> I defined the following grammar:
>
> grammar Hello;
>
> hello: '{' pair '}';
> pair: '"name"' ':' STRING;
This implicitly defines "name" (including the double quotes) as a keyword.
>
> STRING: '"' (~ ["\\\u0000-\u001F])* '"';
And that keyword comes before the STRING rule in the grammar, so it is matched first.
> WS: [ \t\n\r] + -> skip;
>
> It works when tested with the input { "name": "hello" }. It does not when parsing { "name": "name" }. The error is mismatched input '"name"' expecting STRING
The input "name" (including the double quotes) will never be matched by the STRING rule and hence will never appear as string in the pair rule.
Print your token stream to the terminal to see which token values you get, when you have problems with tokens.
Mike
--
www.soft-gems.net