Skip to content

Commit 0be41f4

Browse files
authored
Merge pull request #114 from OP-TED/TEDEFO-4367-add-global-variables-and-functions
Bugfix: The system can now parse a file even if there are no template lines in it.
2 parents 353261f + 63bd4e9 commit 0be41f4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ public void enterTemplateFile(TemplateFileContext ctx) {
319319

320320
@Override
321321
public void exitTemplateFile(TemplateFileContext ctx) {
322-
this.blockStack.pop();
322+
// if there are no template lines the blockStack will be empty,
323+
// otherwise there will be one block left: the one created when exiting the previous line; so we just remove it here.
324+
if (!this.blockStack.isEmpty()) {
325+
this.blockStack.pop();
326+
}
323327

324328
List<Markup> globals = new ArrayList<>();
325329
for (Identifier identifier : this.stack.getGlobals()) {

src/test/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2Test.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ void testGlobals_VariableDeclaration() {
3737
"{ND-Root, text:$t2=?test($t3, 99)} ${BT-00-Text}")));
3838
}
3939

40+
@Test
41+
void testGlobals_NoTemplateLines() {
42+
assertEquals(
43+
lines(
44+
"String:$t3='a'",
45+
"Number:$n1=12",
46+
"String:$t1=$t3",
47+
"String:test(String:$p1, Number:$p2) -> { concat($p1, $t1) }",
48+
"Number:$n2=$n1 + 1",
49+
"String:$t4=udf:test($t3, 22)"), //
50+
translateTemplate(lines(
51+
"// comment", //
52+
"{text:$t3='a'}// comment",
53+
"{number:$n1=12}",
54+
"{text:$t1=$t3}",
55+
"{text:?test(text:$p1, number:$p2) = concat($p1, $t1)}",
56+
"{number:$n2 = $n1 + 1}",
57+
"{text:$t4= ?test($t3, 22)}")));
58+
}
59+
4060
// #endregion Globals -------------------------------------------------------
4161

4262
// #region Template line ----------------------------------------------------

0 commit comments

Comments
 (0)