Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Serialize selected DSL model objects dynamically
Serialize selected DSL model objects dynamically [message #1750640] Fri, 23 December 2016 10:17 Go to next message
Eclipse UserFriend
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 14:52 Go to previous message
Eclipse UserFriend
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());
	}

}
Previous Topic:Creating update site for my xText DSL
Next Topic:Build fails at p2.director
Goto Forum:
  


Current Time: Fri May 16 11:46:12 EDT 2025

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

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

Back to the top