Skip to content

Commit 2f73f3a

Browse files
committed
Handle RecognitionException in Flux varDef. (#421)
1 parent 5dcb04b commit 2f73f3a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

metafacture-flux/src/main/antlr/org/metafacture/flux/parser/Flux.g

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ varDef
6060
->
6161
^(ASSIGN Identifier exp)
6262
;
63+
catch [RecognitionException re] {
64+
reportError(re);
65+
recover(input,re);
66+
retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
67+
throw re;
68+
}
6369

6470
flow
6571
:

metafacture-flux/src/test/java/org/metafacture/flux/FluxGrammarTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void shouldReplaceJavaEscapeSequences()
9090
}
9191

9292
@Test(expected = RuntimeException.class)
93-
public void issue421_shouldThrowRuntimeExceptionWhenSemicolonIsMissing()
93+
public void issue421_shouldThrowRuntimeExceptionWhenSemicolonInFlowIsMissing()
9494
throws RecognitionException, IOException {
9595
final String script = "\"test\"|print";
9696
try {
@@ -101,6 +101,18 @@ public void issue421_shouldThrowRuntimeExceptionWhenSemicolonIsMissing()
101101
}
102102
}
103103

104+
@Test(expected = RuntimeException.class)
105+
public void issue421_shouldThrowRuntimeExceptionWhenSemicolonInVarDefIsMissing()
106+
throws RecognitionException, IOException {
107+
final String script = "foo=42";
108+
try {
109+
FluxCompiler.compile(createInputStream(script), emptyMap());
110+
} catch (RuntimeException re) {
111+
assertEquals("mismatched input '<EOF>' expecting ';' in Flux", re.getMessage());
112+
throw re;
113+
}
114+
}
115+
104116
private ByteArrayInputStream createInputStream(String script) {
105117
return new ByteArrayInputStream(script.getBytes(StandardCharsets.UTF_8));
106118
}

0 commit comments

Comments
 (0)