Vote count: 0 The language that I am lexing requires the ability to hot-swap keywords depending on runtime configuration. It's relatively simple how to do this so long as you are OK embedding target-specific code in your grammar (Java):1 lexer grammar LanguageLexer; tokens { If, Else, While // etc } @header { import java.util.Map; } @members { private Map keywords; public NafiLexer(CharStream input, Map keywords) { this(input); this.keywords = keywords; } } WS: [ ntr]+ -> skip; ID: [a-zA-Z]+ { if(keywords.containsKey(getText())) setType(keywords.get(getText())); }; However, I would like to remove all target-specific code from my .g4 file, as my .g4s will be used across multiple target langua...
ادامه مطلب