Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 313076

Summary: [Xtext] Grammar formatting rules
Product: [Modeling] TMF Reporter: Sebastian Zarnekow <sebastian.zarnekow>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P3 CC: jan, moritz.eysholdt
Version: 1.0.0Flags: sebastian.zarnekow: helios+
Target Milestone: RC1   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Sebastian Zarnekow CLA 2010-05-17 03:18:32 EDT
The Xtext sample / wizard generated / from ecore generated grammars have been formatted manually thus I guess this is what is expected to be aesthetic. The Xtext formatter should meet this expectations. Futhermore there should not be any visible effect when a freshly generated grammar is formatted.
Comment 1 Moritz Eysholdt CLA 2010-05-17 03:53:14 EDT
So who needs to adopt? ;) The existing grammars or the formatter?

One question for the formatter that can be discussed is, whether semicolons should be at the end of the line (java-style) or on a single line (antlr-style). Yesterday I changed the formatter to antlr-style, since that is what we use in Xtext.xtext. But I don't have a strong opinion on this. 

I haven't found a way to introduce line breaks in a rule's body in a reasonable way, though. Except for autowrap after a certain length of the line is exceeded, of course.
Comment 2 Sebastian Zarnekow CLA 2010-05-17 04:02:08 EDT
- What I especially request is the grammar declaration to appear on one line if it does not exceed 120 chars:

grammar foo with bar hidden(zonk)

grammar long.foo with long.bar 
  hidden(zonk)

grammar very.long.foo
  with very.long.bar
  hidden(zonk)

- I like the semicolons in new lines.
- I guess line-breaks in rules cannot be implemented reasonable without information about the actual model so if it is possible to keep the line-breaks in the rules as is (if not > 120 chars), that would be helpful.

So the answer seems to be "both" :-)
Comment 3 Moritz Eysholdt CLA 2010-05-17 07:23:29 EDT
Fixed the formatter-side in HEAD.

(In reply to comment #2)
> - What I especially request is the grammar declaration to appear on one line if
> it does not exceed 120 chars.

This was intended to be a feature. But anyway, it's in one line now.

> - I like the semicolons in new lines.

I've changed that back to have the semicolons at the end of the lines. This way grammars consume less lines of code and thereby for example fit better on a demo screen/presentation slide.

> - I guess line-breaks in rules cannot be implemented reasonable without
> information about the actual model 

true, semantic formatting would be needed for this.

> so if it is possible to keep the line-breaks
> in the rules as is (if not > 120 chars), that would be helpful.

it is, linbreaks within the body of a rule are now kept by the formatter.
Comment 4 Moritz Eysholdt CLA 2010-05-17 09:24:29 EDT
The grammar that is created by the new-project-wizard and the grammars of Xtext's example projects are now formatted as the formatter would do it.

The ecore2xtext wizard will, however, still create grammars that diverge from the default formatting. Since an Xpand template creates the grammar in this case, the best solution would probably be to run the formatter after a grammar has been created. I'm not sure though whether that's worth the effort.
Comment 5 Jan Koehnlein CLA 2010-05-17 09:34:26 EDT
As far as the Ecore2XtextWizard is concerned, I'd prefer not to change the current formatting. It is currently based on semantics, e.g. matching bracket keywords, and kind of optimized in terms of readability.

As this was the last remaining issue, I am closing this bug as fixed.
Comment 6 Karsten Thoms CLA 2017-09-19 16:43:04 EDT
Closing bug which were set to RESOLVED before Eclipse Neon.0.