escape [\r\n\t] in lexical error messages. Fixes antlr/antlr4#75
This commit is contained in:
parent
11385f7920
commit
7049972ab7
|
@ -1,5 +1,11 @@
|
|||
ANTLR v4 Honey Badger
|
||||
|
||||
December 1, 2012
|
||||
|
||||
* escape [\n\r\t] in lexical error messages; e.g,:
|
||||
line 2:3 token recognition error at: '\t'
|
||||
line 2:4 token recognition error at: '\n'
|
||||
|
||||
November 26, 2012
|
||||
|
||||
* Don't generate action methods for lexer rules not containing an action
|
||||
|
|
|
@ -376,14 +376,22 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
|
|||
}
|
||||
|
||||
public void notifyListeners(LexerNoViableAltException e) {
|
||||
String msg = "token recognition error at: '"+
|
||||
_input.getText(Interval.of(_tokenStartCharIndex, _input.index()))+"'";
|
||||
String text = _input.getText(Interval.of(_tokenStartCharIndex, _input.index()));
|
||||
String msg = "token recognition error at: '"+ getErrorDisplay(text) + "'";
|
||||
|
||||
ANTLRErrorListener listener = getErrorListenerDispatch();
|
||||
listener.syntaxError(this, null, _tokenStartLine, _tokenStartCharPositionInLine, msg, e);
|
||||
}
|
||||
|
||||
public String getCharErrorDisplay(int c) {
|
||||
public String getErrorDisplay(String s) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (char c : s.toCharArray()) {
|
||||
buf.append(getErrorDisplay(c));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getErrorDisplay(int c) {
|
||||
String s = String.valueOf((char)c);
|
||||
switch ( c ) {
|
||||
case Token.EOF :
|
||||
|
@ -399,6 +407,11 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
|
|||
s = "\\r";
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public String getCharErrorDisplay(int c) {
|
||||
String s = getErrorDisplay(c);
|
||||
return "'"+s+"'";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue