Association and cross-referencing [message #1781463] |
Wed, 07 February 2018 14:23 |
Philipp Schneider Messages: 2 Registered: February 2018 Location: München |
Junior Member |
|
|
Hey,
I am trying ways to link and access contained items with cross-referenced IDs, here, I have the following grammar:
Domainmodel:
'dmodel' name=ID
"{"
('cmpTypes' '{' ctps+=CMPType ( "," ctps+=CMPType)* '}' )?
('set' '{'
(cmps+=CMP ("," cmps+=CMP)*)?
(prt=[PRT | QualifiedName])?
'}'
)?
'}'
;
CMPType:
'type' name=ID '{' ('prts' '(' prts+=PRT ( "," prts+=PRT)* ')' )? '}'
;
CMP:
'cmp' name=QualifiedName 'as' cmpType=[CMPType|QualifiedName]
;
PRT:
name=ID
;
QualifiedName:
ID ('.' ID)*
;
and here is how the DSL should look like:
dmodel D1 {
cmpTypes {
type C1 {
prts (P1, P2)
},
type C2 {
prts (P3, P4)
}
}
set {
cmp x as C1,
cmp y as C1,
cmp z as C2
//access items in 'prts' (P1, P2, ...) by cmp IDs (x, y, z)
x.P1 // rather than C1.P1 which works
y.P3
}
}
I want to associate cmp IDs (x, y, z) with items in cmpTypes (C1, C2 ...) and then access contained items in 'prts' (P1, P2, ...) by cmp IDs (x, y, z).
Any suggestions or examples how I could realize this?
|
|
|
Re: Association and cross-referencing [message #1781526 is a reply to message #1781463] |
Thu, 08 February 2018 08:42 |
|
Actually you want to refer to a CMP ('x') first and from there to a PRT. If I understand this correct 'x.P1' is a name which is in its first part a cross reference to CMP, followed by a reference to a PRT. So you'll need a rule like 'PRTRef':
PRTRef: cmp=[CMP|ID] '.' prt=[PRT|ID];
I used ID here instead of QualifiedName since the '.' would become ambiguous.
Then you'll have to implement scoping for reference PRTRef_prt in the IScopeProvider.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03576 seconds