Setting a fixed keyword to start a DSL file [message #1799609] |
Tue, 11 December 2018 06:19 |
P J 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 #1799614 is a reply to message #1799612] |
Tue, 11 December 2018 08:15 |
P J 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02948 seconds