Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Inconsistent formatting observed in using Xtext formatter(Inconsistent behavior observed during formatting the file writtent using xtext grammar elements)
Inconsistent formatting observed in using Xtext formatter [message #1420765] Wed, 10 September 2014 12:50
Sheetal Bhatewara is currently offline Sheetal BhatewaraFriend
Messages: 14
Registered: August 2013
Junior Member
I have xtext grammar as below :

MyDSLModel:
    (dmodel=DModel)
;

DModel:
    {DModel}
    (importSection=ImportSection)?
    (
        (groups+=Group) |
        (variableDefinition+=VariableDefinition)
    )*
;

ImportSection:
    (importDeclarations+=Import)+
;

Import:
    'import' importedNamespace=[DModel | ImportID]
;

ImportID:
    ImportIdentifier(('.'|'/')ImportIdentifier)*
;

Group:
    'group' name=Identifier
;

VariableDefinition:
    'var' name=Identifier
;

ImportIdentifier:
    Identifier
    | 'dB'
    | 'm'
    | 'true' | 'false'
    | 'parallel' | 'sequential'
    | 'sites' | 'routing'
;

Identifier:
    PortIdentifier
    | 'mode'
    | 'options'
;

PortIdentifier:
    SINGLE_CHARACTER_ID |  ID

    | 'action'
    | 'config'
    | 'disabled'
    | 'enum'
    | 'extension'
    | 'group'
    | 'import'
    | 'mod'
    | 'set'
    | 'setup'
;

terminal ID:
    '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')+
;

terminal SINGLE_CHARACTER_ID:
    ('a'..'z'|'A'..'Z'|'_')
;


Now, I have a file written using this grammar, which is as below :

import specification/FunctionalTIM.spec
import specification/FunctionalLEV.spec
import specification/FunctionalWVT.spec
group GR1
group GR2
var v1
var v2


I am trying to format this code with following implementation

public class MyDSLFormatter extends AbstractDeclarativeFormatter {

    @Inject
    private MyDSLGrammarAccess grammarAccess;

    @Override
    protected void configureFormatting(FormattingConfig c) {

    ImportElements importAccess = grammarAccess.getImportAccess();
    c.setLinewrap().after(importAccess.getRule());

    GroupElements groupAccess = grammarAccess.getGroupAccess();
    c.setLinewrap().after(groupAccess.getRule());

    VariableDefinitionElements varDefAccess = grammarAccess
                .getVariableDefinitionAccess();
    c.setLinewrap().after(varDefAccess.getRule());

}


Now, the problem I am facing is, inconsistency in formatting, when Import elements are present in my file If my file has import statements in it, then the line wrap for VariableDefinition (after the rule) is not taking effect. So, CTRL+SHIFT+F gives file as

 import specification/FunctionalTIM.spec
    import specification/FunctionalLEV.spec
    import specification/FunctionalWVT.spec
    group GR1 group GR2 var v1 var v2



Note:
But If I am having only Group elements and VariableDefinition elements, then proper line wraps are getting inserted.

So, can anyone help, why this inconsistent behavior is observed? Thanks in advance!

[Updated on: Thu, 11 September 2014 09:33]

Report message to a moderator

Previous Topic:Retrieving hidden comments
Next Topic:[2.6.3 to 2.7.1] Using eclipse application is broken
Goto Forum:
  


Current Time: Sat Dec 14 11:25:43 GMT 2019

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

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

Back to the top