Skip to content

Commit

Permalink
Simplified "isTopLevelProduction" implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterOlivier committed Nov 3, 2024
1 parent f708b01 commit 7e3f4f4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/org/rascalmpl/parser/uptr/recovery/ToTokenRecoverer.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ private List<SkippingStackNode<IConstructor>> findSkippingNodes(int[] input, int
return nodes; // No other nodes would be useful
}

// If we are the top-level node, just skip the rest of the input
if (!recoveryNode.isEndNode() && isTopLevelProduction(recoveryNode)) {
result = SkippingStackNode.createResultUntilEndOfInput(uri, input, startLocation);
nodes.add(new SkippingStackNode<>(stackNodeIdDispenser.dispenseId(), prod, result, startLocation));
return nodes; // No other nodes would be useful
}

// Find the last token of this production and skip until after that
List<InputMatcher> endMatchers = findEndMatchers(recoveryNode.getProduction()[recoveryNode.getDot()]);
for (InputMatcher endMatcher : endMatchers) {
Expand Down Expand Up @@ -234,7 +241,13 @@ private boolean maybeEndNode(AbstractStackNode<IConstructor>[] prod, int dot) {

throw new AssertionError("No end node found?"); // Should not happen, last node is always an end node
}


// Check if a node is a top-level production (i.e., its parent production node has no parents and
// starts at position -1)
private boolean isTopLevelProduction(AbstractStackNode<IConstructor> node) {
return node.getProduction()[0].getStartLocation() == -1;
}

private void addEndMatchers(AbstractStackNode<IConstructor>[] prod, int dot, List<InputMatcher> matchers, Set<Integer> visitedNodes) {
if (prod == null || dot < 0 || dot >= prod.length) {
return;
Expand Down

0 comments on commit 7e3f4f4

Please sign in to comment.