Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to refer to two rules at the same time
How to refer to two rules at the same time [message #908249] Wed, 05 September 2012 02:43 Go to next message
Tu Do is currently offline Tu DoFriend
Messages: 21
Registered: August 2012
Junior Member
Here is the sample rule (Just replace it in MyDsl grammar):

Start:
    elem += (integer)*
;   

int_rule:
    properties += (property)* 'int' (name += integer ('=' values += INT)?) (',' name+=integer ('=' values += INT)?)* ';'
;

/* I have to put the rule name as "integer", so when users hover
 * on variable names, they see exactly type "integer". This is a bit
 * adhoc, but it's acceptable for the time being. However, using this method
 * If some other rules refer to "integer", it can only either retrieve the name
 * in this "integer" rule or its
 */
integer:
    name = ID
;

/*
 * Example: assignment like static final num1 = 2, num2 = 3.... the variable name of type integer can't be referred, since I have to either refer to "int_rule" rule to retrieve its value and its properties or "integer" to retrieve its name. I can't get both.
 */
assignment:
    name = [integer] // or name = [int_rule]
;

enum property:
     'final' | 'static' | 'public' | 'private'
;


I explained in the comments. Basically, the rule for integer is made up of two rules: int_rule and integer and I want to use both in assignment rule. However, Xtext can only let me refer to one rule, and the name feature can just refer to one name instance of the rule, but not multiple name instances in the same rule like in the example. I really need both the informations from both rules, yet I can only refer to one of them.

[Updated on: Wed, 05 September 2012 03:10]

Report message to a moderator

Re: How to refer to two rules at the same time [message #908799 is a reply to message #908249] Thu, 06 September 2012 02:53 Go to previous message
Tu Do is currently offline Tu DoFriend
Messages: 21
Registered: August 2012
Junior Member
Solved it. I just need to refer to "integer" and use the method eContainer() to get its container, "int_rule" then retrieve the info of "int_rule".
Previous Topic:Linking to a java class with specific criteria ?
Next Topic:[xtend] Type Parameter for Create Function?
Goto Forum:
  


Current Time: Fri Feb 28 06:47:53 GMT 2020

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

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

Back to the top