Skip to content

Commit

Permalink
Fixed whitespace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterOlivier committed Oct 24, 2024
1 parent c75cba6 commit 803724c
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 97 deletions.
150 changes: 73 additions & 77 deletions src/org/rascalmpl/parser/gtd/SGTDBF.java
Original file line number Diff line number Diff line change
Expand Up @@ -1345,127 +1345,123 @@ protected AbstractNode parse(AbstractStackNode<P> startNode, URI inputURI, int[]
debugListener = new NopDebugListener<>();
}

initTime();
initTime();

try {
if(invoked){
throw new RuntimeException("Can only invoke 'parse' once.");
}
try {
if(invoked){
throw new RuntimeException("Can only invoke 'parse' once.");

Check warning on line 1352 in src/org/rascalmpl/parser/gtd/SGTDBF.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/parser/gtd/SGTDBF.java#L1352

Added line #L1352 was not covered by tests
}

invoked = true;
invoked = true;

// Initialize.
this.inputURI = inputURI;
this.input = input;
// Initialize.
this.inputURI = inputURI;
this.input = input;

this.recoverer = recoverer;
this.recoverer = recoverer;
this.debugListener = debugListener;

visualizer = ParseStateVisualizer.shouldVisualizeUri(inputURI) ? new ParseStateVisualizer("Parser") : null;

// Initialzed the position store.
positionStore.index(input);
// Initialzed the position store.
positionStore.index(input);

todoLists = new DoubleStack[DEFAULT_TODOLIST_CAPACITY];
todoLists = new DoubleStack[DEFAULT_TODOLIST_CAPACITY];

// Handle the initial expansion of the root node.
AbstractStackNode<P> rootNode = startNode;
rootNode.initEdges();
stacksToExpand.push(rootNode);
lookAheadChar = (input.length > 0) ? input[0] : 0;
// Handle the initial expansion of the root node.
AbstractStackNode<P> rootNode = startNode;
rootNode.initEdges();
stacksToExpand.push(rootNode);
lookAheadChar = (input.length > 0) ? input[0] : 0;

debugListener.shifting(location, input, positionStore);

expand();
expand();

AbstractContainerNode<P> result = null;
if(findFirstStacksToReduce()){
boolean shiftedLevel = (location != 0);
if(findFirstStacksToReduce()) {
boolean shiftedLevel = (location != 0);
while (true) {
lookAheadChar = (location < input.length) ? input[location] : 0;
if(shiftedLevel){ // Nullable fix for the first level.
sharedNextNodes.clear();
cachedEdgesForExpect.clear();
lookAheadChar = (location < input.length) ? input[location] : 0;
if(shiftedLevel){ // Nullable fix for the first level.
sharedNextNodes.clear();
cachedEdgesForExpect.clear();

unexpandableNodes.dirtyClear();
unmatchableLeafNodes.dirtyClear();
unmatchableMidProductionNodes.dirtyClear();
filteredNodes.dirtyClear();
unexpandableNodes.dirtyClear();
unmatchableLeafNodes.dirtyClear();
unmatchableMidProductionNodes.dirtyClear();
filteredNodes.dirtyClear();

debugListener.shifting(location, input, positionStore);
debugListener.shifting(location, input, positionStore);
}

// Reduce-expand loop.
do {
debugListener.iterating();

reduceTerminals();

reduceNonTerminals();

expand();
// Reduce-expand loop.
do {
debugListener.iterating();
reduceTerminals();
reduceNonTerminals();
expand();
}
while (!stacksWithNonTerminalsToReduce.isEmpty() || !stacksWithTerminalsToReduce.isEmpty());

shiftedLevel = true;
shiftedLevel = true;

if (onlyRecoveredStacksLeft() && attemptRecovery()) {
continue;
}

if (!findStacksToReduce()) {
if(location == input.length) {
EdgesSet<P> startNodeEdgesSet = startNode.getIncomingEdges();
int resultStoreId = getResultStoreId(startNode.getId());
if(startNodeEdgesSet != null && startNodeEdgesSet.getLastVisitedLevel(resultStoreId) == input.length) {
if(location == input.length) {
EdgesSet<P> startNodeEdgesSet = startNode.getIncomingEdges();
int resultStoreId = getResultStoreId(startNode.getId());
if(startNodeEdgesSet != null && startNodeEdgesSet.getLastVisitedLevel(resultStoreId) == input.length) {
result = startNodeEdgesSet.getLastResult(resultStoreId); // Success.
break;
}
}
if (!attemptRecovery()) {
// Unsuccessful parse
break;
}
}
}
}
}
}
}
}

visualize("Done", ParseStateVisualizer.PARSER_ID);

if (result != null) {
return result;
}
} finally {
checkTime("Parsing");
}
checkTime("Parsing");
}

try {
// A parse error occured, and recovery failed as well
try {
// A parse error occured, and recovery failed as well
parseErrorEncountered = true;
int errorLocation = (location == Integer.MAX_VALUE ? 0 : location);
int line = positionStore.findLine(errorLocation);
int column = positionStore.getColumn(errorLocation, line);
if (location == input.length) {

int errorLocation = (location == Integer.MAX_VALUE ? 0 : location);
int line = positionStore.findLine(errorLocation);
int column = positionStore.getColumn(errorLocation, line);
if (location == input.length) {
throw new ParseError("Parse error", inputURI, errorLocation, 0, line + 1, line + 1, column, column,
(Stack<AbstractStackNode<?>>) (Stack<?>) unexpandableNodes,
(Stack<AbstractStackNode<?>>) (Stack<?>) unmatchableLeafNodes,
(DoubleStack<ArrayList<AbstractStackNode<?>>, AbstractStackNode<?>>) (DoubleStack<?, ?>) unmatchableMidProductionNodes,
(DoubleStack<AbstractStackNode<?>, AbstractNode>) (DoubleStack<?, ?>) filteredNodes);
}
}
throw new ParseError("Parse error", inputURI, errorLocation, 1, line + 1, line + 1, column, column + 1,
(Stack<AbstractStackNode<?>>) (Stack<?>) unexpandableNodes,
(Stack<AbstractStackNode<?>>) (Stack<?>) unmatchableLeafNodes,
(DoubleStack<ArrayList<AbstractStackNode<?>>, AbstractStackNode<?>>) (DoubleStack<?, ?>) unmatchableMidProductionNodes,
(DoubleStack<AbstractStackNode<?>, AbstractNode>) (DoubleStack<?, ?>) filteredNodes);
}
finally {
checkTime("Error handling");
}
} finally {
checkTime("Error handling");
}
}

