Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatting: respect newlines
Formatting: respect newlines [message #1857028] Fri, 13 January 2023 14:30 Go to next message
Simon Cockx is currently offline Simon CockxFriend
Messages: 69
Registered: October 2021
Member
Suppose I'm writing a formatter for an expression language, and I would like to allow two ways of writing an expression.

In the following example, the `extract` operator should either be preceded by a single space or it should start on a new line.
expr extract prop

expr
    extract prop

However, if it starts on a new line, I would like to add indentation. Is it possible to express this somehow?

Examples of reformatting:
expr
extract
prop

=>
expr
    extract prop


expr        extract
prop

=>
expr extract prop


expr
            extract prop

=>
expr
    extract prop

[Updated on: Fri, 13 January 2023 14:35]

Report message to a moderator

Re: Formatting: respect newlines [message #1857031 is a reply to message #1857028] Fri, 13 January 2023 14:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
You could read the node model in the formatter, check for nl,
Then if else


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Formatting: respect newlines [message #1857033 is a reply to message #1857031] Fri, 13 January 2023 15:47 Go to previous message
Simon Cockx is currently offline Simon CockxFriend
Messages: 69
Registered: October 2021
Member
Slide 138 of https://www.slideshare.net/meysholdt/xtexts-new-formatter-api covered this, thanks. :)

Basically I can do something like
if (extractExpression.regionFor.keyword("extract").previousHiddenRegion.isMultiline) {
 ...
} else {
 ...
}

Great stuff!
Previous Topic:exec-maven-plugin with Xtext
Next Topic:How to implement Formatter maxLineWidth?
Goto Forum:
  


Current Time: Sat Nov 09 02:23:42 GMT 2024

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

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

Back to the top