Skip to main content



      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 15:01 Go to next message
Eclipse UserFriend
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 15:08 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Splitting grammar in multiple files, not projects [message #1870953 is a reply to message #1870950] Wed, 11 September 2024 15:22 Go to previous messageGo to next message
Eclipse UserFriend
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 15:23] by Moderator

Re: Splitting grammar in multiple files, not projects [message #1870959 is a reply to message #1870953] Wed, 11 September 2024 16:35 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Wed, 11 September 2024 16:35] by Moderator

Re: Splitting grammar in multiple files, not projects [message #1870968 is a reply to message #1870959] Thu, 12 September 2024 04:15 Go to previous messageGo to next message
Eclipse UserFriend
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 06:16] by Moderator

Re: Splitting grammar in multiple files, not projects [message #1871007 is a reply to message #1870968] Thu, 12 September 2024 13:18 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Splitting grammar in multiple files, not projects [message #1871010 is a reply to message #1871007] Thu, 12 September 2024 13:19 Go to previous message
Eclipse UserFriend
(Depends on which hierarchy you want to achieve
Previous Topic:Lua xText Grammar: Distinguish between variable reference and declaration
Next Topic:Error "Failed to create injector"
Goto Forum:
  


Current Time: Tue Apr 29 18:24:39 EDT 2025

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

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

Back to the top