forked from jasder/antlr
mode wasn't working as lexer command
This commit is contained in:
parent
ebb8b3a15b
commit
97ab2c42da
|
@ -642,8 +642,8 @@ lexerCommands
|
|||
;
|
||||
|
||||
lexerCommand
|
||||
: id LPAREN lexerCommandExpr RPAREN -> ^(LEXER_ACTION_CALL id lexerCommandExpr)
|
||||
| id
|
||||
: lexerCommandName LPAREN lexerCommandExpr RPAREN -> ^(LEXER_ACTION_CALL lexerCommandName lexerCommandExpr)
|
||||
| lexerCommandName
|
||||
;
|
||||
|
||||
lexerCommandExpr
|
||||
|
@ -651,6 +651,11 @@ lexerCommandExpr
|
|||
| INT
|
||||
;
|
||||
|
||||
lexerCommandName
|
||||
: id
|
||||
| MODE ->ID[$MODE]
|
||||
;
|
||||
|
||||
altList
|
||||
: alternative (OR alternative)* -> alternative+
|
||||
;
|
||||
|
|
|
@ -119,6 +119,38 @@ public class TestLexerExec extends BaseTest {
|
|||
assertEquals(expecting, found);
|
||||
}
|
||||
|
||||
@Test public void testLexerPushPopModeAction() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n" +
|
||||
"STRING_START : '\"' -> pushMode(STRING_MODE), more ;\n" +
|
||||
"WS : (' '|'\n') -> skip ;\n"+
|
||||
"mode STRING_MODE;\n"+
|
||||
"STRING : '\"' -> popMode ;\n"+
|
||||
"ANY : . -> more ;\n";
|
||||
String found = execLexer("L.g", grammar, "L", "\"abc\" \"ab\"");
|
||||
String expecting =
|
||||
"[@0,0:4='\"abc\"',<5>,1:0]\n" +
|
||||
"[@1,6:9='\"ab\"',<5>,1:6]\n" +
|
||||
"[@2,10:9='<EOF>',<-1>,1:10]\n";
|
||||
assertEquals(expecting, found);
|
||||
}
|
||||
|
||||
@Test public void testLexerModeAction() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n" +
|
||||
"STRING_START : '\"' -> mode(STRING_MODE), more ;\n" +
|
||||
"WS : (' '|'\n') -> skip ;\n"+
|
||||
"mode STRING_MODE;\n"+
|
||||
"STRING : '\"' -> mode(DEFAULT_MODE) ;\n"+
|
||||
"ANY : . -> more ;\n";
|
||||
String found = execLexer("L.g", grammar, "L", "\"abc\" \"ab\"");
|
||||
String expecting =
|
||||
"[@0,0:4='\"abc\"',<5>,1:0]\n" +
|
||||
"[@1,6:9='\"ab\"',<5>,1:6]\n" +
|
||||
"[@2,10:9='<EOF>',<-1>,1:10]\n";
|
||||
assertEquals(expecting, found);
|
||||
}
|
||||
|
||||
@Test public void testKeywordID() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n"+
|
||||
|
|
Loading…
Reference in New Issue