# HG changeset patch # User one # Date 1283081280 -32400 # Node ID 29b5497fc942173bb8d99285d0363113f25d0a32 # Parent 29c0866e3a8413d790ec0ea9afff918d67727b3d full test passed. diff -r 29c0866e3a84 -r 29b5497fc942 src/plparser/PropertyListParser.java --- a/src/plparser/PropertyListParser.java Sun Aug 29 18:28:38 2010 +0900 +++ b/src/plparser/PropertyListParser.java Sun Aug 29 20:28:00 2010 +0900 @@ -98,6 +98,7 @@ */ public LinkedList expr1() { LinkedList list = new LinkedList(); + if (nextToken.type==TokenID.CloseCurParen ) return list; expr2(list); while(nextToken.type == TokenID.Semicolon) { nextToken(); @@ -129,11 +130,13 @@ */ public LinkedList expr3() { LinkedListlist = new LinkedList(); + if (nextToken.type==TokenID.CloseParen) return list; Node n1 = term(); list.add(n1); while (nextToken.type==TokenID.Comma) { + nextToken(); + if (nextToken.type==TokenID.CloseParen) return list; Node n2 = term(); - if (nextToken.type==TokenID.CloseParen) return list; list.add(n2); } return list; @@ -157,17 +160,19 @@ LinkedListlist1 = expr3(); if (nextToken.type==TokenID.CloseParen) { } else { // syntax error; - scanner.error(") expected but got "+nextToken); + error(") expected but got "+nextToken); return lf.trueNode(); } + nextToken(); return lf.arrayNode(list1); case CurParen: // Dictionary nextToken(); LinkedList list = expr1(); if (nextToken.type==TokenID.CloseCurParen) { } else { // syntax error; - scanner.error("} expected"); + error("} expected but got "+nextToken); } + nextToken(); return lf.dictionaryNode(list); case NUMBER: n = lf.numberNode(Integer.parseInt(nextToken.name)); diff -r 29c0866e3a84 -r 29b5497fc942 src/plparser/PropertyListScanner.java --- a/src/plparser/PropertyListScanner.java Sun Aug 29 18:28:38 2010 +0900 +++ b/src/plparser/PropertyListScanner.java Sun Aug 29 20:28:00 2010 +0900 @@ -62,7 +62,7 @@ public static Pattern tokenPat = Pattern.compile( "([={}(),;])" ); - public static Pattern namePat = Pattern.compile("([a-zA-Z][\\@\\w]*)"); + public static Pattern namePat = Pattern.compile("([_a-zA-Z][\\@\\w]*)"); public static final Pattern numPat = Pattern.compile("([0-9]+)"); public static final Pattern stringPat1 = Pattern.compile("\\\"([^\"]*)\\\""); public static final Pattern stringPat = Pattern.compile("\\'([^\\']*)\\'"); @@ -71,6 +71,8 @@ public static final Pattern stringPat1End = Pattern.compile("([^\"]*)\\\""); public static final Pattern stringPatEnd = Pattern.compile("([^\\']*)\'"); public static final Pattern commentPat = Pattern.compile("(//.*)"); + public static final Pattern commentPat1 = Pattern.compile("(/\\*)"); + public static final Pattern commentPat1End = Pattern.compile("(.*\\*/)"); public static final Pattern errorPat = Pattern.compile("([^\\s])"); public static final Pattern anyPat = Pattern.compile("(.)"); private static final int BufferSize = 4096; @@ -123,7 +125,7 @@ cb.get(); scan.reset(); while((s1=next(stringPat1End))==null) { s += cb.toString(); - cb.get(); scan.reset(); + cb.get(); scan.reset(); lineno++; } s += s1; Token t; @@ -136,12 +138,20 @@ if ((t = dict.get(s))==null) { dict.put(s, t = new Token(s,TokenID.VARIABLE)); } + if (t.type!=TokenID.VARIABLE) { + t = new Token(s,TokenID.VARIABLE); + } return nextToken = t; } else if ((s=next(numPat))!=null) { return nextToken = new Token(s,TokenID.NUMBER); } else if ((s=next(commentPat))!=null) { while(cb.hasRemaining()&&next(anyPat)!=null); // skip until eol (in case of buffer full) continue; + } else if ((s=next(commentPat1))!=null) { + while(next(commentPat1End)==null) { + cb.get(); scan.reset(); lineno++; + } + continue; } else if ((s=next(errorPat))!=null) { error("Don't understand '"+s+"'"); continue; diff -r 29c0866e3a84 -r 29b5497fc942 src/plparser/TestParser1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/plparser/TestParser1.java Sun Aug 29 20:28:00 2010 +0900 @@ -0,0 +1,20 @@ +package plparser; + + +public class TestParser1 { + + public static void main(String arg[]) { + PropertyListParser p; + PropertyListNodeFactory lf = new PropertyFactoryImpl(); + p = new PropertyListParser(lf); + Property n; + if (arg.length==0) { + arg = new String[1]; + arg[0] = "data/alias_article.plist"; + } + for(String file: arg) { + n = p.parseFile(file); + if (n!=null) System.out.print(n); System.out.println("."); + } + } +}