| Summary: | [formatter/matcher] Unordered groups are not handled correctly | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Johan Wannheden <johan.wannheden> | ||||
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> | ||||
| Status: | CLOSED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | asheiduk, benjamin.schwertfeger, btickets, carl.wannheden, horst, moritz.eysholdt, philipp.salvisberg, sebastian.zarnekow, stephane, sven.efftinge | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Mac OS X - Carbon (unsup.) | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
Johan Wannheden
When changing c.setNoSpace().around(statementAccess.getRightParenthesisKeyword_2()); to c.setNoSpace().before(statementAccess.getRightParenthesisKeyword_2()); the formatter works as expected / intended. Created attachment 177200 [details]
Early Tests, Debug output
I started working on this, but the impact turns out to be to huge for SR1. The patch contains test cases which produce debug output that shows what went wrong.
I have the same problem with xtext 2.3.0. My grammar contains the unordered group
(
& ('pages' pages+=PageRef (',' pages+=PageRef)*)?
& ('preconditions' (preConditions+=Precondition)+)?
)
And the formatter contains
c.setIndentationIncrement().before(ga.getPreconditionRule());
c.setIndentationDecrement().after(ga.getPreconditionRule());
This formats correctly, if the model contains the keywords in order of the definitions in the (un)ordered group. If I change the order The formatting for the direct containing Modelelements seems to be ok, but the siblings are indented.
Additional observation:
I tried to create a simple sample, like the one above, and had to add the decrement after the rule which contains the unordered group. Additionally the unordered group contains two rule calls. The indent decrement is only called, if the unordered group has the "right" order:
Models :
m += Model*
;
Model:
'model' name=ID
(
('greet' greetings+=Greeting+)?
& ('test' test+=Content+)?
);
Content:
name=STRING
;
Greeting:
'Hello' name=ID '!';
public class MyDslFormatter extends AbstractDeclarativeFormatter {
@Override
protected void configureFormatting(FormattingConfig c) {
MyDslGrammarAccess ga = (MyDslGrammarAccess) getGrammarAccess();
c.setLinewrap().before(ga.getModelAccess().getModelKeyword_0());
c.setLinewrap().before(ga.getModelAccess().getGreetKeyword_2_0_0());
c.setLinewrap().before(ga.getModelAccess().getTestKeyword_2_1_0());
c.setLinewrap().before(ga.getContentAccess().getNameAssignment());
c.setLinewrap().before(ga.getGreetingAccess().getHelloKeyword_0());
c.setIndentationIncrement().before(ga.getGreetingRule());
c.setIndentationDecrement().after(ga.getGreetingRule());
c.setIndentationIncrement().before(ga.getContentRule());
c.setIndentationDecrement().after(ga.getContentRule());
c.setIndentationIncrement().after(
ga.getModelAccess().getNameAssignment_1());
// This one is not called correctly
c.setIndentationDecrement().after(ga.getModelRule());
}
}
And the model.mydsl:
model one
greet
Hello a
Hello b
Hello c
test
model one
greet
Hello a
Hello b
Hello c
test
I can confirm this behavior for Xtext SDK 2.5.4.v201404100756: unordered groups only get correctly formatted if the concrete syntax is in fact "ordered" according to the definition of the unordered group in the respective rule. Are there any known workarounds? Xtext 2.7.3 still has this annoying behaviour. *sigh* It's actually fixed with the new formatting infrastructure (see bug 436454). The new formatting infrastructure is already part of Xtext's nightly builds and will be released as internal API with Xtext 2.8.0. It will become public API later. I'm leaving this bug open to make sure we'll implement a test case for this scenario. Scheduled for v2.8 - see comment #7 won't fix because it affects the old formatter infrastructure |