If any lexer rule has a predicate at the beginning of the rule, it will prevent ANTLR from ever caching the start state for the lexer DFA. While this is not necessarily a problem (e.g. for very small inputs), it will quickly dominate performance for anything of reasonable size.
The other predicate you need to move is the one in RegularExpressionLiteral. The following should work. All I did was move the first predicate after the `/`, so it will only be evaluated when a token starts with a `/` character.
RegularExpressionLiteral
: '/' {isRegexPossible()}? RegularExpressionBody '/' RegularExpressionFlags
;
Sam
Hi Raz,
I think it would make sense for IDE extensions to report such an error. For example ANTLRWorks 2 already reports 3 different warnings related to grammar performance.
A better long-term solution in the tool/runtime itself would be modifying the behavior to support LL(1) filtering (past the predicate), and only execute predicates if they remain following the lookahead symbol.
Thanks,
Sam