Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross Referencing different Types
Cross Referencing different Types [message #1839589] Wed, 24 March 2021 09:44 Go to next message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
I have three different Definitions in my Grammar. Signals, Parameters, Enumerations.

I would like to reference all of these in the same place called Assignment without additional Keywords to differentiate between them. The uniqueness of their names is ensured by validation.

Here is a minimal example:

Grammar:
Model:
	(defs +=Definition | assignments += Assignment)*
;

Definition:
	SignalDefinition | ParameterDefinition | EnumDefinition
;

SignalDefinition:
	's' definition=ID
;

ParameterDefinition:
	'p' definition=FQN
;

EnumDefinition:
	'e' definition=ID '{' elements+=ID ('.' elements+=ID) '}'
;

Assignment:
	Identifier '=' INT ';'
;

Identifier:
	ref=[Definition|FQN]
;

FQN:
	ID ('.' ID)*
;


Code Example:
p A
p A.e.f
s B
e ENUMCLASS1 {ELEMENT1, ELEMENT2}
e ENUMCLASS2 {ELEMENT3, ELEMENT4}


// should work
A = 1;
A.e.f = 2;
B = 3;
ENUMCLASS1.ELEMENT1 = 4;

// should not find a reference
ENUMCLASS1.ELEMENT3 = 5;
A.e = 6;
C = 7;



How could I adapt my Grammar or my Scoping or Linking to achieve that? I tried to do it with Scoping but it seems that I dont fully understand how it works.

Thank you for your help in advance.

Lukas

[Updated on: Wed, 24 March 2021 09:45]

Report message to a moderator

Re: Cross Referencing different Types [message #1839590 is a reply to message #1839589] Wed, 24 March 2021 09:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you have to adapt name provider or change the grammar to use name=ID
see https://dietrich-it.de/xtext/2011/07/16/iqualifiednameproviders-in-xtext-2.0/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross Referencing different Types [message #1840595 is a reply to message #1839590] Tue, 20 April 2021 10:23 Go to previous message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
Thank you Christian,

that article pointed me in the right direction. I was able to make it work.
Previous Topic:Xtext LSP, Client with separate server process
Next Topic:Missing folders when create xtext projects from existing ecore
Goto Forum:
  


Current Time: Sat Apr 20 00:45:37 GMT 2024

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

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

Back to the top