Skip to content

Commit 4f8c7a0

Browse files
committed
Removes redundant spaces in single tokens with multiline separators
Now cases when a single keyword is split by multiple multiline separators are supported. ```structurizr work\ spa\ ce { } ``` Also fixes redundant spaces inside quoted strings. The following code was parsed as `"Soft ware System"` before. ```structurizr "Soft\ ware \ Sys\ tem" ``` BREAKING CHANGE! The following code produced valid workspace before, because whitespaces in the second line were preserved. Now the first three lines will produce a single token `workspace{`. ```structurizr workspace\ \ { } ```
1 parent 39bf3d0 commit 4f8c7a0

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,13 @@ private List<DslLine> preProcessLines(List<String> lines) {
953953

954954
for (String line : lines) {
955955
if (line.endsWith(MULTI_LINE_SEPARATOR)) {
956-
buf.append(line, 0, line.length()-1);
957-
lineComplete = false;
956+
if (lineComplete) {
957+
buf.append(line, 0, line.length()-1);
958+
lineComplete = false;
959+
} else {
960+
String strippedLine = line.stripLeading();
961+
buf.append(strippedLine, 0, strippedLine.length() - 1);
962+
}
958963
} else {
959964
if (lineComplete) {
960965
buf.append(line);

structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,14 @@ void test_MultiLineSupport() throws Exception {
973973
assertNotNull(parser.getWorkspace().getModel().getSoftwareSystemWithName("Software System"));
974974
}
975975

976+
@Test
977+
void test_MultiLineInTheMiddleOfTheStringSupport() throws Exception {
978+
StructurizrDslParser parser = new StructurizrDslParser();
979+
parser.parse(new File("src/test/resources/dsl/multi-line-break-string.dsl"));
980+
981+
assertNotNull(parser.getWorkspace().getModel().getSoftwareSystemWithName("Software System"));
982+
}
983+
976984
@Test
977985
void test_MultiLineWithError() {
978986
File dslFile = new File("src/test/resources/dsl/multi-line-with-error.dsl");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
work\
2+
sp\
3+
ace {
4+
5+
mo\
6+
d\
7+
el {
8+
soft\
9+
wareSys\
10+
tem = \
11+
soft\
12+
wareSys\
13+
tem \
14+
"Sof\
15+
tware \
16+
Sys\
17+
tem"
18+
}
19+
20+
}

0 commit comments

Comments
 (0)