[antlr-interest] Someting about range (to change)

Bart Kiers bkiers at gmail.com
Tue Jun 28 22:51:59 PDT 2011


Hi Fabien,

Can you post the grammar that produces the error?

Bart.


On Wed, Jun 29, 2011 at 5:57 AM, Fabien Hermenier <hermenierfabien at gmail.com
> wrote:

> Hi
>
> I am sorry, but this is another problem related to sequence of integer.
> I don't understand my error(s), despite severals
> pass on the wiki page related to this use case.
>
> I want to parse a string with a "sequence" parameter into it, such as
> "toto-[2 ..3]-toto".
> Here is a short version of the grammar that works perfectly:
> ---
> grammar tryout;
>
> options {
>     k=3;
> }
> fragment Digit :'0'..'9';
> DEC_NUMBER: '1'..'9' Digit*;
>
> fragment Letter    :'a'..'z'|'A'..'Z';
>
> WS    :    ('\n'|'\r'|'\t'|' ') {$channel=HIDDEN;};
> LEFTY: (Letter|Digit) (Letter|Digit|'-')* '[';
> RIGHTY: ']' (('-' (Letter|Digit))|Letter|Digit)* ;
>
>
> number :DEC_NUMBER; //HEX_NUMBER, OCT_NUMBER, ... are following but
> removed for this example.
>
> range: LEFTY number '..' number RIGHTY;
> ---
>
> This grammar accepts "toto-[1..3]-toto" or "toto-[1 .. 3]-toto".
> Now, I want to be able to accept the LEFTY token or the RIGHTY token
> even if they contains a '.' inside (not at the beginning). So I've
> modified LEFTY as following:
> LEFTY: (Letter|Digit) ('.'|Letter|Digit|'-')* '[';
>
> Now, ANTLR does no longer accept "toto-[1..3]-toto". It requires at
> least one space between the first number and the range.
> I have read the wiki page related to range, integer, and so one. But in
> my case, I don't see where my grammar is ambiguous as no token
> can start with a '.' . So it seems there is a concept I don't get. Can
> anyone try to help me ?
>
> Thanks in advance,
> Fabien.
>
> 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