|Re: get a model from a grammar expression [message #1745137 is a reply to message #1745072]
||Wed, 05 October 2016 15:06
| Aran A
Registered: January 2011
I'm not developing a big project, but trying to learn which things I can do with dsls, metamodels, and so on. So, in this moment I'm just playing with Eclipse.
I've been trying and at the end, the hint has been the '.xmi' extension for the model file (I wanted another extension, because when I create the metamodels in EMF (without grammars and XText) I'm used to define my own extension for the model files, but anyway, for this example I don't mind to use xmi).
So, the working code to get the model file is as following:
// Initialization for the grammar expression
Injector injector = new CusEvDslStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet rs = injector.getInstance(ResourceSet.class);
// Load the grammar expression
// mydsl is the extension defined for the grammar expressions
// It is defined in the GenerateWTDsl.mwe2 file
Resource r1 = rs.getResource(URI.createURI("example/pro1.mydsl"), true);
System.out.println("Grammar expression loaded...");
// Model is the name of the grammar root
Model m= (Model) r1.getContents().get(0);
// Save the model in a *.xmi file
Resource r2 = rs.createResource(URI.createURI("example/res1.xmi"));
By the way, to get it I've had to simplify my grammar. The original one has some problems, and when I try to save the file (r2.save(null)) I get this error (Error: java.lang.RuntimeException: Could not serialize EObject via backtracking. ...). Now I'll have to investigate that....
Thanks a lot,
Powered by FUDForum
. Page generated in 0.02538 seconds