[antlr-interest] Multiple string template rule

Jim Idle jimi at temporal-wave.com
Tue Oct 25 11:55:38 PDT 2011


Are all your rules either setting $st before they return or creating a
template with ->template(.... or similar? Producing the template is not
automatic.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Tim Poole
> Sent: Tuesday, October 25, 2011 10:00 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Multiple string template rule
>
> :$
>
> That's a bit embarrasing!
>
> OK, so I am actually trying to do a similar thing for both the OR
> statements and the AND statements.
>
> What I didn't explain was that the "<bf ...>" expression isn't
> contributing anything, so it looks like the "b+=andExpr" isn't catching
> anything from the token.
>
> There is an example rule including "( p+=parameterDef )*" but this is
> slightly different to my "(OR b+=andExpr)*".
>
> I suspect that I probably need something closer to "<bf:{ expr | \|\|
> <expr> }>".
> I have tried something similar, but the lack of data in bf seems to be
> the limiting factor.
>
> I'm hoping it's possible, just that I don't understand how to do it,
> yet.
>
> Any thoughts gratefully received...
>
> I'm trying to convert:
>
> rule != "working" or mental_state == "distressed"
>
> into:
>
> rule != "working" || mental_state == "distressed"
>
> Obviously, this snippet of grammar doesn't cover the expressions
> (andExpr) on either side of the "or", but I hope it gives you a flavour
> of what I'm trying to achieve.
>
> orExpr
>       : a=andExpr (OR b+=andExpr)* ->  template(a={$a.text}, bf={$b})
> "<a><bf; separator=\" || \">"
>       ;
>
> Regards,
>
> Tim.
>
> On 25/10/2011 17:02, Jim Idle wrote:
> > Probably because you are modifying the OR rule and not the AND rule.
> >
> > Jim
> >
> >> -----Original Message-----
> >> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> >> bounces at antlr.org] On Behalf Of Tim Poole
> >> Sent: Tuesday, October 25, 2011 8:54 AM
> >> To: antlr-interest at antlr.org
> >> Subject: [antlr-interest] Multiple string template rule
> >>
> >> Hi all,
> >>
> >> I'm trying to use the += in the following rule, but I'm not sure if
> >> my use of it is correct.
> >>
> >> Does anyone have any thoughts?
> >>
> >> I'm trying to convert:
> >>
> >> rule != "working" and mental_state == "distressed"
> >>
> >> into:
> >>
> >> rule != "working"&&  mental_state == "distressed"
> >>
> >> Obviously, this snippet of grammar doesn't cover the expressions
> >> (andExpr) on either side of the "and", but I hope it gives you a
> >> flavour of what I'm trying to achieve.
> >>
> >> orExpr
> >>       : a=andExpr (OR b+=andExpr)* ->  template(a={$a.text},
> bf={$b})
> >> "<a><bf; separator=\"&&  \">"
> >>       ;
> >>
> >> Regards,
> >>
> >> Tim.
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe:
> >> http://www.antlr.org/mailman/options/antlr-interest/your-
> >> email-address
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> > http://www.antlr.org/mailman/options/antlr-interest/your-email-
> address
> >
> >
> > -----
> > No virus found in this message.
> > Checked by AVG - www.avg.com
> > Version: 2012.0.1834 / Virus Database: 2092/4572 - Release Date:
> > 10/24/11
>
> 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