- GSS gss = new GSS(input);
- Input.Location loc = input.getLocation();
- Token tok = input.next();
- GSS.Phase current = gss.new Phase<Token>(null, null, tok, loc, input.getLocation(), null);
- current.newNode(new Result(Forest.create(loc.createRegion(loc), null, null, false), null, null), pt.start, true);
- int count = 1;
- for(int idx=0;;idx++) {
- Input.Location oldloc = loc;
- current.reduce();
- Forest forest = current.token==null ? null : shiftToken((Token)current.token, loc);
- loc = input.getLocation();
- Token nextToken = input.next();
- GSS.Phase next = gss.new Phase<Token>(current, current, nextToken, loc, input.getLocation(), forest);
-
- /*
- FileOutputStream fos = new FileOutputStream("out-"+idx+".dot");
- PrintWriter p = new PrintWriter(new OutputStreamWriter(fos));
- GraphViz gv = new GraphViz();
- for(Object n : current)
- ((Node)n).toGraphViz(gv);
- gv.dump(p);
- p.flush();
- p.close();
- */
-
- count = next.size();
- if (current.isDone()) return (Forest<NodeType>)gss.finalResult;
- current = next;
- }
+ verbose = System.getProperty("sbp.verbose", null) != null;
+ spinpos = 0;
+ try {
+ GSS gss = new GSS(input, this);
+ for(GSS.Phase current = gss.new Phase<Token>(pt.start); ;) {
+
+ if (verbose) {
+ // FIXME: clean this up
+ String s;
+ s = " " + spin[spinpos++ % (spin.length)]+" parsing ";
+ s += input.getName();
+ s += " "+input.getLocation();
+ while(s.indexOf(':') != -1 && s.indexOf(':') < 8) s = " " + s;
+ String y = "@"+gss.viewPos+" ";
+ while(y.length() < 9) y = " " + y;
+ s += y;
+ s += " nodes="+gss.numOldNodes;
+ while(s.length() < 50) s = s + " ";
+ s += " shifted="+gss.numNewNodes;
+ while(s.length() < 60) s = s + " ";
+ s += " reductions="+gss.numReductions;
+ System.err.print("\r"+s+ANSI.clreol()+"\r");
+ }
+
+ if (current.isDone()) return (Forest<NodeType>)current.finalResult;
+ Forest forest = shiftToken((Token)current.token, current.getRegion());
+ current = gss.new Phase<Token>(current, forest);
+ }
+ } finally { if (verbose) System.err.print("\r"+ANSI.clreol()); }
+ }
+
+ // Spinner //////////////////////////////////////////////////////////////////////////////
+
+ private boolean verbose = false;
+ private static final char[] spin = new char[] { '-', '\\', '|', '/' };
+ private int spinpos = 0;
+ private long last = 0;
+ void spin() {
+ if (!verbose) return;
+ long now = System.currentTimeMillis();
+ if (now-last < 70) return;
+ last = now;
+ System.err.print("\r " + spin[spinpos++ % (spin.length)]+"\r");