Skip to content

Commit b56605c

Browse files
committed
Merge pull request #31 from sharwell/fix-29
Fix issues with syntax errors breaking lexer results (fixes #29)
2 parents 16a6bd3 + 1ddb133 commit b56605c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/grammars/org/antlr/intellij/plugin/parser/ANTLRv4Lexer.g4

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,15 @@ tokens {
103103
}
104104

105105
DOC_COMMENT
106-
: '/**' .*? '*/'
106+
: '/**' .*? ('*/' | EOF)
107107
;
108108

109109
BLOCK_COMMENT
110-
: '/*' .*? '*/' //-> channel(HIDDEN)
110+
: '/*' .*? ('*/' | EOF) -> channel(HIDDEN)
111111
;
112112

113113
LINE_COMMENT
114-
: '//' ~[\r\n]* // -> channel(HIDDEN)
115-
;
116-
117-
DOUBLE_QUOTE_STRING_LITERAL
118-
: '"' ('\\' . | ~'"' )*? '"'
114+
: '//' ~[\r\n]* -> channel(HIDDEN)
119115
;
120116

121117
BEGIN_ARG_ACTION
@@ -209,7 +205,11 @@ INT : [0-9]+
209205
// may contain unicode escape sequences of the form \uxxxx, where x
210206
// is a valid hexadecimal number (as per Java basically).
211207
STRING_LITERAL
212-
: '\'' (ESC_SEQ | ~['\\])* '\''
208+
: '\'' (ESC_SEQ | ~['\r\n\\])* '\''
209+
;
210+
211+
UNTERMINATED_STRING_LITERAL
212+
: '\'' (ESC_SEQ | ~['\r\n\\])*
213213
;
214214
215215
// Any kind of escaped character that we can embed within ANTLR
@@ -221,6 +221,10 @@ ESC_SEQ
221221
[btnfr"'\\]
222222
| // A Java style Unicode escape sequence
223223
UNICODE_ESC
224+
| // Invalid escape
225+
.
226+
| // Invalid escape at end of file
227+
EOF
224228
)
225229
;
226230

src/java/org/antlr/intellij/plugin/ANTLRv4SyntaxHighlighter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
6565
else if ( tokenType == ANTLRv4TokenTypes.TOKEN_ELEMENT_TYPES.get(ANTLRv4Lexer.RULE_REF) ) {
6666
return new TextAttributesKey[]{RULENAME};
6767
}
68-
else if (tokenType == ANTLRv4TokenTypes.TOKEN_ELEMENT_TYPES.get(ANTLRv4Lexer.STRING_LITERAL)) {
68+
else if (tokenType == ANTLRv4TokenTypes.TOKEN_ELEMENT_TYPES.get(ANTLRv4Lexer.STRING_LITERAL)
69+
|| tokenType == ANTLRv4TokenTypes.TOKEN_ELEMENT_TYPES.get(ANTLRv4Lexer.UNTERMINATED_STRING_LITERAL)) {
6970
return STRING_KEYS;
7071
}
7172
else if (tokenType == ANTLRv4TokenTypes.TOKEN_ELEMENT_TYPES.get(ANTLRv4Lexer.BLOCK_COMMENT)) {

0 commit comments

Comments
 (0)