Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serialize selected DSL model objects dynamically
Serialize selected DSL model objects dynamically [message #1750640] Fri, 23 December 2016 15:17 Go to next message
Nesredin Mahmud is currently offline Nesredin MahmudFriend
Messages: 7
Registered: July 2014
Junior Member
Hello,

I have a DSL for writing structured statements. My goal is to make string matches on the instances of "StructuredStatement" dynamically. I suppose i need to serialize the instances first into textual forms, and store them somewhere. But, I couldnt figure out the entry to this functionality in my xText DSL source code? I dont know much about xText Smile

Quote:

ReqSpecs:
elements += ReqSpec*
;

ReqSpec:
'Requirement' name=ID statement=StructuredStatement
;

StructuredStatement:
subject=ID predicate=Predicate
;

Predicate:
'is' object=ID'.'
;


Cheers,
Nas
Re: Serialize selected DSL model objects dynamically [message #1750650 is a reply to message #1750640] Fri, 23 December 2016 19:52 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11358
Registered: July 2009
Senior Member
can you please explain what you actually want to do?

what is input and what is the expected output?
if you simply want to serialize a model the following pseudo code should work.

public class Main {
	
	public static void main(String[] args) throws IOException {
		Injector i = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = i.getInstance(ResourceSet.class);
		Resource r = rs.createResource(URI.createURI("demo.mydsl"));
		
		ReqSpecs specs = MyDslFactory.eINSTANCE.createReqSpecs();
		ReqSpec spec1 = MyDslFactory.eINSTANCE.createReqSpec();
		spec1.setName("MySpec1");
		specs.getElements().add(spec1);
		
		StructuredStatement ss = MyDslFactory.eINSTANCE.createStructuredStatement();
		ss.setSubject("MySubj1");
		Predicate pred = MyDslFactory.eINSTANCE.createPredicate();
		pred.setObject("MyObject");
		ss.setPredicate(pred);
		spec1.setStatement(ss);
		// .....
		r.getContents().add(specs);
		r.save(SaveOptions.defaultOptions().toOptionsMap());
	}

}


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Previous Topic:Creating update site for my xText DSL
Next Topic:Build fails at p2.director
Goto Forum:
  


Current Time: Sun Nov 19 07:03:25 GMT 2017

Powered by FUDForum. Page generated in 0.02046 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software