Skip to content

Commit

Permalink
Forbid writing [,] as list literal
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Oct 4, 2021
1 parent 7784b3a commit f08bd72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
9 changes: 8 additions & 1 deletion org.lflang.tests/src/org/lflang/tests/LFParsingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}");
Expand All @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions org.lflang/src/org/lflang/LinguaFranca.xtext
Original file line number Diff line number Diff line change
Expand Up @@ -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)* ','? )? ']'

This comment has been minimized.

Copy link
@lhstrh

lhstrh Oct 4, 2021

Member

Nice 👍

;

Literal:
Expand Down
5 changes: 3 additions & 2 deletions test/Python/src/ListLiterals.lf
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ 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));
sub3 = new Sub(seq = ([1, 2]));

reaction(startup) {=
assert self.empty == []
assert self.empty2 == []
assert self.l12 == [1, 2]
assert self.l12 == self.l12_trailing
print("Success")
=}
}

0 comments on commit f08bd72

Please sign in to comment.