[antlr-interest] Capturing a grammar block as a string
Ilya Sterin
sterini at gmail.com
Tue Nov 25 14:53:36 PST 2008
Awesome, got it working just as you mentioned, by defining it as a
lexer rule. I got it there accidentally by just using good practices,
but you've pointed out why it didn't originally work.
Yeah, I won't be using it for any other constructs. The idea is that
basically anything between the braces will get evaluated by a JSON lib
in the application itself. I don't particularly need to parse JSON
grammar with Antlr for now as I can just allow JSON libs to do it I'm
sure in a non as efficient manner, but am planning on parsing with
Antlr in the future when the time permits to refactor.
Thanks a bunch to everyone.
Ilya Sterin
On Mon, Nov 24, 2008 at 2:28 PM, Gavin Lambert <antlr at mirality.co.nz> wrote:
> 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