Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using indent for more than one level of indentation
Using indent for more than one level of indentation [message #1782182] Tue, 20 February 2018 09:33 Go to next message
Giray Ozel is currently offline Giray OzelFriend
Messages: 18
Registered: February 2018
Junior Member
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 for the Person type 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, they cannot be resolved.
Re: Using indent for more than one level of indentation [message #1782231 is a reply to message #1782182] Tue, 20 February 2018 19:12 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14670
Registered: July 2009
Senior Member
you can do this with custom replacer as described here:
https://stackoverflow.com/questions/45305293/how-to-define-different-indentation-levels-in-the-same-document-with-xtext-forma


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Problem with ID Terminal Rule
Next Topic:Custom QualifiedNameProvider Problems
Goto Forum:
  


Current Time: Sat Apr 27 04:12:13 GMT 2024

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

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

Back to the top