Skip to main content



      Home
Home » Modeling » TMF (Xtext) » XText grammar for .xtext files(Whether it is possible to programmatically read in .xtext files)
XText grammar for .xtext files [message #1726906] Thu, 17 March 2016 07:39 Go to next message
Eclipse UserFriend
Hello everyone, I would like to ask the following question:

Is it possible to read .xtext files in programmatically just like reading in files generated with .xtext grammar, i.e. is there a thing like "xtext.xtext" which allows you to generate a parser for the xtext language itself.
Re: XText grammar for .xtext files [message #1726934 is a reply to message #1726906] Thu, 17 March 2016 10:55 Go to previous messageGo to next message
Eclipse UserFriend
yes this is possible. can you be a bit more specific what you want to do?
e.g. if you want to hook into the xtext generator simply write a generatorfragment and add it to the workflow
Re: XText grammar for .xtext files [message #1726940 is a reply to message #1726934] Thu, 17 March 2016 11:31 Go to previous messageGo to next message
Eclipse UserFriend
Thank you for your quick anwer. In particular, I would like to modify .xtext files programatically, to e.g. change the syntax.
For example, I might want to add new rules, delete existing rules, add Terminals or Nonterminals to certain rules or delete them etc.

One specific use case would be to automatically "improve" the XText syntax generated from ecore models based on user-defined criteria.
Re: XText grammar for .xtext files [message #1726945 is a reply to message #1726940] Thu, 17 March 2016 11:55 Go to previous messageGo to next message
Eclipse UserFriend
sth. like this should work

	public static void main(String[] args) throws IOException {
		Injector i = new XtextStandaloneSetup().createInjectorAndDoEMFRegistration();
		XtextResourceSet resourceSet = i.getInstance(XtextResourceSet.class);
		Resource r = resourceSet.getResource(URI.createURI("src/org/xtext/example/mydsl2/MyDsl.xtext"), true);
		r.load(null);
		Grammar g = (Grammar) r.getContents().get(0);
		System.out.println(g);
	}
Re: XText grammar for .xtext files [message #1726947 is a reply to message #1726945] Thu, 17 March 2016 12:02 Go to previous messageGo to next message
Eclipse UserFriend
Thank you, that seems like exactly what I would like to have!

Also, it works like a charm (at least for what I have tried it yet).
Re: XText grammar for .xtext files [message #1726951 is a reply to message #1726947] Thu, 17 March 2016 12:28 Go to previous messageGo to next message
Eclipse UserFriend
Depending on your use case you might need other stuff as well.
Re: XText grammar for .xtext files [message #1726952 is a reply to message #1726951] Thu, 17 March 2016 12:29 Go to previous message
Eclipse UserFriend
Christian Dietrich <no_email@xxxxxxxxd> wrote:
> Depending on your use case you might need other stuff as well.
>
>

Thus writing a fragment would be easier since it does all the setup stuff
Previous Topic: XMI file error.
Next Topic:How to change a resource
Goto Forum:
  


Current Time: Mon Jul 07 11:39:26 EDT 2025

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

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

Back to the top