[antlr-interest] Lexer for a grammar similar to a template engine
Gavin Lambert
antlr at mirality.co.nz
Sun Oct 11 13:00:00 PDT 2009
At 23:43 11/10/2009, Graham Wideman wrote:
>First off, your OTHER rule should contain OR not AND if you want
to
>accept '$' or '{' when they are not part of '${'.
>
>Other than that, it should be possible to write this without
>resorting to an action (semantic predicate), which would allow
>visualizing in ANTLRworks and so on.
It's probably best to do the initial split at "replacement string"
vs. "everything else". Then you can further evaluate the
replacement string at the parser level:
file: ( TEXT { /* print out the text */ }
| STRING { /* look up and fill in the replacement */ }
)* EOF;
STRING: '${' (~'}')* '}';
TEXT: (~'$' | '$' ~'{')+;
More information about the antlr-interest
mailing list