Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Expression and Remembering Parentheses
icon5.gif  Expression and Remembering Parentheses [message #1511280] Sun, 14 December 2014 15:45 Go to next message
Eclipse UserFriend
I am fairly new to Xtext and I am trying to build a expression in grammar that will let me construct a SQL where clause in generated code. Here is what I have so far:
Query:
  'query' expression=Expression
;

Expression:
  Or;
  
Or returns Expression:
  And ({Or.left=current} "||" right=And)*
;
  
And returns Expression:
  Primary ({And.left=current} "&&" right=Primary)*
;
  
Primary returns Expression:
  '(' Expression ')' |
  Atomic
;
  
Atomic returns Expression:
  value=AttributeCriteria
;


All of this is working great so far. I can build the complex expressions with parentheses but the generated model doesn't remember the parentheses. I need that information to be brought into the model so I can construct my SQL where clause with the matching parens. What do I need to add to the grammar so I can remember the nested parentheses in the generated model? Thanks.
Re: Expression and Remembering Parentheses [message #1511455 is a reply to message #1511280] Sun, 14 December 2014 19:13 Go to previous messageGo to next message
Eclipse UserFriend
On 2014-14-12 21:45, Matt Bertolini wrote:
> I am fairly new to Xtext and I am trying to build a expression in
> grammar that will let me construct a SQL where clause in generated code.
> Here is what I have so far:
>
> Query:
> 'query' expression=Expression
> ;
>
> Expression:
> Or;
>
> Or returns Expression:
> And ({Or.left=current} "||" right=And)*
> ;
>
> And returns Expression:
> Primary ({And.left=current} "&&" right=Primary)*
> ;
>
> Primary returns Expression:
> '(' Expression ')' |
> Atomic
> ;
>
> Atomic returns Expression:
> value=AttributeCriteria
> ;
>
>
> All of this is working great so far. I can build the complex expressions
> with parentheses but the generated model doesn't remember the
> parentheses. I need that information to be brought into the model so I
> can construct my SQL where clause with the matching parens. What do I
> need to add to the grammar so I can remember the nested parentheses in
> the generated model? Thanks.

Now, your Primary expression simply produces Expression - change this
rule and add a rule that represents a parenthesized expression - like this:

Primary
: ParenthesizedExpression
| Atomic
;

ParenthesizedExpression
: '(' expr = Expression ')'
;


Regards
- henrik
Re: Expression and Remembering Parentheses [message #1512328 is a reply to message #1511455] Mon, 15 December 2014 12:06 Go to previous message
Eclipse UserFriend
Thanks for the reply. That makes sense now. I now have it working. Thanks for the help!
Previous Topic:XText standalone content assistant
Next Topic:Custom Preferences Page
Goto Forum:
  


Current Time: Mon Nov 03 14:46:34 EST 2025

Powered by FUDForum. Page generated in 0.03667 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top