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