Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Referencing elements in an external file (with a different grammar)
Referencing elements in an external file (with a different grammar) [message #955057] Tue, 23 October 2012 13:21 Go to next message
Quentin Boucher is currently offline Quentin Boucher
Messages: 27
Registered: July 2012
Junior Member
Hello,

I'm still requiring your help. I have finished my (main) first grammar. Let's call it X. Now, I started implementing the second one (Y) which references elements from X. Links between both grammars work fine and I'm able to access elements from all files implementing X.

My question now is: how can I limit the available files implementing X? I would like to link a Y file with its corresponding X file. But I'm not able to implement an import mechanism supporting that requirements...

Thank you for your help!

Quentin
Re: Referencing elements in an external file (with a different grammar) [message #955946 is a reply to message #955057] Wed, 24 October 2012 05:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
Hi what about simply filtering the global scope by wrapping an extra
filter in your iglobalscopeprovider if you want to apply the
filtering in general or wraping the delegategetscope into a
filteringscope in a specific scope_x_y method for a specific
reference.

In both cases you should be able to filter the ieobjectdescriptions
by their URI.

Alternatively you could try to use importuribased scoping and add an
implicit import.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Referencing elements in an external file (with a different grammar) [message #956194 is a reply to message #955946] Wed, 24 October 2012 10:04 Go to previous messageGo to next message
Quentin Boucher is currently offline Quentin Boucher
Messages: 27
Registered: July 2012
Junior Member
Thank you for your answer!
I would go for a global scope scope in the iglobalscopeprovider. Do you have a useful direct link to such an impelmentation?

Thank you very much!

Quentin
Re: Referencing elements in an external file (with a different grammar) [message #956231 is a reply to message #956194] Wed, 24 October 2012 10:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
No sorry I have not but I'd simply wrap the super call of getscope in
a filteringscope

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Referencing elements in an external file (with a different grammar) [message #958747 is a reply to message #955057] Fri, 26 October 2012 07:28 Go to previous messageGo to next message
Quentin Boucher is currently offline Quentin Boucher
Messages: 27
Registered: July 2012
Junior Member
Thank you for your answer. I finally chose a GlobalScopeProvider and managed to implement it, ot without some difficulty.

I now have a more basic grammar question. Here is a part of it:

Short_ID: 
	  Feature_Declaration
	| Attribute
	| Constant;

Short_IDTail: 
	  Short_ID
	| Shared_Feature
	| Sub_Attribute;

Long_ID: 
	  head=[Short_ID] (tail=(Long_IDTail))?
	| keyword=Shortcut   tail=Long_IDTail;

Long_IDTail: 
	  '.' head=[Short_IDTail] (tail=Long_IDTail)?;


Root_Feature: 'root' name=ID body=Feature_Content;

Hierarchical_Feature: optional?=('opt')? name=ID body=Feature_Content?;

Feature_Declaration: Root_Feature | Hierarchical_Feature;

Attribute:
	  Base_Attribute
	| {Structure_Attribute} type=[Record] name=ID '{' sub_attributes+=Sub_Attribute+ '}';
	
Base_Attribute:
	  type='int' name=ID attr_body=Attribute_Body? ';'
	| type='real' name=ID attr_body=Attribute_Body? ';'
	| type='bool' name=ID attr_body=Attribute_Body? ';'
	| type='enum' name=ID  'in' '{' domain=Enum_List '}'  ( 'is' attr_value=Expression	| ',' attr_condition=Attribute_Conditionnal)? ';'
	| predefined_type=[SimpleType|ID] name=ID attr_body=Attribute_Body? ';';


Enum_List: enums+=Enum_Element (',' enums+=Enum_Element)*;

Enum_Element: name=ID;


I also have the notion of expression where I can use a Long_ID (ie a reference to an attribute, a feature or a constant using a kind of qualified name ) or a direct reference to an Enum_element.

Expression:
	 ...
	| ref=Long_ID
        | elt=[Enum_Element];



However, there is a conflict between both elements do to the ID thing with backtracjong off. If I switch backtracking on it doesn't complain but cannot find references to existing Enum_Elements.

Here are the solutions I have tried:
- force grammar using =>elt=[Enum_Element]
- include Enum_Element in Short_ID (which is not the best solution for me). But there, there is a conflict with Common_Feature. The tests I have conducted brought me to the conclusion that the conflict is with Hierarchical_Feature and Enum_Element. I have thus tried to make a common supertype like: Common_Feature | Enum_Element but the conflict remains.

Do you have any idea of a solution?

Thank you in advance!
Re: Referencing elements in an external file (with a different grammar) [message #959373 is a reply to message #958747] Fri, 26 October 2012 17:12 Go to previous messageGo to next message
Quentin Boucher is currently offline Quentin Boucher
Messages: 27
Registered: July 2012
Junior Member
I guess this is due to the fact that Enum_Element is just composed of an ID. Would you have an alternative solution?

Thank you!
Re: Referencing elements in an external file (with a different grammar) [message #963348 is a reply to message #955057] Mon, 29 October 2012 18:55 Go to previous message
Quentin Boucher is currently offline Quentin Boucher
Messages: 27
Registered: July 2012
Junior Member
Actually, it was just a Qualified Name problem.
Previous Topic:Use ANTLR grammar within Xtext
Next Topic:Eclipse/Xtext crashing
Goto Forum:
  


Current Time: Wed Oct 22 15:38:42 GMT 2014

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

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