[antlr-interest] Capturing a grammar block as a string
Gavin Lambert
antlr at mirality.co.nz
Mon Nov 24 11:28:28 PST 2008
At 13:22 24/11/2008, Ilya Sterin wrote:
>So in my grammar, I capture blocks of JSON-like structures. I
>don't want antlr to try to parse that structure, but rather to
>evaluate it as a string.
>
>Here is a sample code...
>
>define project as {
> "name": "some_widget",
> "version": "0.01-alpha"
>}
[...]
>json
> : '{' .* '}'
> ;
The problem is because you've used a parser rule instead of a
lexer rule (and thus . means "any token", not "any
character"). If you change this to a lexer rule, then it should
work.
(Of course, this assumes that {...} isn't used for any other
construct in your language. If it is, then things get more
complicated.)
More information about the antlr-interest
mailing list