I am using Xtext 2.13 and Formatter2. I am trying to put two lines between sections. But within the section, I only want one line. Because each section can have a list of different types of items, I can't determine what will be the last list item. Therefore, I am getting a conflicting regions error even though the code does format the way I want.
Is there another solution to avoid the error?
Grammar snippet:
Model :
inputSection=InputSection
actionSection=ActionSection
outputSection=OutputSection
;
InputSection :
{InputSection} (inputs+=Input)*
;
Input :
(Infile | Inprocedure)
;
Infile:
('/INFILE' | '/INFILES') ('=' | '=(') fileNames+=FileName (',' fileNames+=FileName)* (')')?
(statements+=InputStatement)*
;
InputStatement:
InputOption |
Process |
AdvancedField
;
Formatter snippet:
def dispatch void format(InputSection object, extension IFormattableDocument document) {
object.append[setNewLines(1, 2, 2)]
for (input : object.inputs) {
input.format
}
}
def dispatch void format(Infile object, extension IFormattableDocument document) {
object.append[newLine]
object.regionFor.keyword("=").surround[noSpace]
object.interior[indent]
for (stmt : object.statements) {
stmt.append[newLine]
stmt.format
}
}
Intended output:
/INFILES=random_file_placeholder
/PROCESS=RANDOM
/FIELD=(PRESIDENT, TYPE=ALPHA_DIGIT, POS=1, SIZE=26)
/FIELD=(SERVICE, TYPE=ALPHA_DIGIT, POS=28, SIZE=9)
/REPORT
/OUTFILE=stdout
/PROCESS=RECORD
/FIELD=(PRESIDENT, TYPE=ALPHA_DIGIT, POS=1, SIZE=26)
/FIELD=(SERVICE, TYPE=ALPHA_DIGIT, POS=28, SIZE=9)