Skip to main content



      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 14:17 Go to next message
Eclipse UserFriend
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] Tue, 18 July 2017 22:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi this is not possible
There is only one hierarchy
And you can inherit only not aggregate
Re: grammar modularization within one project [message #1768531 is a reply to message #1768457] Wed, 19 July 2017 13:55 Go to previous messageGo to next message
Eclipse UserFriend
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 14:35 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: grammar modularization within one project [message #1769277 is a reply to message #1768536] Fri, 28 July 2017 09:50 Go to previous messageGo to next message
Eclipse UserFriend
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 09:51 Go to previous messageGo to next message
Eclipse UserFriend
If it were easy it would be implemented
Re: grammar modularization within one project [message #1771989 is a reply to message #1769278] Sat, 02 September 2017 13:20 Go to previous messageGo to next message
Eclipse UserFriend
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 02:50 Go to previous messageGo to next message
Eclipse UserFriend
No. One grammar can have only one (direct) supergrammar

[Updated on: Sun, 03 September 2017 03:36] by Moderator

Re: grammar modularization within one project [message #1772035 is a reply to message #1771996] Mon, 04 September 2017 08:01 Go to previous messageGo to next message
Eclipse UserFriend
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 10:58 Go to previous message
Eclipse UserFriend
no cyclic mixins
Previous Topic:Xtend template using a Metamodel (ecore)
Next Topic:Xtext standalone generator output configuration
Goto Forum:
  


Current Time: Tue May 13 00:01:43 EDT 2025

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

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

Back to the top