diff --git a/src/org/rascalmpl/parser/gtd/SGTDBF.java b/src/org/rascalmpl/parser/gtd/SGTDBF.java
index ced74501b4c..3133248aee7 100755
--- a/src/org/rascalmpl/parser/gtd/SGTDBF.java
+++ b/src/org/rascalmpl/parser/gtd/SGTDBF.java
@@ -10,7 +10,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.rascalmpl.parser.gtd.debug.IDebugListener;
import org.rascalmpl.parser.gtd.exception.ParseError;
@@ -48,6 +47,8 @@
import org.rascalmpl.parser.util.ParseStateVisualizer;
import org.rascalmpl.util.visualize.dot.NodeId;
import org.rascalmpl.values.RascalValueFactory;
+import org.rascalmpl.values.parsetrees.ITree;
+import org.rascalmpl.values.parsetrees.TreeAdapter;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IList;
@@ -134,7 +135,7 @@ public abstract class SGTDBF
implements IGTD
{
private final DoubleStack, AbstractNode> filteredNodes;
// Error reporting guards
- private boolean parseErrorOccured;
+ private boolean parseErrorEncountered;
// Error recovery
private IRecoverer recoverer;
@@ -958,7 +959,7 @@ private boolean findFirstStacksToReduce() {
return findStacksToReduce();
}
- parseErrorOccured = true;
+ parseErrorEncountered = true;
}
return false;
@@ -1016,14 +1017,14 @@ private boolean findStacksToReduce() {
return findStacksToReduce();
}
- parseErrorOccured = true;
+ parseErrorEncountered = true;
}
return false;
}
public boolean parseErrorHasOccurred() {
- return parseErrorOccured;
+ return parseErrorEncountered;
}
/**
@@ -1449,7 +1450,7 @@ protected AbstractNode parse(AbstractStackNode
startNode, URI inputURI, int[]
try {
// A parse error occured, and recovery failed as well
- parseErrorOccured = true;
+ parseErrorEncountered = true;
int errorLocation = (location == Integer.MAX_VALUE ? 0 : location);
int line = positionStore.findLine(errorLocation);
@@ -1594,7 +1595,7 @@ protected T buildResult(AbstractNode result, INodeFlattener converter,
actionExecutor.completed(rootEnvironment, (parseResult == null));
}
if (parseResult != null) {
- if (recoverer != null) {
+ if (recoverer != null && parseErrorEncountered) {
parseResult = introduceErrorNodes(parseResult, nodeConstructorFactory);
}
return parseResult; // Success.
@@ -1639,13 +1640,13 @@ private IConstructor introduceErrorNodes(IConstructor tree,
IConstructor result;
Type type = tree.getConstructorType();
if (type == RascalValueFactory.Tree_Appl) {
- result = fixErrorAppl(tree, nodeConstructorFactory);
+ result = fixErrorAppl((ITree) tree, nodeConstructorFactory);
}
else if (type == RascalValueFactory.Tree_Char) {
result = tree;
}
else if (type == RascalValueFactory.Tree_Amb) {
- result = fixErrorAmb(tree, nodeConstructorFactory);
+ result = fixErrorAmb((ITree) tree, nodeConstructorFactory);
}
else if (type == RascalValueFactory.Tree_Cycle) {
result = tree;
@@ -1662,50 +1663,52 @@ else if (type == RascalValueFactory.Tree_Cycle) {
return result;
}
- private IConstructor fixErrorAppl(IConstructor tree,
+ private IConstructor fixErrorAppl(ITree tree,
INodeConstructorFactory nodeConstructorFactory) {
- IValue prod = tree.get(0);
- IList childList = (IList) tree.get(1);
- int childCount = childList.length();
+ IValue prod = TreeAdapter.getProduction(tree);
+ IList childList = TreeAdapter.getArgs(tree);
- ArrayList children = new ArrayList<>(childCount);
- boolean anyChanges = false;
+ ArrayList newChildren = null;
boolean errorTree = false;
+ int childCount = childList.length();
for (int i = 0; i < childCount; i++) {
- if (i == childCount - 1) {
- // Last child could be a skipped child
- IConstructor last = (IConstructor) childList.get(childCount - 1);
- if (last.getConstructorType() == RascalValueFactory.Tree_Appl) {
- IConstructor lastProd = (IConstructor) last.get(0);
- if (lastProd.getConstructorType() == RascalValueFactory.Production_Skipped) {
- errorTree = true;
- children.add(last);
- break;
- }
- }
+ IConstructor child = (IConstructor) childList.get(i);
+ IConstructor newChild = null;
+
+ // Last child could be a skipped child
+ if (i == childCount - 1
+ && child.getConstructorType() == RascalValueFactory.Tree_Appl
+ && TreeAdapter.getProduction((ITree)child).getConstructorType() == RascalValueFactory.Production_Skipped) {
+ errorTree = true;
+ newChild = child;
+ } else {
+ newChild = introduceErrorNodes(child, nodeConstructorFactory);
}
- IConstructor child = (IConstructor) childList.get(i);
- IConstructor resultChild = introduceErrorNodes(child, nodeConstructorFactory);
- children.add(resultChild);
- if (resultChild != child) {
- anyChanges = true;
+ if (newChild != child || errorTree) {
+ if (newChildren == null) {
+ newChildren = new ArrayList<>(childCount);
+ for (int j=0; j nodeConstructorFactory) {
- ISet alternativeSet = (ISet) tree.get(0);
+ ISet alternativeSet = TreeAdapter.getAlternatives(tree);
ArrayList alternatives = new ArrayList<>(alternativeSet.size());
boolean anyChanges = false;
for (IValue alt : alternativeSet) {
@@ -1714,7 +1717,7 @@ private IConstructor fixErrorAmb(IConstructor tree,
anyChanges = true;
}
alternatives.add(newAlt);
- };
+ }
if (anyChanges) {
return nodeConstructorFactory.createAmbiguityNode(alternatives);
@@ -1723,8 +1726,6 @@ private IConstructor fixErrorAmb(IConstructor tree,
return tree;
}
-
-
/**
* Datastructure visualization for debugging purposes
*/