Mercurial > hg > Members > kono > PLparser
changeset 3:1f46c9d09c1e
Simple Example worked.
author | kono@ie.u-ryukyu.ac.jp |
---|---|
date | Sun, 29 Aug 2010 12:47:11 +0900 |
parents | 151c7fe6c61a |
children | 29c0866e3a84 |
files | src/plparser/ArrayProperty.java src/plparser/DictProperty.java src/plparser/PropertyListParser.java |
diffstat | 3 files changed, 27 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plparser/ArrayProperty.java Sun Aug 29 02:36:08 2010 +0900 +++ b/src/plparser/ArrayProperty.java Sun Aug 29 12:47:11 2010 +0900 @@ -8,8 +8,16 @@ public ArrayProperty(LinkedList<Property> list1) { list = list1; } - + public String toString() { - return "Array ("+list+")"; + String s = "Array(" ; + for(Property p:list) { + s += p; + s += ","; + } + s = s.substring(0, s.length()-1); + s += ")"; + return s; } + }
--- a/src/plparser/DictProperty.java Sun Aug 29 02:36:08 2010 +0900 +++ b/src/plparser/DictProperty.java Sun Aug 29 12:47:11 2010 +0900 @@ -23,6 +23,7 @@ s += map.get(p); s += ","; } + s = s.substring(0, s.length()-1); s += "}"; return s; }
--- a/src/plparser/PropertyListParser.java Sun Aug 29 02:36:08 2010 +0900 +++ b/src/plparser/PropertyListParser.java Sun Aug 29 12:47:11 2010 +0900 @@ -16,6 +16,7 @@ PropertyListNodeFactory<Node> lf) { this.lf = lf; initialize(); + scanner.set(string); } @@ -84,34 +85,48 @@ return n; } + /** + * expr1 {} Dictionary + * @return list of node (key,value,key,value) + */ public LinkedList<Node> expr1() { LinkedList<Node> list = new LinkedList<Node>(); expr2(list); while(nextToken.type == TokenID.Semicolon) { nextToken(); + if (nextToken.type==TokenID.CloseCurParen ) return list; expr2(list); } return list; } - + /** + * expr2 + * key = value + */ public void expr2(LinkedList<Node>list) { Node n1 = term(); if (nextToken.type!=TokenID.Assign) { error("needs assignment"); return; } + nextToken(); Node n2 = term(); list.add(n1); list.add(n2); return; } + /** + * expr3 Array + * @return list of node + */ public LinkedList<Node> expr3() { LinkedList<Node>list = new LinkedList<Node>(); Node n1 = term(); list.add(n1); while (nextToken.type==TokenID.Comma) { Node n2 = term(); + if (nextToken.type==TokenID.CloseParen) return list; list.add(n2); } return list;