[antlr-interest] Follow up to hoisted predicates and local variables
Mike Lischke
mike at lischke-online.de
Fri Sep 14 09:31:28 PDT 2012
Hi,
I'm bitten by this problem as well: http://antlr.markmail.org/message/eliyhfji5hsrbyoz?q=hoisted+predicates+and+local+variables
but with lexer rules and wonder what would be a good approach to solve this case? I couldn't get global scopes to work because I cannot use them in a lexer rule. Lexer member vars seem to be a good solution, but they are evaluated in the dfa15_sst helper before they are actually set.
Here's the relevant code:
fragment BLOCK_COMMENT options{ greedy = false; }:
VERSION_COMMENT
| MULTILINE_COMMENT
;
fragment VERSION_COMMENT:
LOGICAL_NOT_OPERATOR (v = INTEGER WS { matched_version = check_version($v); })? VERSION_COMMENT_TAIL
;
fragment VERSION_COMMENT_TAIL:
{ !matched_version }? => ( options { greedy = false; }: . )* '*' '/' { $type = MULTILINE_COMMENT; $channel = 98; }
| { $type = VERSION_COMMENT; $channel = 98; in_version_comment = true; }
(the initial /* is consumed by a higher level rule).
Mike
--
www.soft-gems.net
More information about the antlr-interest
mailing list