Reputation: 35
I have an own Xtext grammar definition:
grammar org.xtext.example.mydsl.MyOtherDsl with org.eclipse.xtext.common.Terminals
generate myOtherDsl "http://www.xtext.org/example/mydsl/MyOtherDsl"
OtherModel:
Foo | Bar;
Foo: 'foo' name=ID;
Bar: 'bar' name=ID;
Now, I want to use this grammar in the (standard example) Xtext grammar via an "import":
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import "http://www.xtext.org/example/mydsl/MyOtherDsl" as other
Model:
greetings+=Greeting*
foobars+=FooBar*;
Greeting: 'Hello' name=ID '!' foo=[other::Foo];
FooBar: other::Foo | other::Bar;
While Greeting: 'Hello' name=ID '!' foo=[other::Foo];
is working, FooBar: other::Foo | other::Bar;
throws an error: no viable alternative at input 'other'. In the Greeting
rule I use the reference for an attribute (foo
). In the FooBar
rule I just want to use it as a type. How can I do it?
Any help appreciated.
Thanks, Andreas
Upvotes: 2
Views: 1193
Reputation: 11868
Xtext only Supports a Single Inhertiance Hierarchy
grammar org.xtext.example.mydsl.MyDslBase with org.eclipse.xtext.common.Terminals
grammar org.xtext.example.mydsl.MyDslGrandParent with org.xtext.example.mydsl.MyDslBase
grammar org.xtext.example.mydsl.MyDslParent with org.xtext.example.mydsl.MyDslGrandParent
grammar org.xtext.example.mydsl.MyDslChild with org.xtext.example.mydsl.MyDslParent
so it is not possible to spilt them up into several and group them togther in one dsl
Upvotes: 2