Home » Modeling » TMF (Xtext) » How to implement Formatter maxLineWidth?
How to implement Formatter maxLineWidth? [message #1857027] |
Fri, 13 January 2023 14:19 |
Simon Cockx Messages: 69 Registered: October 2021 |
Member |
|
|
In the documentation of FormatterPreferenceKeys, it says "Formatters based on this infrastructure should honor these keys as well."
One of the keys is "maxLineWidth".
Are there any examples or guidelines on how to take this property into account?
Example: suppose we have an expression language with an expression such as
if compute(["this", "is", "a", "very", "long", "expression"]) < 10 then RunA(compute(["this", "is", "short"]) > 100) else RunB(compute(["this", "is", "a", "very", "long", "expression"]) > compute(["this", "is", "an", "even", "longer", "expression"]))
I would like to accept this expression as-is if it doesn't exceed the maxLineWidth, otherwise, I would like to reformat it to
if compute(["this", "is", "a", "very", "long", "expression"]) < 10
then RunA(compute(["this", "is", "short"]) < 5)
else RunB(
compute(["this", "is", "a", "very", "long", "expression"]) > compute(["this", "is", "an", "even", "longer", "expression"])
)
In pseudo code:
(1) if an if-then-else expression exceeds the maxLineWidth, put the condition, the "then"-branch and the "else" branch on different lines.
(2) if a function call exceeds maxLineWidth, put its arguments on a separate line.
Note that this should run incrementally: in the example, the expression `RunA(compute(["this", "is", "short"]) < 5)` is initially exceeding maxLineWidth, but after putting the if, then and else on separate lines, that's not the case anymore.
Is something like this possible to express? Or how is this kind of thing usually done? I can't seem to find a good resource illustrating this.
|
|
| | | | | | |
Goto Forum:
Current Time: Thu Dec 26 20:30:54 GMT 2024
Powered by FUDForum. Page generated in 0.02599 seconds
|