- private void newNode2(Node p, Node parent, Forest pending, Parser.Table.State state, boolean fromEmptyReduction, Phase start) {
- p.holder.merge(pending);
- if (p.parents().contains(parent)) return;
- p.addParent(parent, fromEmptyReduction);
+ public void newNode(Node parent, Forest pending, State state, boolean fromEmptyReduction, Position reduction) {
+ int pos = parent==null?0:parent.phase()==null?0:parent.phase().pos;
+ Sequence owner = reduction==null ? null : reduction.owner();
+ if (reduction!=null) {
+ if (owner.hates!=null) {
+ for (Sequence s : performed.getAll(pos))
+ if (owner.hates.contains(s))
+ return;
+ for (Sequence s : lastperformed.getAll(pos))
+ if (owner.hates.contains(s)) {
+ //System.out.println("now expecting ["+pos+"] => " + s);
+ expected.add(pos, s);
+ return;
+ }
+ }
+ if (owner.needs != null)
+ for(Sequence s : owner.needs)
+ if (!performed.contains(pos, s)) {
+ waiting.add(s, new Waiting(parent, pending, state, fromEmptyReduction, reduction));
+ return;
+ }
+ if (!performed.contains(pos, owner)) {
+ performed.add(pos, owner);
+ if (owner.hated != null)
+ for(Sequence seq : owner.hated)
+ if (performed.contains(pos, seq)) {
+ performed.remove(pos, seq);
+ reset = true;
+ }
+ }
+ }
+ if (!owner.lame)
+ newNode(parent, pending, state, fromEmptyReduction);
+ if (reduction != null) {
+ boolean redo = true;
+ while(redo) {
+ redo = false;
+ for(Waiting w : waiting.getAll(owner)) {
+ if (w.parent==parent || (parent!=null&&w.parent!=null&&w.parent.phase()==parent.phase())) {
+ waiting.remove(owner, w);
+ w.perform();
+ redo = true;
+ break;
+ }
+ }
+ }
+ }