Skip to content

Instantly share code, notes, and snippets.

@lvjp
Created October 7, 2018 21:14
Show Gist options
  • Save lvjp/7449854156a61f63661b0817da4b0fad to your computer and use it in GitHub Desktop.
Save lvjp/7449854156a61f63661b0817da4b0fad to your computer and use it in GitHub Desktop.
ANTLR4.7 : Lexer more and getText() are not friend ?
lexer grammar MoreSetTextLexer;
tokens {
DecodedValue
}
ValueDetector: '@' -> more, pushMode(ValueDecoder);
mode ValueDecoder;
EndOfValue : '@' -> popMode, type(DecodedValue);
SpecialChar
: '&' ~([;])* ';'
{
final String text = getText();
System.out.println("An & --> " + getText());
setText("&" + getText().substring(1, getText().length() -1).toUpperCase() + ";");
}
-> more
;
Others : . { System.out.println("One more char: " + getText()); } -> more ;
parser grammar MoreSetTextParser;
options {
tokenVocab=MoreSetTextLexer;
}
file : DecodedValue+ ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment