Skip to content

Commit 927c641

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 183cbfd commit 927c641

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,8 +1212,13 @@ private List<DslLine> preProcessLines(List<String> lines) {
12121212

12131213
for (String line : lines) {
12141214
if (!COMMENT_PATTERN.matcher(line).matches() && line.endsWith(MULTI_LINE_SEPARATOR)) {
1215-
buf.append(line, 0, line.length()-1);
1216-
lineComplete = false;
1215+
if (lineComplete) {
1216+
buf.append(line, 0, line.length()-1);
1217+
lineComplete = false;
1218+
} else {
1219+
String strippedLine = line.stripLeading();
1220+
buf.append(strippedLine, 0, strippedLine.length() - 1);
1221+
}
12171222
} else {
12181223
if (lineComplete) {
12191224
buf.append(line);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,14 @@ void test_MultiLineSupport() throws Exception {
11411141
assertNotNull(parser.getWorkspace().getModel().getSoftwareSystemWithName("Software System"));
11421142
}
11431143

1144+
@Test
1145+
void test_MultiLineInTheMiddleOfTheStringSupport() throws Exception {
1146+
StructurizrDslParser parser = new StructurizrDslParser();
1147+
parser.parse(new File("src/test/resources/dsl/multi-line-break-string.dsl"));
1148+
1149+
assertNotNull(parser.getWorkspace().getModel().getSoftwareSystemWithName("Software System"));
1150+
}
1151+
11441152
@Test
11451153
void test_MultiLineWithError() {
11461154
File dslFile = new File("src/test/resources/dsl/multi-line-with-error.dsl");
Lines changed: 20 additions & 0 deletions
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)