[antlr-interest] How to handle single and plural (i.e. 'day' or 'days')
Colin Yates
colin.yates at gmail.com
Tue Oct 26 06:54:58 PDT 2010
Ah OK - many many thanks.
Col
On 26 October 2010 14:10, Martijn Reuvers <martijn.reuvers at gmail.com> wrote:
> Hello Colin,
>
> You are missing a space in between.
>
> This should work:
>
> grammar test;
>
> someRule : DAY+
> ;
>
> DAY :
> 'day' 's'?
> ;
>
> Note that DAY is a lexer token.
>
> Cheers!
> Martijn
>
>
>
> On Tue, Oct 26, 2010 at 1:34 PM, Colin Yates <colin.yates at gmail.com>
> wrote:
> > Hi,
> >
> > The user can type in '1 day' or '7 days'. I have the following rule
> which
> > matches:
> >
> > durationPeriod: ('day' | 'days') { // do something};
> >
> > and this works fine. I initially tried:
> >
> > durationPeriod: 'day'('s')? { // do something};
> >
> > but this never matched 'days'.
> >
> > Based on the '100 monkeys' reality I tried the following:
> >
> > durationPeriod: ('day''s')? { // do something};
> > and
> > durationPeriod: ('day')('s')? { // do something};
> >
> > but none of them matched 'days'. The exact error is [line 1:2 no viable
> > alternative at input 'days'']
> >
> > What have I missed? The (incredibly useful!) Syntax Diagram in antlworks
> > shows that the trailing 's' can be skipped, so I don't understand why it
> > doesn't work.
> >
> > Many thanks,
> >
> > Col
> >
> > 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