Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Making it possible to write Xtext grammar in DSL
Making it possible to write Xtext grammar in DSL [message #1839432] Sun, 21 March 2021 11:05 Go to next message
M D is currently offline M DFriend
Messages: 33
Registered: January 2021
Member
I want to make it possible to write Xtext grammar in my DSL. Thus, I've found the Xtext metamodel grammar from here and pasted it in (deleted the Grammar rule, though): https://github.com/eclipse/xtext-core/blob/master/org.eclipse.xtext/src/org/eclipse/xtext/Xtext.xtext

I want to define new rules in my DSL, but also want to use existing terminal rules I've defined in my grammar, like STRING, so I don't have to recreate those terminal rules in my DSL.

I've tried changing:

TerminalRuleCall returns RuleCall:
rule=[AbstractRule|RuleID]
;

to something like:

TerminalRuleCall returns RuleCall:
AbstractRuleReference | PredefinedRule
;

AbstractRuleReference:
rule = [AbstractRule|RuleID]
;

PredefinedRule:
rule = PREDEFINED_TERMINALS
;

terminal PREDEFINED_TERMINALS:
'STRING' | 'INT'
;

This, however, gives me an error at "rule = PREDEFINED_TERMINALS" saying: "Cannot find comptaible type for the feature 'rule'.

Is is this the right approach, and why do I get this error?

Thanks.
Re: Making it possible to write Xtext grammar in DSL [message #1839445 is a reply to message #1839432] Sun, 21 March 2021 18:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Have you understood how "with org.eclipse.xtext.common.Terminals" in the standard examples enables the contents of Terminals.xtext to be re-used?

As with Terminal.xtext you can just use a few terminals, or as with EssentialOCL.xtext you can re-use a whole language.

Regards

Ed Willink
Re: Making it possible to write Xtext grammar in DSL [message #1839451 is a reply to message #1839445] Sun, 21 March 2021 22:41 Go to previous messageGo to next message
M D is currently offline M DFriend
Messages: 33
Registered: January 2021
Member
Don't know if I understand you correctly. Maybe I also haven't explained it properly.

My DSL is used to create the grammar for another DSL among other things. Thus, I want it to do stuff and also write new Xtext grammar in it. I know STRING and such is defined in org.eclipse.xtext.common.Terminals, but those applies to the grammar of my DSL and not my DSL itself. I want to able to write name = STRING in my DSL without having to define STRING in my DSL.
Re: Making it possible to write Xtext grammar in DSL [message #1839520 is a reply to message #1839451] Tue, 23 March 2021 08:46 Go to previous messageGo to next message
M D is currently offline M DFriend
Messages: 33
Registered: January 2021
Member
?
Re: Making it possible to write Xtext grammar in DSL [message #1839524 is a reply to message #1839520] Tue, 23 March 2021 11:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
If in the metamodel there's a cross reference so it has to be in your grammar

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Making it possible to write Xtext grammar in DSL [message #1839531 is a reply to message #1839524] Tue, 23 March 2021 12:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Rephrasing what you ask, it would appear that you are developing a new DSL that has many similarities to Xtext, so you have an Xtext ++ --.

In so far as what you are trying to do doesn't work for you, I suggest that you proceed in smaller and smaller steps until you identify the step where you have a misunderstanding.

First step: clone the Xtext grammar unchanged other than to rename to avoid conflicts with the original Xtext. Next steps; remove an Xtext facility you do not require./ add: add a new facility that you do.

Once you have a specific small change that fails to work and you cannot comprehend, you can post that change for comment by those that may be able to help.

Regards

Ed Willink
Re: Making it possible to write Xtext grammar in DSL [message #1839544 is a reply to message #1839524] Tue, 23 March 2021 15:33 Go to previous messageGo to next message
M D is currently offline M DFriend
Messages: 33
Registered: January 2021
Member
Christian Dietrich wrote on Tue, 23 March 2021 11:16
If in the metamodel there's a cross reference so it has to be in your grammar

That's why I change it from

TerminalRuleCall returns RuleCall:
rule=[AbstractRule|RuleID]
;

to:

TerminalRuleCall returns RuleCall:
AbstractRuleReference | PredefinedRule
;

So it can either be a cross-reference to a newly defined tule in my DSL or a predefined rule in my grammar, which is what I use the terminal rule PREDEFINED_TERMINALS to.

Ed Willink wrote on Tue, 23 March 2021 12:40
Hi

Rephrasing what you ask, it would appear that you are developing a new DSL that has many similarities to Xtext, so you have an Xtext ++ --.

In so far as what you are trying to do doesn't work for you, I suggest that you proceed in smaller and smaller steps until you identify the step where you have a misunderstanding.

First step: clone the Xtext grammar unchanged other than to rename to avoid conflicts with the original Xtext. Next steps; remove an Xtext facility you do not require./ add: add a new facility that you do.

Once you have a specific small change that fails to work and you cannot comprehend, you can post that change for comment by those that may be able to help.

Regards

Ed Willink

I've already cloned the grammar and made small changes. The small changes are the ones I wrote in the original post.
Re: Making it possible to write Xtext grammar in DSL [message #1839549 is a reply to message #1839544] Tue, 23 March 2021 17:15 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you presented your problem as a MyDSL.xtext rather than a snippet it would be much easier for others to help you.

Regards

Ed Willink
Previous Topic:Generated validator is .java, not .xtend
Next Topic:How to I get a handle on my language's Grammar/Grammar Access?
Goto Forum:
  


Current Time: Sat Apr 20 04:32:02 GMT 2024

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

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

Back to the top