[solved] Indentation of elements in EList using formatting2 API [message #1827721] |
Thu, 21 May 2020 13:31  |
Eclipse User |
|
|
|
Hello,
I am having trouble figuring out how to indent elements in an EList using the formatting2 API. Everything I've tried so far leads to this strange "indentInc=1;indentDec=1" result or an error along the lines of "That is not allowed on an AST element.
Could anyone please help me understand what is happening when I get "indentInc=1;indentDec=1"? And of course any guidance on the proper way to go about this will be greatly appreciated.
Cheers and thank you!
grammar org.xtext.example.mydsl.MyDsl hidden(WS)
import "URL_REMOVED" as ecore
generate myDsl "URL_REMOVED"
Model:
greeting=Greeting
;
Greeting:
'Hello' ','? name=SIMPLE_WORD '!' NL+
lines+=Line*
;
Line: {Line}
SIMPLE_WORD+
NL
;
terminal SIMPLE_WORD:
('0'..'9' | 'a'..'z' | 'A'..'Z')
('0'..'9' | 'a'..'z' | 'A'..'Z' | '-' | '_')*
;
terminal NL: ('\r'? '\n');
terminal WS: (' ' | '\t');
class MyDslFormatter extends AbstractFormatter2 {
@Inject extension MyDslGrammarAccess
def dispatch void format(Model model, extension IFormattableDocument document) {
model.greeting.format()
println(document)
}
def dispatch void format(Greeting greeting, extension IFormattableDocument document) {
for (line : greeting.lines) {
line.format()
line.prepend[indent]
}
}
def dispatch void format(Line line, extension IFormattableDocument document) {
// TODO...
}
}
@RunWith(XtextRunner)
@InjectWith(MyDslInjectorProvider)
class MyDslFormattingTest {
@Inject extension FormatterTestHelper
@Test
def void indentLines() {
assertFormatted[
toBeFormatted = '''
Hello, World!
The quick brown fox
Jumps over the lazy dog
'''
expectation = '''
Hello, World!
The quick brown fox
Jumps over the lazy dog
'''
]
}
}
Quote:
----------- RootDocument with ITextReplacers (syntax: <offset|text>) -----------
Hello, World!
<14|>The quick brown fox
<34|>Jumps over the lazy dog
--------------------------------------------------------------------------------
14 0 "": HiddenRegionReplacer: indentInc=1;indentDec=1
34 0 "": HiddenRegionReplacer: indentInc=1;indentDec=1
[Updated on: Fri, 22 May 2020 16:20] by Moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.23759 seconds