Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Keep the Grammar structure same as before saving the file(Keep the Grammar structure same as before saving the file)
Keep the Grammar structure same as before saving the file [message #1806731] Tue, 14 May 2019 13:21 Go to next message
Nagashree KN is currently offline Nagashree KNFriend
Messages: 32
Registered: September 2018
Member
Hi,

I am facing problem in the Structure of the Grammar. on saving the xtext editor (runtime) , Grammar format is changing. it is displaying the grammar in 1 line. How i can retain the grammar structure same ,before and after saving the file.
My grammar is given below-

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/sirius/sample/basicfamily"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Family returns Family:
{Family}
'Family{'
name=EString
('members{' members+=Person ( "," members+=Person)* '}' )?
'}';

Person returns Person:
Man | Woman;

EString returns ecore::EString:
STRING | ID;

Man returns Man:
{Man}
'Man{'
name=EString
('children{' children+=[Person|EString] ( "," children+=
[Person|EString])* '}' )?
('parents{' parents+=[Person|EString] ( "," parents+=
[Person|EString])* '}' )?
'}';

Woman returns Woman:
{Woman}
'Woman{'
name=EString
('children{' children+=[Person|EString] ( "," children+=
[Person|EString])* '}' )?
('parents{' parents+=[Person|EString] ( "," parents+=
[Person|EString])* '}' )?
'}';
And i have attached some screenshots.

Please help i how to solve.
Re: Keep the Grammar structure same as before saving the file [message #1819672 is a reply to message #1806731] Tue, 21 January 2020 04:13 Go to previous messageGo to next message
Naveen R is currently offline Naveen RFriend
Messages: 7
Registered: May 2019
Junior Member
Hi,
From Xtext 2.8 extend the new formatter2 class org.eclipse.xtext.formatting2 .
Refer the blog - https://blogs.itemis.com/en/tabular-formatting-with-the-new-formatter-api

Before Xtext 2.8 extend the formatter class org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter
Refer - https://github.com/mn-mikke/Model-driven-Pretty-Printer-for-Xtext-Framework/wiki/Standard-Way-of-Code-Formatting-in-Xtext-Framework

Using the above classes the formatting of the DSL can be controlled.

Regards,
Naveen

[Updated on: Tue, 21 January 2020 04:16]

Report message to a moderator

Re: Keep the Grammar structure same as before saving the file [message #1821336 is a reply to message #1819672] Tue, 11 February 2020 04:49 Go to previous message
Nagashree KN is currently offline Nagashree KNFriend
Messages: 32
Registered: September 2018
Member
Thank you Naveen :)
Previous Topic:Changing Formatter2 Indentation Preferences from Tab to Spaces?
Next Topic:Project wizard: how to set the JRE System Library programmatically?
Goto Forum:
  


Current Time: Fri Apr 19 15:26:48 GMT 2024

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

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

Back to the top