Mercurial > hg > Members > kono > PLparser
changeset 4:29c0866e3a84
text
author | one |
---|---|
date | Sun, 29 Aug 2010 18:28:38 +0900 |
parents | 1f46c9d09c1e |
children | 29b5497fc942 |
files | src/plparser/Dictionary.java src/plparser/PropertyListParser.java src/plparser/PropertyListScanner.java |
diffstat | 3 files changed, 20 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plparser/Dictionary.java Sun Aug 29 12:47:11 2010 +0900 +++ b/src/plparser/Dictionary.java Sun Aug 29 18:28:38 2010 +0900 @@ -11,8 +11,6 @@ this.put(name, t); return t; } - - public Token<Node> reserve(String string) { return reserve(string,TokenID.Any);
--- a/src/plparser/PropertyListParser.java Sun Aug 29 12:47:11 2010 +0900 +++ b/src/plparser/PropertyListParser.java Sun Aug 29 18:28:38 2010 +0900 @@ -10,8 +10,9 @@ Token<Node> nextToken; public PropertyListScanner<Node> scanner; private Dictionary<Node> dict; + // scope is necessary if you have to parse nested name scope // private PropertyListScope<Node> scope; - + public PropertyListParser(String string, PropertyListNodeFactory<Node> lf) { this.lf = lf; @@ -19,6 +20,11 @@ scanner.set(string); } + public PropertyListParser(PropertyListNodeFactory<Node> lf) { + this.lf = lf; + initialize(); + } + public void initReservedWord() { dict.reserve("=",TokenID.Assign); @@ -40,7 +46,8 @@ } public Node parse() { - if (scanner==null) return null; + if (scanner==null) return null; // internal error + if (scanner.cb==null) return null; // nothing to do nextToken(); return term(); } @@ -55,24 +62,24 @@ } - public void parseFile(String file) { + public Node parseFile(String file) { try { scanner = scanner.pushScannerFile(file); } catch (FileNotFoundException e) { error("Can't open "+file); - return; + return null; } - doParse(); + return doParse(); } - public void parse(InputStream file) { + public Node parse(InputStream file) { scanner = scanner.pushScannerFile(file,null); - doParse(); + return doParse(); } - public void parse(InputStream in, String prompt) { + public Node parse(InputStream in, String prompt) { scanner = scanner.pushScannerFile(in,prompt); - doParse(); + return doParse(); } public Node doParse() {
--- a/src/plparser/PropertyListScanner.java Sun Aug 29 12:47:11 2010 +0900 +++ b/src/plparser/PropertyListScanner.java Sun Aug 29 18:28:38 2010 +0900 @@ -108,7 +108,8 @@ String s1; cb.get(); scan.reset(); while((s1=next(stringPatEnd))==null) { - s += next(anyPat); cb.get(); scan.reset(); + s += cb.toString(); + cb.get(); scan.reset(); } s += s1; Token<Node> t; @@ -121,7 +122,8 @@ String s1; cb.get(); scan.reset(); while((s1=next(stringPat1End))==null) { - s += next(anyPat); cb.get(); scan.reset(); + s += cb.toString(); + cb.get(); scan.reset(); } s += s1; Token<Node> t;