[antlr-interest] Reading all text to end-of-line in a rule

Massimiliano Donini maxgbr at hotmail.it
Fri Nov 26 11:15:19 PST 2010


  Can you send complete grammar?
That error is about lexer rules order

Max

Il 26/11/2010 20:09, Bill Lear ha scritto:
> On Friday, November 26, 2010 at 19:23:24 (+0100) Martijn Reuvers writes:
>> Hello Bill,
>>
>> The grammar below does the trick for your command (I stripped it
>> somewhat, to quickly get it working). See the SHELL_COMMAND token,
>> notice the options part with the greedy identifier. It reads until it
>> encounters the newline stuff. You need to have something in front of
>> it, like SHELL in this example - otherwise it would match anything,
>> which is not what you want.
> Thanks Martijn.  I tried replacing my original COMMAND_TEXT with
> your suggestion:
>
> COMMAND_TEXT: (options {greedy=false;} : . )* '\r'? '\n' {
>          setText(getText().trim());
>      }
>      ;
>
> and though this reduces the conflict, I still have one I don't know how
> to resolve:
>
> error(208): Command.g:124:1: The following token definitions can never be matched because prior tokens match the same input: NEWLINE
>
> I need the NEWLINE so I can limit the commands to a single line.  Here is
> one part of the grammar I did not share that is relevant, along with
> the parts I changed with your help:
>
> command
>      : (clean|shell) (NEWLINE | EOF)
>      | NEWLINE
>      ;
>
> [clean as before]
>
> shell : 'shell' timeoutOption? COMMAND_TEXT ;
>
> [timeoutOption as before, etc.]
>
> COMMAND_TEXT: (options {greedy=false;} : . )* '\r'? '\n' {
>          setText(getText().trim());
>      }
>      ;
> EMAIL: ~('\n' | '\r' | ' ' | '"')+ ;
> NEWLINE: '\r'? '\n' ;
> WS: (' ' | '\t')+ { skip(); } ;
>
> So, how do I preserve the single-line command idiom with the shell command
> "read-to-end-of" line part?
>
>
> Bill
>
> 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