Skip to main content



      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 01:19 Go to next message
Eclipse UserFriend
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 01:20] by Moderator

Re: Setting a fixed keyword to start a DSL file [message #1799610 is a reply to message #1799609] Tue, 11 December 2018 01:30 Go to previous messageGo to next message
Eclipse UserFriend
Can you please explain what is not working for you with your grammar
Re: Setting a fixed keyword to start a DSL file [message #1799612 is a reply to message #1799610] Tue, 11 December 2018 01:44 Go to previous messageGo to next message
Eclipse UserFriend
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 03:15 Go to previous messageGo to next message
Eclipse UserFriend
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 03:18] by Moderator

Re: Setting a fixed keyword to start a DSL file [message #1799617 is a reply to message #1799614] Tue, 11 December 2018 03:53 Go to previous message
Eclipse UserFriend
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: Tue Jun 24 10:19:34 EDT 2025

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

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

Back to the top