Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-references in a parser used in a standalone application
Cross-references in a parser used in a standalone application [message #1690701] Mon, 30 March 2015 16:49 Go to next message
koz01 Mising name is currently offline koz01 Mising nameFriend
Messages: 1
Registered: March 2015
Junior Member
Hello,
I have defined a grammar

grammar a.Dsl with org.eclipse.xtext.common.Terminals
...
Model:
	greetings+=Greeting*;
	
Greeting:
	Definition|Application;
	
Definition:
	'Def' name=ID '.';
Application:
	'App' def = [Definition] '.';

and I try to parse in a standalone application:
	
public static void main(String[] args) {
  String str =  "Def var."//
                    + "App var.";
  Injector injector =
  new DslStandaloneSetup().createInjectorAndDoEMFRegistration();
  XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
  resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
  DslParser tp = injector.getInstance(DslParser.class);
  Reader r = new StringReader(str);
  IParseResult pr = tp.doParse(r);
  Model m = (Model) pr.getRootASTElement();
  Application a = (Application) m.getGreetings().get(1);
  Definition def = a.getDef();
  //def is null
  System.out.println(def);
}

Why a value of the attribute ´def´ is not set in the selected node of the AST (Definition)? I guess that it is required to run linking but I don´t know how. Is there anybody how could help me.
Thank you
Jan
Re: Cross-references in a parser used in a standalone application [message #1690715 is a reply to message #1690701] Mon, 30 March 2015 18:37 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am not sure what you do in your code. you usually do the reading as follows

String modelString = "Hello Xtext! Hello World from Xtext!";
		Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = injector.getInstance(ResourceSet.class);
		Resource r = rs.createResource(URI.createURI("dummy.mydsl"));
		r.load(new StringInputStream(modelString), null);
		Model m = (Model) r.getContents().get(0);


have a look at https://wiki.eclipse.org/Xtext/FAQ as well


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XtextCON - Final Program Online
Next Topic:Future versions backward compatibility
Goto Forum:
  


Current Time: Thu Apr 18 09:45:12 GMT 2024

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

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

Back to the top