+ public Input.Location getLocation() { return location; }
+ public Input.Location getNextLocation() { return nextLocation; }
+ public boolean isFrontier() { return hash!=null; }
+
+ /** perform all shift operations, adding promoted nodes to <tt>next</tt> */
+ private void shift(Phase next, Forest result) throws ParseFailed {
+ this.next = next;
+ // this massively improves GC performance
+ if (prev != null) {
+ IntPairMap<Node> h = prev.hash;
+ prev.hash = null;
+ prev.performed = null;
+ for(Node n : h) n.check();
+ }
+ numOldNodes = hash.size();
+ for(Node n : hash.values()) {
+ if (token == null && n.state().isAccepting()) {
+ if (finalResult==null) finalResult = new Forest.Many();
+ for(Result r : n)
+ finalResult.merge(r.getForest());
+ }
+ if (token == null) continue;
+ n.state().invokeShifts(token, this, new Result(result, n, null));
+ }
+ 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());
+ } else {
+ ParseFailed.error("unexpected character '"+ANSI.cyan(StringUtil.escapify(token+"",
+ "\\\'\r\n"))+"'",
+ this, token, getRegionFromThisToNext());
+ }
+ }
+ if (token==null && finalResult==null)
+ ParseFailed.error("unexpected end of file", this, null,
+ getLocation().createRegion(getLocation()));
+ for(Node n : hash) n.check();
+ }
+
+ Input.Region getRegionFromThisToNext() {
+ return getLocation().createRegion(getNextLocation());
+ }
+
+ void newNodeFromReduction(Result result, State state, Pos reduction) {
+ int pos = result.phase().pos;
+ for(int s : reduction.hates())
+ if (performed.contains(pos, s))
+ return;
+ for(int s : reduction.needs())
+ if (!performed.contains(pos, s))
+ return;
+ if (reduction.owner_needed_or_hated() && !performed.contains(pos, reduction.provides()))
+ performed.add(pos, reduction.provides());
+ if (state!=null)
+ newNode(result, state, reduction.numPops()<=0);
+ }