Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Split XText Grammar into multiple files
icon5.gif  Split XText Grammar into multiple files [message #898778] Fri, 27 July 2012 14:14 Go to next message
Gregoire de Hemptinne is currently offline Gregoire de HemptinneFriend
Messages: 3
Registered: January 2012
Junior Member
Hi All,

I created a grammar for Wazaabi (declarative UI framework) but the grammar file is very long and difficult to read. I would like to split the grammar into several files to make contribution easier.

I was not able to find any clear documentation or code sample to do that. Can someone help me?

I'm afraid I'll meet some problems since I have some abstract objects in my model. And if I split my grammar I will have to be able to reference to an abstract class defined in another grammar file.

Thank you in advance for your help Smile
Best regards
Re: Split XText Grammar into multiple files [message #898820 is a reply to message #898778] Fri, 27 July 2012 18:59 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

if its only to improve readablity and not about reusing a grammar for several languages (like the default Terminals or Xbase), don't do it. There are too many problems involved (at least think well on the cost/value balance).

Comment the grammar, structure it well (order of elements but also indentation etc for good readability), write a separate documentation for the main concepts and with entry points for working with it. Use the tooling (outline view, find references etc.)

There is no Xtext concept for: take these 5 files and act as if they were defined in a single grammar file. The rule of thumb is that each grammar comes with its own meta model and language infrastructure. Further a grammar can "extend" only one other grammar.

Alex


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

[Updated on: Fri, 27 July 2012 19:02]

Report message to a moderator

Re: Split XText Grammar into multiple files [message #899011 is a reply to message #898820] Mon, 30 July 2012 07:28 Go to previous messageGo to next message
frank fotso is currently offline frank fotsoFriend
Messages: 91
Registered: May 2012
Member
hi
this means that i can't extend a grammar in another grammar twice ?, so i want to create many different grammar with their own model and i want at the end to import all the grammar created in another one such that the one containing the imported can be consider as a big model.
i also want to know if every grammar created since they have their own model , if i make a change in some of them , should i change my grammar containing that imported file too?
thanks in advance
Re: Split XText Grammar into multiple files [message #899059 is a reply to message #899011] Mon, 30 July 2012 11:40 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-30-07 9:28, frank fotso wrote:
> hi this means that i can't extend a grammar in another grammar twice ?,
uh,
grammar A and B can both extend grammar X, and grammar P can extend A, T
extend B etc. What you can not do is have a grammar that extends more
than one other grammar.

> so i want to create many different grammar with their own model and i
> want at the end to import all the grammar created in another one such
> that the one containing the imported can be consider as a big model.
No, that will not work.
You can however separate the model from the grammar and do the reuse,
combination in the models, and then use these models in various grammars.

> i also want to know if every grammar created since they have their own
> model , if i make a change in some of them , should i change my grammar
> containing that imported file too?

When a grammar is changed, you need to regenerate all grammars that
makes use of it to make it take effect.

If you import models instead of generating them from the grammar, you do
not need to regenerate the grammar/parsers as long as the model changes
are compatible with what is being used by the already built grammar.

Does that help you?
Regards
- henrik
Re: Split XText Grammar into multiple files [message #899851 is a reply to message #899059] Thu, 02 August 2012 15:23 Go to previous messageGo to next message
Gregoire de Hemptinne is currently offline Gregoire de HemptinneFriend
Messages: 3
Registered: January 2012
Junior Member
@Alexander, thank you for your answer. This is just the information I needed. Indeed, this is not optimal to split my grammar into several files only for improve readability. So I will continue working with this big file.
Regards
- Gregoire

[Updated on: Thu, 02 August 2012 15:23]

Report message to a moderator

Re: Split XText Grammar into multiple files [message #1840017 is a reply to message #898820] Mon, 05 April 2021 04:16 Go to previous messageGo to next message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 125
Registered: July 2009
Location: New York City, NY
Senior Member
I'm struggling with the same problem, and was wondering if there have been any recent developments regarding this (the question was originally asked 9 years ago).
I have a large grammar that contains several recursive expression grammars that I'd like to move to their own files.
Re: Split XText Grammar into multiple files [message #1840019 is a reply to message #1840017] Mon, 05 April 2021 06:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

A couple of yearsago an internal breaking change was introduced whereby rule names were adjusted to include a qualifying prefix avoiding the collision anarchy that can come from multiple grammar files. An important step forwards but not obviously expanded to first class support.

It is however probably much easier now to write an Xtext preprocessor that merges multiple partial Xtext files into an overall monolith.

This is probably a sensible way to go since making Xtext bigger and bigger to cope with every new enthusiasm is unmanageable. Much easier to write an Xtext++2Xtext transformation to normalize all the added goodies into the capabilities of the existing unchanged tool.

Xtext has an Ecore model so writing an M2M is not that hard. The Xtext model is not very pretty so my org.eclipse.ocl.examples.xtext2lpg transformation comprises four passes using a cleaner XBNF (extended Backus Naur Format)

Xtext 2 XBNFwithcardinality rationalization in QVTo
XBNFwithcardinality 2 XBNF normalization in QVTo
XBNF 2 XBNF inlining in QVTo
XBNF 2 LPG in Xtend

You might try to transform multi-Xtext via XBNF to single-Xtext. Please report back.

Regards

Ed Willink
Re: Split XText Grammar into multiple files [message #1840271 is a reply to message #1840019] Sun, 11 April 2021 01:10 Go to previous message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 125
Registered: July 2009
Location: New York City, NY
Senior Member
Thanks for your suggestions, Ed. I'll give the pre-processor approach a try.

Regards,

Mirko
Previous Topic:Qualified Name according to the hierarchical level
Next Topic:SecurityException in Maven build
Goto Forum:
  


Current Time: Fri Mar 29 15:30:08 GMT 2024

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

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

Back to the top