diff --git a/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java b/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java index 487c3b21e5..a58dec3e12 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java @@ -27,7 +27,7 @@ public class LFParsingTest { @Test - public void testLexingEmptyTargetProperties() throws Exception { + public void testParsingEmptyTargetProperties() throws Exception { assertNoParsingErrorsIn("target C { }; \nreactor Foo {}"); assertNoParsingErrorsIn("target C {a:b,}; \nreactor Foo {}"); expectParsingErrorIn("target C {,}; \nreactor Foo {}"); @@ -38,6 +38,13 @@ public void testLexingEmptyTargetProperties() throws Exception { // assertNoParsingErrorsIn("target C {x:[,]}; \nreactor Foo {}"); } + @Test + public void testParsingListLiterals() throws Exception { + assertNoParsingErrorsIn("target Python; \nreactor Foo(p([1,])) {}"); + // [,] is not an ok list literal + expectParsingErrorIn("target Python; \nreactor Foo(p([,])) {}"); + } + @Test public void testLexingLifetimeAnnots() throws Exception { assertNoParsingErrorsIn(makeLfTargetCode("Rust", diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index c0c718ff39..cc293ec564 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -387,12 +387,8 @@ SignedInt: // List literals support even empty lists, and a trailing comma. -// Note: this expansion is weirdly written, but without the -// emptyList property, Xtext fails to push a ListLiteral node -// when the list is empty... Another bug of Xtext. ListLiteral: - '[' (items+=Value (',' items+=Value)* ','? ']' - | ','? emptyList?=']') + {ListLiteral} '[' ( items+=Value (',' items+=Value)* ','? )? ']' ; Literal: diff --git a/test/Python/src/ListLiterals.lf b/test/Python/src/ListLiterals.lf index 88a126949c..9af1583a3a 100644 --- a/test/Python/src/ListLiterals.lf +++ b/test/Python/src/ListLiterals.lf @@ -9,8 +9,9 @@ reactor Sub(seq([1,2])) { main reactor { state l12([1,2]); + state l12_trailing([1,2,]); state empty([]); - state empty2([,]); + // doesn't parse state empty2([,]); sub = new Sub(seq = [1, 2]); sub2 = new Sub(seq = (1, 2)); @@ -18,8 +19,8 @@ main reactor { reaction(startup) {= assert self.empty == [] - assert self.empty2 == [] assert self.l12 == [1, 2] + assert self.l12 == self.l12_trailing print("Success") =} }