Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 11:39 Go to next message
Robert Bill is currently offline Robert BillFriend
Messages: 4
Registered: March 2016
Junior Member
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 14:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText grammar for .xtext files [message #1726940 is a reply to message #1726934] Thu, 17 March 2016 15:31 Go to previous messageGo to next message
Robert Bill is currently offline Robert BillFriend
Messages: 4
Registered: March 2016
Junior Member
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 15:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
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);
	}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText grammar for .xtext files [message #1726947 is a reply to message #1726945] Thu, 17 March 2016 16:02 Go to previous messageGo to next message
Robert Bill is currently offline Robert BillFriend
Messages: 4
Registered: March 2016
Junior Member
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 16:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
Depending on your use case you might need other stuff as well.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText grammar for .xtext files [message #1726952 is a reply to message #1726951] Thu, 17 March 2016 16:29 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic: XMI file error.
Next Topic:How to change a resource
Goto Forum:
  


Current Time: Sun Oct 17 01:33:57 GMT 2021

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

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

Back to the top