WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 200076b

Browse files
committed
Issue #36 - Added end line and column determination to parser.
1 parent fadef44 commit 200076b

File tree

6 files changed

+1513
-1131
lines changed

6 files changed

+1513
-1131
lines changed
-30.6 KB
Binary file not shown.

org.modeldriven.alf/src/org/modeldriven/alf/execution/AlfBase.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,21 @@ protected void printConstraintViolation(String line, ConstraintViolation violati
126126
this.println("");
127127
if (line != null) {
128128
this.println(line);
129-
StringBuffer indent = new StringBuffer();
130-
for (int n = violation.getBeginColumn(); n > 1; n--) {
131-
indent.append(" ");
129+
StringBuffer marker = new StringBuffer();
130+
int beginColumn = violation.getBeginColumn();
131+
int endColumn = violation.getEndColumn();
132+
for (int n = beginColumn; n > 1; n--) {
133+
marker.append(" ");
132134
}
133-
this.println(indent + "^");
134-
}
135+
marker.append("^");
136+
if (violation.getBeginLine() == violation.getEndLine() && endColumn > beginColumn) {
137+
for (int n = beginColumn+1; n < endColumn; n++ ) {
138+
marker.append("-");
139+
}
140+
marker.append("^");
141+
}
142+
this.println(marker.toString());
143+
}
135144
this.println(violation.getErrorMessage());
136145
}
137146

org.modeldriven.alf/src/org/modeldriven/alf/parser/ParseException.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public ParseException(Token currentTokenVal,
4444
currentToken = currentTokenVal;
4545
expectedTokenSequences = expectedTokenSequencesVal;
4646
tokenImage = tokenImageVal;
47+
48+
beginLine = currentToken.next.beginLine;
49+
beginColumn = currentToken.next.beginColumn;
50+
endLine = currentToken.next.endLine;
51+
endColumn = currentToken.next.endColumn;
4752
}
4853

4954
/**
@@ -69,7 +74,7 @@ public ParseException(String message) {
6974
/**
7075
* This is the last token that has been consumed successfully. If
7176
* this object has been created due to a parse error, the token
72-
* followng this token will (therefore) be the first error token.
77+
* following this token will (therefore) be the first error token.
7378
*/
7479
public Token currentToken;
7580

@@ -87,20 +92,25 @@ public ParseException(String message) {
8792
*/
8893
public String[] tokenImage;
8994

95+
private int beginLine = 0;
96+
private int beginColumn = 0;
97+
private int endLine = 0;
98+
private int endColumn = 0;
99+
90100
public int getBeginLine() {
91-
return this.currentToken.next.beginLine;
101+
return this.beginLine;
92102
}
93103

94104
public int getBeginColumn() {
95-
return this.currentToken.next.beginColumn;
105+
return this.beginColumn;
96106
}
97107

98108
public int getEndLine() {
99-
return this.currentToken.next.endLine;
109+
return this.endLine;
100110
}
101111

102112
public int getEndColumn() {
103-
return this.currentToken.next.endColumn;
113+
return this.endColumn;
104114
}
105115

106116
/**

0 commit comments

Comments
 (0)