Skip to content

Commit

Permalink
[EGL] Set custom length on AST nodes to undo escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
agarciadom committed Oct 16, 2024
1 parent 7157336 commit 8399031
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class AST extends CommonTree {
protected URI uri;
protected Integer line = null;
protected Integer column = null;

// Optional: only used for undoing EGL escaping
protected Integer length = null;

protected Region region;
protected AST annotations;
protected boolean imaginary;
Expand Down Expand Up @@ -282,7 +286,7 @@ public Region getRegion() {
Position endPosition = new Position();
if (!isImaginary()) {
endPosition.setLine(this.getLine());
endPosition.setColumn(this.getColumn() + ((CommonToken)getToken()).getStopIndex() - ((CommonToken)getToken()).getStartIndex() + 1);
endPosition.setColumn(this.getColumn() + getLength());
}
else {
endPosition.setLine(-1);
Expand Down Expand Up @@ -381,6 +385,17 @@ public String toExtendedStringTree() {
return toExtendedStringTree(0);
}

public Integer getLength() {
if (length == null) {
return ((CommonToken)getToken()).getStopIndex() - ((CommonToken)getToken()).getStartIndex() + 1;
}
return length;
}

public void setLength(Integer length) {
this.length = length;
}

protected String toExtendedStringTree(int indent) {
String toString = "";
for (int i=0;i<indent;i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ protected boolean updateRegionsOfStaticTextASTs(AST ast) {
}

public void updateASTLocations(AST ast) {
ast.setColumn(getTrace().getEglColumnNumberFor(ast.getLine(), ast.getColumn()));
final int eglStartColumn = getTrace().getEglColumnNumberFor(ast.getLine(), ast.getColumn());
final int eglEndColumn = getTrace().getEglColumnNumberFor(ast.getLine(), ast.getColumn() + ast.getLength());
ast.setColumn(eglStartColumn);
ast.setLength(eglEndColumn - eglStartColumn);
ast.setLine(getTrace().getEglLineNumberFor(ast.getLine()));

for (Token token : ast.getExtraTokens()) {
Expand Down

0 comments on commit 8399031

Please sign in to comment.