Skip to main content



      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] Tue, 04 September 2012 22:43 Go to next message
Eclipse UserFriend
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: Tue, 04 September 2012 23:10] by Moderator

Re: How to refer to two rules at the same time [message #908799 is a reply to message #908249] Wed, 05 September 2012 22:53 Go to previous message
Eclipse UserFriend
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: Sat Jul 05 23:53:52 EDT 2025

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

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

Back to the top