Support zero-length empty lexer rules with lexer commands (fixes #687)

This commit is contained in:
Sam Harwell 2014-08-28 23:44:21 -05:00
parent 6790b25e5b
commit e497efaa58
2 changed files with 6 additions and 4 deletions

View File

@ -547,11 +547,11 @@ lexerAlt
( lexerCommands -> ^(LEXER_ALT_ACTION<AltAST> lexerElements lexerCommands)
| -> lexerElements
)
| -> ^(ALT<AltAST> EPSILON) // empty alt
;
lexerElements
: lexerElement+ -> ^(ALT<AltAST> lexerElement+)
: lexerElement+ -> ^(ALT<AltAST> lexerElement+)
| -> ^(ALT<AltAST> EPSILON) // empty alt
;
lexerElement

View File

@ -659,8 +659,10 @@ public class TestLexerExec extends BaseTest {
}
/**
* This is a regression test for antlr/antlr4#688 "Lexer cannot match
* This is a regression test for antlr/antlr4#687 "Empty zero-length tokens
* cannot have lexer commands" and antlr/antlr4#688 "Lexer cannot match
* zero-length tokens"
* https://github.com/antlr/antlr4/issues/687
* https://github.com/antlr/antlr4/issues/688
*/
@Test public void testZeroLengthToken() throws Exception {
@ -674,7 +676,7 @@ public class TestLexerExec extends BaseTest {
"mode StringMode;\n" +
"\n" +
" StringMode_X : 'x' -> more;\n" +
" StringMode_Done : {} -> more, mode(EndStringMode);\n" +
" StringMode_Done : -> more, mode(EndStringMode);\n" +
"\n" +
"mode EndStringMode; \n" +
"\n" +