[antlr-interest] keywords and arbitrary text

Jim Idle jimi at temporal-wave.com
Wed Jul 7 13:42:35 PDT 2010


You just need:


TITLE : 'Title' (~('\n'|'\r'))* ;

Then look for TITLE in your parser.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Peter Hull
> Sent: Wednesday, July 07, 2010 12:58 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] keywords and arbitrary text
> 
> Hi all, here is a quick question from a new user.
> I have a simple language I want to parse. Each line is a separate
> command and each command looks something like
> KEYWORD param param...
> e.g.
> SetGate 10 4.5
> However there's a title command that can take any text up to the end
> of line, e.g
> Title Configuration 1
> or even
> Title This is a Title
> I had a rule
> TEXT: ~('\n'|'\r')+
> but this (I think) matched all the keywords too, even if I used tokens
> {...}
> Is there a way to say that the TEXT token is only to be used after
> Title? I saw something on island grammars but I couldn't understand it
> to be honest.
> 
> Pete
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list