Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Omitting root name in references
Omitting root name in references [message #1783030] Tue, 06 March 2018 23:07 Go to next message
Ray Kerstens is currently offline Ray KerstensFriend
Messages: 8
Registered: January 2018
Junior Member
Hi all,

I have two DLS. In the second DSL I which to use a reference to a element of the first DSL. This element is element of the root, but since the root has a name, it expects the input as [RootName].[ElementName]. Since there is only one root, I'd want this reference to be just [ElementName]. I expect it has to do with scoping, but I can't seem to work this one out. I'm extending an already existing DSL I don't want to remove the name of the Root. Any idea's? I included a simple example to make my problem more tangible:

Grammar first language:
System:
"System" name=ID
elements+=Element*
;
Element:
"Element"
name = ID
;


Example first language:
System system1
Element bar


Grammar second language:
Variables:
"Variable" name=ID "of" "Element" [FirstLanguage::Element|FQN]
;


Example second language:
Variable foo of Element bar


FQN is defined as
FQN: ID ("." ID)*;
Re: Omitting root name in references [message #1783037 is a reply to message #1783030] Wed, 07 March 2018 05:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
What if you have two systems with the same element


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Omitting root name in references [message #1783043 is a reply to message #1783030] Wed, 07 March 2018 06:29 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Yes that's a scoping rule you'd have to implement in your scope provider. As Christian said you should somewhere specify that you refer to elements from a system with a given name. Often namspace imports are used, which would be nearly work out of the box.

Like:
import system1.*

Variable foo of Element bar


In the second DSL add an import concept:

MyModel:
   imports+=Import*
   variables+=Variable*;

Import: 'import' importedNamespace=FQNWithWildcard;

FQNWithWildcard: FQN ('.*')?;

Re: Omitting root name in references [message #1783049 is a reply to message #1783037] Wed, 07 March 2018 08:13 Go to previous messageGo to next message
Ray Kerstens is currently offline Ray KerstensFriend
Messages: 8
Registered: January 2018
Junior Member
Christian Dietrich wrote on Wed, 07 March 2018 05:38
What if you have two systems with the same element


This is restricted in the validator, so that shouldn't be a problem.
Re: Omitting root name in references [message #1783060 is a reply to message #1783043] Wed, 07 March 2018 10:13 Go to previous messageGo to next message
Ray Kerstens is currently offline Ray KerstensFriend
Messages: 8
Registered: January 2018
Junior Member
Karsten Thoms wrote on Wed, 07 March 2018 06:29
Yes that's a scoping rule you'd have to implement in your scope provider. As Christian said you should somewhere specify that you refer to elements from a system with a given name. Often namspace imports are used, which would be nearly work out of the box.

Like:
import system1.*

Variable foo of Element bar


In the second DSL add an import concept:

MyModel:
   imports+=Import*
   variables+=Variable*;

Import: 'import' importedNamespace=FQNWithWildcard;

FQNWithWildcard: FQN ('.*')?;



If I ware to implement this I should add some scoping right? I'm not sure how I would approach this as the importedNamespace is not linked (referenced) to the first DSL
Re: Omitting root name in references [message #1783061 is a reply to message #1783060] Wed, 07 March 2018 10:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
it is not linked.
and validation wont help

if you have

system x element y
and
system z element y

and refer to y which one should be picked?

and is y simple name specific to dslb or to all dsls using y


so you chould change the nameprovider of system dsl to give simple names.
or you could use imports.
imports carer about names only.
they dont care where they come from


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Omitting root name in references [message #1783071 is a reply to message #1783061] Wed, 07 March 2018 10:32 Go to previous messageGo to next message
Ray Kerstens is currently offline Ray KerstensFriend
Messages: 8
Registered: January 2018
Junior Member
Ah I get your meaning. Although validation would work for multiple systems defined in one file it wouldn't work for multiple files.

y is used by multiple dsls (on different levels, not always as a child of the root). So as of now the second dsl grammer is:
MyModel:
   imports+=Import*
   variables+=Variable*;

Import: 'import' importedNamespace=FQNWithWildcard;

FQNWithWildcard: FQN ('.*')?;

Variables:
   "Variable" name=ID "of" "Element" [FirstLanguage::Element|FQN]
;


How then would the DSL understand that I mean element y of system named (but not cross referenced) importedNameSpace?
Re: Omitting root name in references [message #1783072 is a reply to message #1783071] Wed, 07 March 2018 10:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
it wont. it will see that there is a global x.y system and that you import x.*
so the name y you write could actually mean x.y


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Omitting root name in references [message #1783073 is a reply to message #1783072] Wed, 07 March 2018 10:43 Go to previous messageGo to next message
Ray Kerstens is currently offline Ray KerstensFriend
Messages: 8
Registered: January 2018
Junior Member
Then I'm probably doing something wrong here. It's telling me it cannot resolve the reference to y, and content assist suggests me x.y which does not give the 'cannot resolve reference' error.

Current state of the first dsl (grammar):
System:
    "System" name=ID
    elements+=Element*
;
Element:
    "Element"
    name = ID
;


Current state of second dsl (grammar):
MyModel:
   imports+=Import*
   variables+=Variable*;

Import: 'import' importedNamespace=FQNWithWildcard;

FQNWithWildcard: FQN ('.*')?;

Variables:
   "Variable" name=ID "of" "Element" [FirstLanguage::Element|FQN]
;


examples:
example language1:
System system1
    Element bar

example language2
import system1.*
Variable foo of Element bar
Re: Omitting root name in references [message #1783077 is a reply to message #1783073] Wed, 07 March 2018 11:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
cannot reproduce.

can you share your complete hello world projects


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Omitting root name in references [message #1783082 is a reply to message #1783077] Wed, 07 March 2018 13:35 Go to previous message
Ray Kerstens is currently offline Ray KerstensFriend
Messages: 8
Registered: January 2018
Junior Member
Hmm, never mind. It seems to work now. Probably has to do with the clean and restart of the workspace I did...
Thanks Christian!
Previous Topic:Assert error in FormatterTestHelper due to different whitespace in ITextRegionAccess strings.
Next Topic:Create dynamically primitive types that are defined in a types ecore model
Goto Forum:
  


Current Time: Fri Mar 29 07:15:24 GMT 2024

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

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

Back to the top