Create and configure instances [message #1855312] |
Fri, 07 October 2022 07: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 #1855403 is a reply to message #1855380] |
Wed, 12 October 2022 05: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 05:33] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03824 seconds