Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem parsing xtext from variable: references missing
Problem parsing xtext from variable: references missing [message #1068164] Fri, 12 July 2013 13:35 Go to next message
Dennis Stampfer is currently offline Dennis StampferFriend
Messages: 23
Registered: April 2013
Junior Member
Hi,

this post is kind of a follow up / progress after http://www.eclipse.org/forums/index.php/t/490211/.

I run a mwe2 workflow file with a custom generator to generate code from an xtext DSL which is stored in a variable:

xtend2:
«var str = "...." as String»
«FOR p : ParseXtext::parse(str).eAllContents.toIterable»
	«p»
«ENDFOR»



The DSL stored in variable str for example contains:
ComponentParams {
	ParamSetInstance Simple2.SimpleParam {
	}
}


... where Simple2.SimpleParam references to a file contained in the project classpath.


the workflow part looks as follows:
    component = org.eclipse.xtext.generator.GeneratorComponent {
        register = org.xtend.mygen.GeneratorSetup {}
        slot = 'model'
        outlet = {
        	path = "src-gen"
        }
    }



When running the generator (.mwe2->run as->..):
java.lang.Exception: Xtext parsing error in parameter definition:
[XtextLinkingDiagnostic: null:16 Couldn't resolve reference to ParamSet 'Simple2.SimpleParam'.]



My editor resolves the references, but the generator does not. The function to parse the xtext dsl looks as follows:

public class ParseXtext {
	public static EObject parse(String xtext, ResourceSet rs) {
		try {
			// see http://wiki.eclipse.org/Xtext/FAQ
			new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("..");
			Injector injector = new ParameterStandaloneSetup().createInjectorAndDoEMFRegistration();
			XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
			resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
			
//			Resource resource2 = resourceSet.createResource(URI.createURI("platform:/resource/SimpleRepository/model/parameter/simple.param"));
//			resource2.load(null);
//			resourceSet.getResources().add(resource2);
			
			Resource resource = resourceSet.createResource(URI.createURI("platform:/resource/xxxx/DUMMY.param"));
			InputStream in = new ByteArrayInputStream(xtext.getBytes());
			resource.load(in, resourceSet.getLoadOptions());
			
			if(resource.getErrors().size() > 0) {
				throw new Exception("Xtext parsing error in parameter definition:\n"+resource.getErrors());
			}
			return resource.getContents().get(0);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;


Uncommenting the three lines in ParseXtext::parse(), the the generator does not complain and everything works. platform:/resource/SimpleRepository/model/parameter/simple.param is the file where Simple2.SimpleParam is defined.

My question: how can I obtain a resource set in the standalone workflow that includes all files from the project classpath? I think I cannot get a handle on the project as I am outside of eclipse (standalone).

I thought going into in the direction of XtextResourceSetProvider.get(projectHandle) but in the context of ParseXtext::parse() in the generator / standalone I don't have a handle on the project.

I think it can't be too much that is missing. I appreciate any hint for what direction to look into.

Thanks,
dennis
Re: Problem parsing xtext from variable: references missing [message #1068166 is a reply to message #1068164] Fri, 12 July 2013 13:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

I am not quite sure what you are doing.

you usually use the Reader component to read models . this reader
component allows you to register multiple standalonesetups. All model
files belonging to these setups will be read.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem parsing xtext from variable: references missing [message #1068167 is a reply to message #1068166] Fri, 12 July 2013 13:53 Go to previous messageGo to next message
Dennis Stampfer is currently offline Dennis StampferFriend
Messages: 23
Registered: April 2013
Junior Member
Hi,

my usecase is:

I have a uml model with stereotypes and tagged values. The uml model is read by the Reader. Some uml elements contain xtext dsl stuff in their tagged values. Of course, these values or any references contained in tagged values are not read or resolved by the Reader, as the reader does not look into the tagged values.

In the generator above, these tagged values are stored in variable str and parseXtext::parse(str) is called to parse and generate from that xtext model.

thanks,
dennis
Re: Problem parsing xtext from variable: references missing [message #1068171 is a reply to message #1068167] Fri, 12 July 2013 14:06 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi so you could load to referenced DSL files to the same resource set
as the uml files

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XAnnotations in 2.4
Next Topic:Is there a headless feature fur running MWE2 workflows?
Goto Forum:
  


Current Time: Fri Apr 19 00:43:41 GMT 2024

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

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

Back to the top