Skip to content

Commit

Permalink
implemented setField on error trees
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Nov 13, 2024
1 parent bb7ea53 commit 262ac79
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/org/rascalmpl/values/parsetrees/TreeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ else if (ProductionAdapter.isRegular(prod)) {
return null;
}
}
else if (ProductionAdapter.isError(prod)) {
var eprod = ProductionAdapter.getErrorProd(prod);
int dot = ProductionAdapter.getErrorDot(prod);
int index = SymbolAdapter.indexOfLabel(ProductionAdapter.getSymbols(eprod), field);
IList args = getArgs(tree);

if (index != -1) {
if (index < dot) {
// changing the normal part of the tree
return setArgs(tree, args.put(index, repl));
}
else if (index == dot) {
// extending the accepted part of the tree by one field
eprod = prod.set("prod", IRascalValueFactory.getInstance().integer(dot + 1));
return setProduction(setArgs(tree, args.append(repl)), eprod);
}

// otherwise we return null which indicates the field does not exist.
}
}
}

return null;
Expand Down

0 comments on commit 262ac79

Please sign in to comment.