Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » grammar modularization within one project(How to modularize an xtext grammar definition into more files within one project)
grammar modularization within one project [message #1768440] Tue, 18 July 2017 18:17 Go to next message
Robert Klinger is currently offline Robert KlingerFriend
Messages: 10
Registered: July 2017
Junior Member
Greetings,

is there a recommended way to modularize the grammar definition?

I found the possibilities to seperate the grammar definition with import mechanism or with grammar mixin. Grammar mixin only allows to use one other grammar and imports seem only to work for Cross-Referencing.
Transitive grammar mixin does not seem to be a good solution if I want to keep the project open for extension.

Example:
Example: Feature1 | Feature2 | Feature3;
Feature1: ...;
Feature2: ...;
Feature3: ...;

Now I want to seperate this enormous grammar definition into three files and want to have something like:

BaseDsl.xtext:
Example: Feature1 | Feature2Dsl:Feature2 | Feature3Dsl:Feature3;
Feature1: ...;
Feature2Dsl.xtext
Feature2: ...;
Feature3Dsl.xtext
Feature3: ...;


____________
Note: I am new to xtext
Re: grammar modularization within one project [message #1768457 is a reply to message #1768440] Wed, 19 July 2017 02:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi this is not possible
There is only one hierarchy
And you can inherit only not aggregate


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar modularization within one project [message #1768531 is a reply to message #1768457] Wed, 19 July 2017 17:55 Go to previous messageGo to next message
Robert Klinger is currently offline Robert KlingerFriend
Messages: 10
Registered: July 2017
Junior Member
Oh, okay, thank you.

Does someone know the reason this is not possible?
What should I do If I want to modularize my grammar? :O
Re: grammar modularization within one project [message #1768536 is a reply to message #1768531] Wed, 19 July 2017 18:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
You can split up the grammar along one hierarchy

Grandparent parent child grandchild ....

The main problem is that there is no easy logic to merge multiple grammars
Nor an easy composition cause how parsers work

Thus it was never a usecase to implement this
https://bugs.eclipse.org/bugs/show_bug.cgi?id=445764
Is open for 3 years now

Can you give some hints what you want to achieve with the splitting


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar modularization within one project [message #1769277 is a reply to message #1768536] Fri, 28 July 2017 13:50 Go to previous messageGo to next message
Robert Klinger is currently offline Robert KlingerFriend
Messages: 10
Registered: July 2017
Junior Member
I want to merge different language parts, because they do not exist yet.
I want to have a base DSL and other providers should be able to provide parts to the target language.

______________________________

Example:
Total target grammar, Feature3 might not be existent yet, so there would not be a "| Feature3" and no rule for Feature3.
Grammar:
Model: Feature1 | Feature2 | Feature3;
Feature1: ...;
Feature2: ...;
Feature3: ...;

What I want to achieve is a BaseDsl in which I only need to add the "|Feature3" or something like "|Feature3Dsl:Feature3" and to add another file with the implementation of the grammar for Feature3.

BaseDsl.xtext:
Example: Feature1 | Feature2Dsl:Feature2 | Feature3Dsl:Feature3;
Feature1: ...;
Feature2Dsl.xtext
Feature2: ...;
Feature3Dsl.xtext
Feature3: ...;

______________________________

Besides that the generator needs to be extended at the right point.
The text "feature1 feature2 feature3" should then be translated into something like "feature1Translation feature2Translation feature3Translation". Especially the order should be the same.
I think this should be rather easy as soon as the grammar is merged the right way.
Grammar mixin therefore is a bad solution as I would need to make changes in different files for each added grammar part <-> Open-Closed-Principle.
Re: grammar modularization within one project [message #1769278 is a reply to message #1769277] Fri, 28 July 2017 13:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
If it were easy it would be implemented

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar modularization within one project [message #1771989 is a reply to message #1769278] Sat, 02 September 2017 17:20 Go to previous messageGo to next message
Robert Klinger is currently offline Robert KlingerFriend
Messages: 10
Registered: July 2017
Junior Member
Is it possible to use transitive grammar mixin like this:
A with B with C with A?

And thanks alot for your help so far :)
Re: grammar modularization within one project [message #1771996 is a reply to message #1771989] Sun, 03 September 2017 06:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
No. One grammar can have only one (direct) supergrammar

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 03 September 2017 07:36]

Report message to a moderator

Re: grammar modularization within one project [message #1772035 is a reply to message #1771996] Mon, 04 September 2017 12:01 Go to previous messageGo to next message
Robert Klinger is currently offline Robert KlingerFriend
Messages: 10
Registered: July 2017
Junior Member
oh sorry, I meant that: A with B
and the grammar B is mixed with C
then the grammar C is mixed with A again
basically every grammar is mixed with one direct other grammar but because grammar mixin is transitive C would be mixed with all rules of A and B

Re: grammar modularization within one project [message #1772045 is a reply to message #1772035] Mon, 04 September 2017 14:58 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
no cyclic mixins

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtend template using a Metamodel (ecore)
Next Topic:Xtext standalone generator output configuration
Goto Forum:
  


Current Time: Tue Apr 16 05:17:49 GMT 2024

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

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

Back to the top