-
- if (!good && token!=null)
- throw new ParseFailed(ParseFailed.error(ANSI.red("unexpected character ")+" \'"+
- ANSI.purple(StringUtil.escapify(token+"", "\\\'\r\n"))+
- "\' encountered at "+
- ANSI.green(getLocation())+"\n", token, hash.values()),
- getLocation());
- if (token==null && finalResult==null)
- throw new ParseFailed(ParseFailed.error(ANSI.red("unexpected end of file\n"), token, hash.values()),
- getLocation());
- }
-
-
- class Waiting {
- Node parent;
- Forest pending;
- State state;
- boolean fromEmptyReduction;
- Position reduction;
- public Waiting(Node parent, Forest pending, State state, boolean fromEmptyReduction, Position reduction) {
- waits++;
- this.parent = parent;
- this.pending = pending;
- this.state = state;
- this.fromEmptyReduction = fromEmptyReduction;
- this.reduction = reduction;
- }
- public void perform() {
- //System.out.println("performing: " + reduction.position);
- newNode(parent, pending, state, fromEmptyReduction, reduction);
- }
- }
-
- // Node /////////////////////////////////////////////////////////////////////////////////
-
- /** a node in the GSS */
- final class Node extends FastSet<Node> implements Invokable<Position, Node, Node>, IntegerMappable {
-
- private Forest.Ref holder = null;
- private boolean allqueued = false;
-
- /** what state this node is in */
- public final Parser.Table<Tok>.State<Tok> state;
-
- /** which Phase this Node belongs to (node that Node is also a non-static inner class of Phase) */
- public Phase phase() { return Phase.this; }
- public Forest.Ref holder() { return holder==null ? (holder = new Forest.Ref()) : holder; }
- public Forest pending() { return Phase.this.closed ? holder().resolve() : holder; }
- public FastSet<Node> parents() { return this; }
-
- public void performReductions() {
- if (allqueued) return;
- allqueued = true;
- state.invokeReductions(token, this, this, null);
- }
-
- public void performReductions(Node n2) {
- if (!allqueued) performReductions();
- else state.invokeReductions(token, this, this, n2);
- }
-
- public void performEmptyReductions() { state.invokeReductions(token, this, null, null); }
- public final void invoke(Position r, Node n, Node n2) {
- if (n==null || n2==null || r.pos==0) {
- if (r.pos==0) {
- if (n==null) n = this;
- else return;
- }
- if (n==null) return;
- Forest[] holder = new Forest[r.pos];
- if (r.pos==0) n.finish(r, r.zero(), n.phase(), holder);
- else n.reduce(r, r.pos-1, n.phase(), holder);
+ numNewNodes = next==null ? 0 : next.hash.size();
+ viewPos = this.pos;
+
+ if (!good && token!=null) {
+ String toks = token+"";
+ if (toks.length()==1 && toks.charAt(0) == edu.berkeley.sbp.chr.CharAtom.left) {
+ ParseFailed.error("unexpected increase in indentation", this,
+ token, getRegionFromThisToNext());
+ } else if (toks.length()==1 && toks.charAt(0) == edu.berkeley.sbp.chr.CharAtom.right) {
+ ParseFailed.error("unexpected decrease in indentation", this,
+ token, getRegionFromThisToNext());