Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Modularisation of a big grammar
Modularisation of a big grammar [message #682054] Fri, 10 June 2011 10:01 Go to next message
Daniel Trierweiler is currently offline Daniel TrierweilerFriend
Messages: 67
Registered: June 2011
Member
Hey Guys,

first of all, I'm realtivly new to Xtext but got already used to the key mechanics and basic concepts.
Currently I am working on a quite big base grammar with a "easy to modularize" structure like:

Config:
	(subconfig1 = Subconfig1)?
	(subconfig2 = Subconfig2)?
	(subconfig3 = Subconfig3)?


Each subconfig consists of at least 200 lines of rules, which makes the base grammar file very confusing. I would love to split this xtext file into one xtext file for each subconfig.
I tried to figure it out via the Xtext User Guide, but without success.
So my actual questions:

1) Would it be possible to split the base file? Should I create multiple subconfig*.xtext files in the main directory (project) of the base grammar, or create a project for each subconfig*.xtext?

2) How can I generate the genmodel and ecore model from those xtext files, if I put them in one project? Is this even possible?

3) And how do I import those grammars? Via the generated ecore model? Or is there an easier way to achieve this? I thought about something like this:
import "platform:/resource/org.test.xtext/src-gen/org/test/xtext/subconfig1.ecore" as subconfig1
import "platform:/resource/org.test.xtext/src-gen/org/test/xtext/subconfig2.ecore" as subconfig2

And then adressing the EObjects via [subconfig1::*]

I hope I made it clear what I am intending to do Smile
Thanks a lot for your advice/input/help!

Daniel
Re: Modularisation of a big grammar [message #682066 is a reply to message #682054] Fri, 10 June 2011 10:29 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

Xtext does not have an include mechanism in the sense that you include a bunch of Xtext-grammars. It allows only single grammar inheritance (first line grammar ... with superGrammar). However superGrammar is not only the xtext file but the entire language infrastructure. This is why it is not merely a splitting up of the grammar file (and I wouldn't do it if I was not really forced to; note also that you don't really want the complete infrastructure - e.g. Editor - for the SubConfigs).

The basic layout would be SC1-Grammar extends Default-Terminals, SC2 extends SC1, SC3 extends SC2 and Config extends SC3, so if there are "cyclic dependencies" among the configs, splitting them up might not even be possible (not sure).


as to 1) Basically it is possible. You can create separate projects (relatively simple) or have them in the same project (bit more complicated, as you have get the workflow right, haveing more than one language definition in the generator component).

as to 2) Look at the generator fragments in the workflow, there is one responsible for meta model generation.

as to 3) The grammar rules are made accessible via the "with" in the grammar header, if you reference Types, you have to import the metamodel via import (and configure the generator fragment, such that the types are not generated again)

Summary: don't do it, you will spend days until you will have the generator-Infrastructure working.

Alex

P.S.: I've never looked into the possibility, but it might be a cleaner solution to have different xtext-grammars and have a (custom-self-implemented) preprocessing step that copies the rules into a combined grammar and uses that one. This is not without problems, e.g. if you have cross references to types that are not defined in the current file.


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
Re: Modularisation of a big grammar [message #682073 is a reply to message #682066] Fri, 10 June 2011 10:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7670
Registered: July 2009
Senior Member
Hi

I wouldn't be quite so negative.

Cyclic dependencies can be resolved by a dummy rule (analoguous to an
abstract function in Java). This highlights that you don't get true
modularity. All rules names are in the one namespace so an including
grammar overrides colliding names in the included grammar.

Perhaps you would be better to write smaller modular grammars and use a
simple script to strip preamble and stubs from each grammar module and
then concatenate the results following an appropriate overall preamble.

There is not much point in creating the fully tooled intermediates since
they just fill up disk space and the ANTLR Java files are BIG. For OCL I
use intermediates because OCL is re-used in different ways, but the
consequences on 'code' sizes are unpleasant.

Regards

Ed Willink

On 10/06/2011 11:29, Alexander Nittka wrote:
> Hi,
>
> Xtext does not have an include mechanism in the sense that you include
> a bunch of Xtext-grammars. It allows only single grammar inheritance
> (first line grammar ... with superGrammar). However superGrammar is
> not only the xtext file but the entire language infrastructure. This
> is why it is not merely a splitting up of the grammar file (and I
> wouldn't do it if I was not really forced to; note also that you don't
> really want the complete infrastructure - e.g. Editor - for the
> SubConfigs).
>
> The basic layout would be SC1-Grammar extends Default-Terminals, SC2
> extends SC1, SC3 extends SC2 and Config extends SC3, so if there are
> "cyclic dependencies" among the configs, splitting them up might not
> even be possible (not sure).
>
>
> as to 1) Basically it is possible. You can create separate projects
> (relatively simple) or have them in the same project (bit more
> complicated, as you have get the workflow right, haveing more than one
> language definition in the generator component).
>
> as to 2) Look at the generator fragments in the workflow, there is one
> responsible for meta model generation.
>
> as to 3) The grammar rules are made accessible via the "with" in the
> grammar header, if you reference Types, you have to import the
> metamodel via import (and configure the generator fragment, such that
> the types are not generated again)
>
> Summary: don't do it, you will spend days until you will have the
> generator-Infrastructure working.
>
> Alex
>
> P.S.: I've never looked into the possibility, but it might be a
> cleaner solution to have different xtext-grammars and have a
> (custom-self-implemented) preprocessing step that copies the rules
> into a combined grammar and uses that one. This is not without
> problems, e.g. if you have cross references to types that are not
> defined in the current file.
Re: Modularisation of a big grammar [message #682092 is a reply to message #682073] Fri, 10 June 2011 11:51 Go to previous message
Daniel Trierweiler is currently offline Daniel TrierweilerFriend
Messages: 67
Registered: June 2011
Member
Thanks a lot for the fast answers Smile

I thought about some dummy rules aswell, but I don't think that this would be a clean way to go. I read something about multiple inheritance in Sven's Blog, but I guess that it's just not possible...
I guess I will stick with the script based idea you both proposed as that should be the cleanest way Smile
Thanks a lot!
Previous Topic:Use imported objects in generator
Next Topic:[Xtend2] editor features
Goto Forum:
  


Current Time: Thu Sep 19 08:52:07 GMT 2024

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

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

Back to the top