xtext - Including a grammar into another grammar -
i reuse grammar definitions.
i have grammar this:
person: 'contact' name=id '{' 'phone' phone=int '}' ;
i have grammar this:
include "uri/to/other/project/to/other/grammar/definitions" call: 'call' person=person ;
person
not known second grammar. xtext therefore able insert or include person
definition first grammar second grammar?
a further step generation of person
. know how accomplish too.
i found solution. can use keyword "with" used include terminals.
the necessary steps:
- create xtext project com.mydsl.a (a) , com.mydsl.b (b)
- write grammar a
- add dependency in meta-inf/manifest of b
- add a.ui dependency in meta-inf/manifest of b.ui
- add registration of a's genmodel in b's workflow that: in standalonesetup:
registergenmodelfile = "platform:/resource/a/src-gen/path/to/a.genmodel"
- change first line of b
grammar b a
- you can use eclasses of while writing grammar b
with
cannot used include more 1 grammar, terminal definitions must stated in a.
the generation executed in b's igenerator, can reuse generation of a's eclasses if extend a's generator.
this approach kind of inheritance, since proposal, validation, etc classes extended a's counterparts. didn't find out if multiple inheritance supported. can place comma after with a
doesn't work.
Comments
Post a Comment