added decent error reporting
[sbp.git] / src / edu / berkeley / sbp / Parser.java
index fac14b0..ddee582 100644 (file)
@@ -36,16 +36,18 @@ public abstract class Parser<T extends Token, R> {
     public Forest<R> parse(Token.Stream<T> input) throws IOException, Failed {
         GSS gss = new GSS();
         Token.Location loc = input.getLocation();
-        GSS.Phase current = gss.new Phase(null, input.next(), loc);
+        GSS.Phase current = gss.new Phase(null, input.next(1), loc);
         current.newNode(null, null, pt.start, true);
+        int count = 1;
         for(;;) {
             loc = input.getLocation();
-            GSS.Phase next = gss.new Phase(current, input.next(), loc);
+            //current.checkFailure();
+            GSS.Phase next = gss.new Phase(current, input.next(count), loc);
             current.reduce();
             Forest forest = current.token==null ? null : shiftedToken((T)current.token, loc);
             current.shift(next, forest);
+            count = next.hash.size();
             if (current.isDone()) return (Forest<R>)current.finalResult;
-            current.checkFailure();
             current = next;
         }
     }
@@ -59,7 +61,7 @@ public abstract class Parser<T extends Token, R> {
         public Failed() { this("", null); }
         public Failed(String message, Token.Location loc) { this.location = loc; this.message = message; }
         public Token.Location getLocation() { return location; }
-        public String toString() { return message + (location==null ? "" : (" at " + location)); }
+        public String toString() { return message/* + (location==null ? "" : (" at " + location))*/; }
     }
 
     public static class Ambiguous extends RuntimeException {