[antlr-interest] Novice Question - Token for all characters from a given point to End of Line

Foust javafoust at gmail.com
Tue Aug 5 12:46:22 PDT 2008


Ø  (options{greedy=false;} : . ) NEW_LINE 

 

Did you mean:

 

                                .*

?

 

Brent

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Matt Palmer
Sent: Tuesday, August 05, 2008 11:22 AM
To: Brisard, Fred D
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Novice Question - Token for all characters
from a given point to End of Line

 

Hi Fred,

You should be able to use predicates, something like this:

COMMAND 
      : 'create' | 'delete'                     { inCommand = true; } 
      ;

COMMAND_TOKEN 
      : {inCommand}?=>
          (options{greedy=false;} : . ) NEW_LINE  { inCommand = false; }
         ;

Matt.

On Tue, Aug 5, 2008 at 7:03 PM, Brisard, Fred D <Fred.Brisard at ca.com> wrote:

I have a keyword style grammar and have the need to accept all the
characters until the end of line to be accepted as a single token.  

For example, I have a statement that is of the following type

Command multiple arguments (EOL)

Where Command can be a command name and the multiple arguments are one or
more arguments.  There can be from 1 to many arguments – each argument does
not have a fixed content – it may be an integer, a string, a quoted string.
The characters in the string can be most anything.

I was looking for something similar to the multiple line comment technique
using the greedy=false option.  Collect all the characters following the
Command into a single token.

Any ideas or suggestions are appreciated.

Regards, Fred

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080805/569520ca/attachment.html 


More information about the antlr-interest mailing list