Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Setting a fixed keyword to start a DSL file (How to set a fixed keyword that would start a DSL file created using Xtext)
Setting a fixed keyword to start a DSL file [message #1799609] Tue, 11 December 2018 06:19 Go to next message
P J is currently offline P JFriend
Messages: 64
Registered: October 2018
Member
Hi,

I am developing a DSL using Xtext as an Eclipse plugin. I need my language to start with a specific fixed expression, e.g: projection FileName ;, where 'projection' is the keyword and 'FileName' is a custom name. Is it possible to do so? I have attached my grammar below. Can anyone kindly tell me how I should change it to achieve my target?

Domainmodel:
	(elements+=MainElement)
;

MainElement:
	ProjectionName | ProjectionComponent | LayerSpecification |
	Description | Capability | Category | ServiceGroup |
	IncludeFragment | {MainElement} Override | {MainElement} Overtake
;

ProjectionName:
	'projection' modelName=ID ';'
;

ProjectionComponent:
	'component' componentName=ID ';'
;

LayerSpecification:
	'layer' layerName=ID ';'
;

Description:
	'description' string=STRING ';'
;

Capability:
	'capability' type=('Online' | 'Offline') ';'
;

Category:
	'category' type=('Integration' | 'ExternalB2B' | 'Users') ';'
;

ServiceGroup:
	'servicegroup' type=('Mobility' | 'Reporting') ';'
;

IncludeFragment:
	('@Dynamic_Component_Dependency' componentName=ID) 'include' 'fragment' fragmentToIncludeName=ID ';'
;

Override:
	'@Override'
;

Overtake:
	'@Overtake'
;

[Updated on: Tue, 11 December 2018 06:20]

Report message to a moderator

Re: Setting a fixed keyword to start a DSL file [message #1799610 is a reply to message #1799609] Tue, 11 December 2018 06:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Can you please explain what is not working for you with your grammar

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Setting a fixed keyword to start a DSL file [message #1799612 is a reply to message #1799610] Tue, 11 December 2018 06:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you need ProjectName first, try putting it first.

Domainmodel:
	elements+=ProjectionName (elements+=MainElement)
;

MainElement:
	ProjectionComponent | LayerSpecification |
	Description | Capability | Category | ServiceGroup |
	IncludeFragment | {MainElement} Override | {MainElement} Overtake
;


Regards

Ed Willink
Re: Setting a fixed keyword to start a DSL file [message #1799614 is a reply to message #1799612] Tue, 11 December 2018 08:15 Go to previous messageGo to next message
P J is currently offline P JFriend
Messages: 64
Registered: October 2018
Member
Hi Ed,

Thank you so much for the reply. :) It worked just as you said. In the meanwhile, I too found a bit more complex method which I have mentioned below (The difference between your code and mine is, mine has all compulsory keywords in an order, while yours gives 'projection' keyword first and allows to select any keyword next) : -

Domainmodel:
	(elements+=MainElement)
;

MainElement:
	(ProjectionName rule=ProjectionComponent) rule=LayerSpecification
	(rule=Description) (rule=Capability)? (rule=Category)? (rule=ServiceGroup)?
	(rule=IncludeFragment)* ( Override | Overtake )*
;


However, mine gives both 'layer' and 'projection' keywords at the beginning, which I guess should be corrected using *, ? symbols. So I guess your answer is a better choice.

[Updated on: Tue, 11 December 2018 08:18]

Report message to a moderator

Re: Setting a fixed keyword to start a DSL file [message #1799617 is a reply to message #1799614] Tue, 11 December 2018 08:53 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The 'better choice' is that one that does what you need flexibly and without errors. You seem to offer a variety of alternatives that don't do what you want and certainly have errors such as multiple assignment to rule. I suggest you revisit some tutorials so that you understand the capabilities that Xtext offers you.

Regards

Ed Willink

Previous Topic:Xtext DSL plugin only provides keyword suggestions for the first line of the file
Next Topic:Xtext content description identification
Goto Forum:
  


Current Time: Fri Apr 26 12:26:06 GMT 2024

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

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

Back to the top