Skip to content

Commit 71bbda8

Browse files
authored
Merge pull request #286 from jrha/fix_ParseException_SourceRange
panc: Fixes for parseException and sourceRange
2 parents 72d4e61 + 10511d2 commit 71bbda8

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

panc/src/main/java/org/quattor/pan/parser/ParseException.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Centre National de la Recherche Scientifique (CNRS).
2828
* This exception is thrown when parse errors are encountered. You can
2929
* explicitly create objects of this exception type by calling the method
3030
* generateParseException in the generated parser.
31-
*
31+
*
3232
* You can modify this class to customize your error reporting mechanisms so
3333
* long as you retain the public fields.
3434
*/
@@ -129,8 +129,7 @@ public String getMessage() {
129129
msg.append("parse error [");
130130
msg.append((file != null) ? file.toString() : "?");
131131
msg.append(":");
132-
msg.append((sourceRange != null) ? sourceRange.toString()
133-
: "?");
132+
msg.append((sourceRange != null) ? sourceRange.toString() : "?");
134133
msg.append("]\n");
135134
msg.append(super.getMessage());
136135
return msg.toString();
@@ -152,14 +151,10 @@ public String getMessage() {
152151
}
153152
String retval = "parse error ";
154153
retval += (file != null) ? "[" + file + ":" : "[?:";
155-
if (sourceRange != null) {
156-
retval += sourceRange.toString() + "]\n";
157-
} else {
158-
retval += currentToken.next.beginLine + "."
159-
+ currentToken.next.beginColumn + "-"
160-
+ currentToken.next.endLine + "."
161-
+ currentToken.next.endLine + "]\n";
162-
}
154+
if (sourceRange == null) {
155+
sourceRange = PanParserUtils.sourceRangeFromTokens(currentToken.next, currentToken.next);
156+
};
157+
retval += sourceRange.toString() + "]\n";
163158
retval += "\nEncountered: ";
164159
Token tok = currentToken.next;
165160
for (int i = 0; i < maxSize; i++) {

panc/src/main/java/org/quattor/pan/ttemplate/SourceRange.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Centre National de la Recherche Scientifique (CNRS).
2323
/**
2424
* Defines a range of characters within a source pan template that is used to
2525
* provide detailed error messages.
26-
*
26+
*
2727
* @author loomis
28-
*
28+
*
2929
*/
3030
public class SourceRange {
3131

@@ -45,13 +45,13 @@ public SourceRange(int beginLine, int beginColumn, int endLine,
4545
throw new IllegalArgumentException("beginLine must be positive");
4646
}
4747
if (beginColumn < 1) {
48-
throw new IllegalArgumentException("beginLine must be positive");
48+
throw new IllegalArgumentException("beginColumn must be positive");
4949
}
5050
if (endLine < 1) {
5151
throw new IllegalArgumentException("endLine must be positive");
5252
}
5353
if (endColumn < 1) {
54-
throw new IllegalArgumentException("endLine must be positive");
54+
throw new IllegalArgumentException("endColumn must be positive");
5555
}
5656

5757
// Check that ending point is after (or the same as) the starting point.

0 commit comments

Comments
 (0)