private void initTime() {
timestamp = System.nanoTime();
timestamp = System.nanoTime();
}

private boolean onlyRecoveredStacksLeft() {
Expand Down Expand Up @@ -1689,21 +1685,21 @@ private IConstructor fixErrorAppl(ITree tree,
IList childList = TreeAdapter.getArgs(tree);

ArrayList<IConstructor> newChildren = null;
boolean errorTree = false;
boolean errorTree = false;
int childCount = childList.length();
for (int i=0; i<childCount; i++) {
for (int i=0; i<childCount; i++) {
IConstructor child = (IConstructor) childList.get(i);
IConstructor newChild = null;

// Last child could be a skipped child
// 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;
errorTree = true;
newChild = child;
} else {
newChild = introduceErrorNodes(child, nodeConstructorFactory);
}
}

if (newChild != child || errorTree) {
if (newChildren == null) {
Expand All @@ -1713,38 +1709,38 @@ private IConstructor fixErrorAppl(ITree tree,
}
}
newChildren.add(newChild);
}
}
}

if (errorTree) {
if (errorTree) {
return nodeConstructorFactory.createErrorNode(newChildren, prod);
}
else if (newChildren != null) {
return nodeConstructorFactory.createSortNode(newChildren, prod);
}
}

return tree;
}

private IConstructor fixErrorAmb(ITree tree,
INodeConstructorFactory<IConstructor, S> nodeConstructorFactory) {
ISet alternativeSet = TreeAdapter.getAlternatives(tree);
ArrayList<IConstructor> alternatives = new ArrayList<>(alternativeSet.size());
ArrayList<IConstructor> alternatives = new ArrayList<>(alternativeSet.size());
boolean anyChanges = false;
for (IValue alt : alternativeSet) {
IConstructor newAlt = introduceErrorNodes((IConstructor) alt, nodeConstructorFactory);
if (newAlt != alt) {
if (newAlt != alt) {
anyChanges = true;
}
alternatives.add(newAlt);
}
alternatives.add(newAlt);
}

if (anyChanges) {
return nodeConstructorFactory.createAmbiguityNode(alternatives);
}

return tree;

Check warning on line 1742 in src/org/rascalmpl/parser/gtd/SGTDBF.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/parser/gtd/SGTDBF.java#L1742

Added line #L1742 was not covered by tests
}
}

