Dealing with cross-reference instances [message #1806739] |
Tue, 14 May 2019 10:15  |
Eclipse User |
|
|
|
Hi,
I'm working on a GUI language, and find myself a little stuck when implementing a templating system for it. What I want to achieve is to define a custom/composite type of entity (template) and then instantiating this entity and assigning each instance different values. I've created a simplified version of my xtext file, but I believe it still captures the issue well. The two methods of overwriting the title value should ideally be interchangeable, and I can (with a lot of messing about) currently get the nested example (instanceOne) to work as described.
I've made the scoping work for the most part by adding local qualified names, but when I attempt to reference instanceTwo.title, all I get is effectively B.title, and no apparent way to distinguish between which instance it is (instanceOne.title === instanceTwo.title).
I suspect part of the problem originates from the fact that the properties are not owned by the entity, but that is a design constraint.
Now, is it possible to "instantiate" a type from a cross-reference, or perhaps something similar?
I greatly appreciate any thoughts on how to approach this problem!
Xtext file:
Model:
main=Main?
templates+=Template*
;
Main returns Unit:
{Main} 'main' name=ID '{'
'entities' '{' entities+=Entity* '}'
('specifications' '{' specifications+=Specification* '}')?
'}'
;
Template returns Unit:
{Template} 'template' name=ID '{'
'entities' '{' entities+=Entity* '}'
('specifications' '{' specifications+=Specification* '}')?
'}'
;
Entity:
(
{Label} 'label' |
{Instance} 'new' ref=[Unit | ID]
) name=ID
;
Specification:
entity=[Entity | FQN] '{' options+=Option* '}'
;
Option:
{Text} 'text' '=' value=STRING |
{InstanceOption} specification=Specification
;
FQN:
ID ('.' ID)*
;
.mydsl example
main A {
entities {
label header
B instanceOne
B instanceTwo
}
specifications {
header {
text = "hello world"
}
instanceOne {
title {
text = "This is instance one"
}
}
instanceTwo.title {
text = "This is instance two"
}
}
}
}
template B {
entities {
label title
label subtitle
}
}
Cheers,
Markus
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05438 seconds