I have recently started working with XText. So far I have been able to define a simple grammar, complete the JvmModelInferrer and generate the corresponding java classes and .java files.
Is it possible to generate automatically the DSL file (taking into account its grammar) from a set of custom Java classes?
Let me provide a simple example.
I have the following grammar:
MODEL:
entities+=ENTITY*
;
ENTITY:
'entity' name=ValidID 'as'
(elements+=PROPERTY)*
'end'
;
PROPERTY:
(many?='many')? 'property' name=ID 'of' type=JvmTypeReference
;
If I have the following sample.myDsl
entity Book as
property title of String
property numPages of Integer
end
entity Author as
property name of String
property surname of String
end
I get the Book.java and the Author.java files. In my project I have a processor that analyzes java files and creates objects from them, so if I run the processor on the previous Book.java and Author.java I would get two instances of a custom Entity java type. Each Entity instance would have a set of Property instances. So, the Java model is very similar to the xtext grammar.
Is it possible to "feed" these two objects to XText, maybe define an Inferrer to specify the translations, and taking into account the same .xtext grammar file, generate automatically a .myDsl file?
with xtext it is ususally no problem to
if you use xbase and jvmmodelinferrrer building the ast might be a kind of pain if you reference from a model to a inferred jvm element or try to build xbase expressions as ast here is a simple complex example using the domainmodel example