0

I have the following grammar:

Department:
  'Department:' name = ID
  'Company:' companyName = STRING
  'Persons:' persons += Person+
;

Person:
  firstName = STRING
  ':'
  surname = STRING
  ':'
  address = STRING
;

And I would like to have formatting like this:

Department: Department1
    Company: "Company1"
    Persons:
        "Person1FirstName" : "Person1LastName" : "Person1Address"
        "Person2FirstName" : "Person2LastName" : "Person2Address"

But when I implement the formatter code I cannot seem to be able to use indent twice since the white space formatting gets merged instead of getting concatinated.

class TestsFormatter extends AbstractFormatter2
{
    def dispatch void format(Department department, extension IFormattableDocument document)
    {
        department.interior[indent]
        department.regionFor.keyword("Department:").prepend[setNewLines(2)]
        department.regionFor.keyword("Department:").append[oneSpace]
        department.regionFor.keyword("Company:").prepend[newLine]
        department.regionFor.keyword("Company:").append[oneSpace]
        department.regionFor.keyword("Persons:").prepend[newLine]

        for (Person person : department.persons)
        {
            person.format
        }
    }

    def dispatch void format(Person person, extension IFormattableDocument document)
    {
        person.prepend[indent]
        person.prepend[indent]
    }
}

I found out that there is an example with "increaseIndentation/decreaseIndentation" in the documentation of AbstractFormatter2. But when I try to use them, it cannot resolve them.

User48591
  • 301
  • 1
  • 2
  • 10

1 Answers1

1

you can achive this by using a custom replacer similar as described in How to define different indentation levels in the same document with Xtext formatter

Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32