[antlr-interest] Comment rule matches links

Thomas Brandon tbrandonau at gmail.com
Tue Aug 26 01:41:22 PDT 2008


On Tue, Aug 26, 2008 at 6:24 PM, Jenny Balfer
<ai06087 at lehre.ba-stuttgart.de> wrote:
>
> My problem are regular expressions that match quotes, like this one:
>
> replace(/"/, "&quot;");
>
> In this case, the STRING rule matches everything from the first to the
> second quote, which is "/, ", and then takes everything beginning from the
> last quote sign to any further one.
> I already found the article about island grammars
> (http://www.antlr.org/wiki/display/ANTLR3/Island+Grammars+Under+Parser+Control),
> but I have no idea how I can apply this solution for my problem, for the
> workaround is for parser grammars and my STRING / COMMENT rules are still
> part of the lexer.
>
If you don't need the regular expression structure you can just match
them as a single token. If you do need structure you could either just
use a seperate grammar in a later phase to process the single tokens
in your main token stream or use the technique from the island-grammar
example, which shows island grammars under lexer control, to include
it in the main token stream. The ANTLR examples are at
http://www.antlr.org/download/examples-v3.tar.gz.

Tom.


More information about the antlr-interest mailing list