changeset 5:29b5497fc942

full test passed.
author one
date Sun, 29 Aug 2010 20:28:00 +0900
parents 29c0866e3a84
children 563bcb96e4fa
files src/plparser/PropertyListParser.java src/plparser/PropertyListScanner.java src/plparser/TestParser1.java
diffstat 3 files changed, 40 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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<Node> expr1() {
 		LinkedList<Node> list = new LinkedList<Node>();
+		if (nextToken.type==TokenID.CloseCurParen ) return list;
 	    expr2(list);
 		while(nextToken.type == TokenID.Semicolon) {
 			nextToken();
@@ -129,11 +130,13 @@
 	 */
 	public LinkedList<Node> expr3() {
 		LinkedList<Node>list = new LinkedList<Node>();
+		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 @@
 			LinkedList<Node>list1 = 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<Node> 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));
--- 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<Node> t;
@@ -136,12 +138,20 @@
 				if ((t = dict.get(s))==null) {
 					dict.put(s, t = new Token<Node>(s,TokenID.VARIABLE));
 				}
+				if (t.type!=TokenID.VARIABLE) {
+					t = new Token<Node>(s,TokenID.VARIABLE);
+				}
 				return nextToken = t;
 			} else if ((s=next(numPat))!=null) {
 				return nextToken = new Token<Node>(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;
--- /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<Property> p;
+		PropertyListNodeFactory<Property> lf = new PropertyFactoryImpl(); 
+		p = new PropertyListParser<Property>(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(".");
+		}
+	}
+}