diff --git a/src/org/rascalmpl/library/util/ErrorRecovery.java b/src/org/rascalmpl/library/util/ErrorRecovery.java index 5d116f0e70..7ee22c65f1 100644 --- a/src/org/rascalmpl/library/util/ErrorRecovery.java +++ b/src/org/rascalmpl/library/util/ErrorRecovery.java @@ -31,10 +31,12 @@ public ErrorRecovery(IRascalValueFactory rascalValues) { private static class ScoredTree { public final IConstructor tree; public final int score; + public final boolean hasErrors; - public ScoredTree(IConstructor tree, int score) { + public ScoredTree(IConstructor tree, int score, boolean hasErrors) { this.tree = tree; this.score = score; + this.hasErrors = hasErrors; } } @@ -60,8 +62,8 @@ private ScoredTree disambiguate(IConstructor tree, boolean allowAmbiguity, boole } else if (type == RascalValueFactory.Tree_Amb) { result = disambiguateAmb((ITree) tree, allowAmbiguity, buildTree, processedTrees); } else { - // Other trees (cycle, char) do not have subtrees so they have a score of 0 - result = new ScoredTree(tree, 0); + // Other trees (cycle, char) do not have subtrees so they have a score of 0 and no errors + result = new ScoredTree(tree, 0, false); } return result; @@ -74,10 +76,11 @@ private ScoredTree disambiguateAppl(ITree appl, boolean allowAmbiguity, boolean } if (ProductionAdapter.isSkipped(appl.getProduction())) { - result = new ScoredTree(appl, ((IList) appl.get(1)).length()); + result = new ScoredTree(appl, ((IList) appl.get(1)).length(), true); } else { IList args = TreeAdapter.getArgs(appl); int totalScore = 0; + boolean hasErrors = false; IListWriter disambiguatedArgs = null; // Disambiguate and score all children @@ -85,6 +88,7 @@ private ScoredTree disambiguateAppl(ITree appl, boolean allowAmbiguity, boolean IValue arg = args.get(i); ScoredTree disambiguatedArg = disambiguate((IConstructor) arg, allowAmbiguity, buildTree, processedTrees); totalScore += disambiguatedArg.score; + hasErrors |= disambiguatedArg.hasErrors; if (buildTree && disambiguatedArg.tree != arg && disambiguatedArgs == null) { disambiguatedArgs = rascalValues.listWriter(); for (int j=0; j disambiguatedAlt.score) { + errorAltWithBestScore = disambiguatedAlt; + } + } else { // Non-error tree if (alternativesWithoutErrors == null) { alternativesWithoutErrors = rascalValues.setWriter(); } alternativesWithoutErrors.insert(disambiguatedAlt.tree); - } else { - // Only keep the best of the error trees - if (errorAltWithBestScore == null || errorAltWithBestScore.score > disambiguatedAlt.score) { - errorAltWithBestScore = disambiguatedAlt; - } } } @@ -171,7 +175,7 @@ private ScoredTree disambiguateAmb(ITree amb, boolean allowAmbiguity, boolean bu } } - result = new ScoredTree(resultTree, 0); + result = new ScoredTree(resultTree, 0, false); processedTrees.put(amb, result); return result;