Is there a way to provide a lexer's predicate with the current token's value? for instance, in my lexer grammar FlowLexer
, I dynamically load tokens:
Before I parse, I load the tokens dynamically:
var lexer = new FlowLexer(new AntlrInputStream(flowContent)) {
TokenExists = tokenValue => tokensDictionary.ContainsKey(tokenValue)
};
And then during parsing/lexing, the TokenExists
predicate is called:
@lexer::members{
public Func<string,bool> TokenExists = null;
}
/* ... stuff ... */
TOK : [-_.0-9a-zA-Z]+
{!TokenExists(/*WHAT GOES HERE?*/);}?
-> mode(IN_TOKEN);
/* ... stuff ... */
But how do I pass the token value to the TokenExists
predicate?
(This is an attempt to create context-aware lexer: I have several mode
s, and in which one there are different rules).