Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Splitting grammar in multiple files, not projects(How to split a grammar into multiple files)
Splitting grammar in multiple files, not projects [message #1870947] Wed, 11 September 2024 19:01 Go to next message
Ralph Hummeling is currently offline Ralph HummelingFriend
Messages: 7
Registered: July 2024
Junior Member
Say we have a rather large grammar and we'd like to split it up in multiple files, as is common to software developers. How would we go about that without creating multiple projects?
Re: Splitting grammar in multiple files, not projects [message #1870950 is a reply to message #1870947] Wed, 11 September 2024 19:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
Hi you can simply have multiple language sections in the workflow

https://github.com/cdietrich/xtext-multi-dsl/blob/133bad08f7a5da0e8ba2bdbc06e425aeb58809f6/org.xtext.example.mydsl/src/org/xtext/example/mydsl/GenerateMyDsl.mwe2#L42


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Splitting grammar in multiple files, not projects [message #1870953 is a reply to message #1870950] Wed, 11 September 2024 19:22 Go to previous messageGo to next message
Ralph Hummeling is currently offline Ralph HummelingFriend
Messages: 7
Registered: July 2024
Junior Member
Alright, so in essence we define grammar B to extend grammar A and then import grammar A
grammar B with A
import A as a

Furthermore, in the workflow we define all the grammars and references per grammar:
referencedResource="platform:/resource/<...>/A.xtext"

Are there any limitations to this setup? I believe I've encountered a 'Sealed' exception when trying to extend a production rule.

[Updated on: Wed, 11 September 2024 19:23]

Report message to a moderator

Re: Splitting grammar in multiple files, not projects [message #1870959 is a reply to message #1870953] Wed, 11 September 2024 20:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
Depends on what you exactly do. You cannot introduce new eattributes or ereferences without creating a new subeclass which seems to be your problem

What are you exactly doing


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Wed, 11 September 2024 20:35]

Report message to a moderator

Re: Splitting grammar in multiple files, not projects [message #1870968 is a reply to message #1870959] Thu, 12 September 2024 08:15 Go to previous messageGo to next message
Ralph Hummeling is currently offline Ralph HummelingFriend
Messages: 7
Registered: July 2024
Junior Member
Say in grammar A we have a production rule:
RuleX: 'Hello' name=ID '!';

In grammar B we have a rule which refers this rule:
grammar B with A
import A
RuleY: RuleX | 'Goodbye';

This gives the error: "Cannot add supertype 'RuleY' to sealed type 'RuleX', but can be resolved by assigning RuleX to a feature:
grammar B with A
import A
RuleY: x=RuleX | y='Goodbye';

However, I'd prefer to extend RuleX instead of encapsulating it in a feature.
I made this construct with actions to resolve:
RuleY: {RuleX} f=RuleX | {RuleZ} f='Goodbye';

but perhaps there are better ways...

[Updated on: Thu, 12 September 2024 10:16]

Report message to a moderator

Re: Splitting grammar in multiple files, not projects [message #1871007 is a reply to message #1870968] Thu, 12 September 2024 17:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
You can do a

RuleY returns RuleX: RuleX | {RuleY}'Goodbye';

Or you need to introduce Ruley as supertype for x
Already in base.
Eg by uncallled rule

Ruley: rulex


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Splitting grammar in multiple files, not projects [message #1871010 is a reply to message #1871007] Thu, 12 September 2024 17:19 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
(Depends on which hierarchy you want to achieve

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:Lua xText Grammar: Distinguish between variable reference and declaration
Next Topic:Error "Failed to create injector"
Goto Forum:
  


Current Time: Fri Oct 11 08:54:54 GMT 2024

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

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

Back to the top