/**
* Datastructure visualization for debugging purposes
Expand Down
38 changes: 18 additions & 20 deletions src/org/rascalmpl/parser/uptr/recovery/ToTokenRecoverer.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ private DoubleArrayList<AbstractStackNode<IConstructor>, AbstractNode> reviveNod
continue;
}

AbstractStackNode<IConstructor> continuer =
new RecoveryPointStackNode<>(stackNodeIdDispenser.dispenseId(), prod, recoveryNode);
AbstractStackNode<IConstructor> continuer = new RecoveryPointStackNode<>(stackNodeIdDispenser.dispenseId(), prod, recoveryNode);

EdgesSet<IConstructor> edges = new EdgesSet<>(1);
edges.add(continuer);
Expand Down Expand Up @@ -210,23 +209,23 @@ private void addEndMatchers(AbstractStackNode<IConstructor>[] prod, int dot, Lis
public Void visit(LiteralStackNode<IConstructor> literal) {
matchers.add(new LiteralMatcher(literal.getLiteral()));
return null;
}
}

@Override
public Void visit(CaseInsensitiveLiteralStackNode<IConstructor> literal) {
matchers.add(new CaseInsensitiveLiteralMatcher(literal.getLiteral()));
return null;
}
}

@Override
public Void visit(NonTerminalStackNode<IConstructor> nonTerminal) {
String name = nonTerminal.getName();
AbstractStackNode<IConstructor>[] alternatives = expectsProvider.getExpects(name);
for (AbstractStackNode<IConstructor> alternative : alternatives) {
addEndMatchers(alternative.getProduction(), 0, matchers, visitedNodes);
}
AbstractStackNode<IConstructor>[] alternatives = expectsProvider.getExpects(name);
for (AbstractStackNode<IConstructor> alternative : alternatives) {
addEndMatchers(alternative.getProduction(), 0, matchers, visitedNodes);
}
return null;
}
}
});
}

Expand Down Expand Up @@ -283,21 +282,21 @@ private void addNextMatchers(AbstractStackNode<IConstructor>[] prod, int dot, Li
public Void visit(LiteralStackNode<IConstructor> literal) {
matchers.add(new LiteralMatcher(literal.getLiteral()));
return null;
}
}

@Override
public Void visit(CaseInsensitiveLiteralStackNode<IConstructor> literal) {
matchers.add(new CaseInsensitiveLiteralMatcher(literal.getLiteral()));
return null;
}
}

@Override
public Void visit(NonTerminalStackNode<IConstructor> nonTerminal) {
String name = nonTerminal.getName();
AbstractStackNode<IConstructor>[] alternatives = expectsProvider.getExpects(name);
for (AbstractStackNode<IConstructor> alternative : alternatives) {
addNextMatchers(alternative.getProduction(), 0, matchers, visitedNodes);
}
AbstractStackNode<IConstructor>[] alternatives = expectsProvider.getExpects(name);
for (AbstractStackNode<IConstructor> alternative : alternatives) {
addNextMatchers(alternative.getProduction(), 0, matchers, visitedNodes);
}

return null;
}
Expand Down Expand Up @@ -444,7 +443,6 @@ private void findRecoveryNodes(AbstractStackNode<IConstructor> failer,
if (edgesList != null) {
for (int j = edgesList.size() - 1; j >= 0; --j) {
AbstractStackNode<IConstructor> parent = edgesList.get(j);

todo.push(parent);
}
}
Expand All @@ -458,16 +456,16 @@ private void addRecoveryNode(AbstractStackNode<IConstructor> node, ArrayList<ICo
for (int i=0; i<recoveryNodes.size(); i++) {
if (recoveryNodes.getFirst(i) == node && equalProductions(productions, recoveryNodes.getSecond(i))) {
return;
}
}
}
}

recoveryNodes.add(node, productions);
}
}

private boolean equalProductions(ArrayList<IConstructor> prods1, ArrayList<IConstructor> prods2) {
if (prods1.size() != prods2.size()) {
return false;

Check warning on line 467 in src/org/rascalmpl/parser/uptr/recovery/ToTokenRecoverer.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/parser/uptr/recovery/ToTokenRecoverer.java#L467

Added line #L467 was not covered by tests
}
}

for (int j = 0; j < prods1.size(); j++) {
if (prods1.get(j) != prods2.get(j)) {
Expand Down

0 comments on commit 803724c

Please sign in to comment.