Create and configure instances [message #1855312] |
Fri, 07 October 2022 11:18  |
Eclipse User |
|
|
|
Hi,
I am new in Xtext and the grammar syntax. Therefore, the question might be stupid, but I would like to express this use-case:
I would like to define an entity with features:
entity MyEntityDeclaration {
name : String
description : String
}
The Xtext grammer to define this is clear to me, it's part of the 15 minute tutorial on Xtext documentation site. The attached file contains the grammer of the entity declaration.
But now I would like to create an instance of this entity. Something like this:
new MyEntityDeclaration A {
name = "MyName"
description = "MyDescription"
}
new MyEntityDeclaration B {
name = "AnotherName"
description = "AnotherDescription"
}
How would I specify the grammar to achieve this?
Thanks for help.
|
|
|
Re: Create and configure instances [message #1855313 is a reply to message #1855312] |
Fri, 07 October 2022 12:19   |
Eclipse User |
|
|
|
am not sure if i get your point at all. i propose to do the tutorial.
Instance:
"new" type=[Entity] name=ID "{"
propertyInstances+=PropertyInstance*
"}";
PropertyInstance:
attr=[Attribute] "=" value=Literal // Expresssion, whatever you have;
+ implement scoping for PropertyInstance
[Updated on: Fri, 07 October 2022 12:46] by Moderator Report message to a moderator
|
|
|
Re: Create and configure instances [message #1855380 is a reply to message #1855313] |
Tue, 11 October 2022 14:35   |
Eclipse User |
|
|
|
Thank you for your help.
I tried to extend my grammar according to your proposal (see attached MyDsl.xtext). Unfortunately, I was not able to specify the scope for the FeatureInstance.
Therefore, I can specify something like this in my dsl file:
package my.sample {
datatype String
entity User {
firstName : String
lastName : String
}
entity Address {
street : String
country : String
phone : String
}
new User MyUser {
set User.firstName = "Ny first name"
set User.lastName = "Ny last name"
set Address.country = "this is the wrong feature scope..."
}
}
Can you please explaint how to implement the scoping for the PropertyInstance (in my file it's ther FeatureInstance)?
Thank you for your help.
Attachment: MyDsl.xtext
(Size: 1.07KB, Downloaded 83 times)
|
|
|
Re: Create and configure instances [message #1855403 is a reply to message #1855380] |
Wed, 12 October 2022 09:30  |
Eclipse User |
|
|
|
would expect
new User MyUser {
set firstName = "Ny first name"
set lastName = "Ny last name"
}
FeatureInstance: // remove the bad return
'set' type=[Feature] "=" value=Literal;
in grammar and a scope provider like (untessted)
public class MyDslScopeProvider extends AbstractMyDslScopeProvider {
@Override
public IScope getScope(EObject context, EReference reference) {
if (reference == MyDslPackage.Literals.FEATURE_INSTANCE__TYPE) {
Instance inst = null;
if (context instanceof Instance) {
inst = (Instance) context;
} else if (context instanceof FeatureInstance) {
inst = (Instance) context.eContainer();
}
if (inst != null) {
return Scopes.scopeFor(inst.getType().getFeatures());
} else {
return IScope.NULLSCOPE;
}
}
return super.getScope(context, reference);
}
}
is it intentional you have this wired syntax set User.xxxxx
then you sould have also two references there,
but the user would be redundant / implemented as in
https://dietrich-it.de/xtext/2013/05/18/xtext-and-dot/path-expressions/
[Updated on: Wed, 12 October 2022 09:33] by Moderator Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03698 seconds