Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Cross Referencing different Types
Cross Referencing different Types [message #1839589] Wed, 24 March 2021 05:44 Go to next message
Eclipse UserFriend
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 05:45] by Moderator

Re: Cross Referencing different Types [message #1839590 is a reply to message #1839589] Wed, 24 March 2021 05:46 Go to previous messageGo to next message
Eclipse UserFriend
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/
Re: Cross Referencing different Types [message #1840595 is a reply to message #1839590] Tue, 20 April 2021 06:23 Go to previous message
Eclipse UserFriend
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: Sun Jul 06 11:17:13 EDT 2025

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

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

Back to the top