From 458b79b4a6cb22168f00ee130c6b7ce9572b67c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 23 Jul 2021 19:08:04 +0200 Subject: [PATCH 1/4] Allow empty target properties block This is especially handy when you comment out a target property. For now if the block happens to be empty you get a really unfriendly error: lfc: fatal error: Unable to validate resource. Reason: no viable alternative at input '}' missing '}' at ';' Unrecognized target parameter: null. Recognized parameters are: build, build-type, clock-sync, clock-sync-options, cmake-include, compiler, docker, external-runtime-path, fast, files, flags, coordination, coordination-options, keepalive, logging, no-compile, no-runtime-validation, protobufs, runtime-version, threads, timeout, tracing. --- .../src/org/lflang/tests/LFParsingTest.java | 11 +++++++++++ org.lflang/src/org/lflang/LinguaFranca.xtext | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java b/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java index 67f7a6265e..8624d68e74 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java @@ -26,6 +26,17 @@ public class LFParsingTest { private ParseHelper parseHelper; + @Test + public void testLexingEmptyTargetProperties() throws Exception { + assertNoParsingErrorsIn("target C { }; \nreactor Foo {}"); + assertNoParsingErrorsIn("target C {,}; \nreactor Foo {}"); + assertNoParsingErrorsIn("target C {a:b,}; \nreactor Foo {}"); + // array elements + assertNoParsingErrorsIn("target C {x:[ ]}; \nreactor Foo {}"); + assertNoParsingErrorsIn("target C {x:[]}; \nreactor Foo {}"); + assertNoParsingErrorsIn("target C {x:[,]}; \nreactor Foo {}"); + } + @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 5c2400933e..2371f9c243 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -243,13 +243,14 @@ Delay: /////////// For target parameters KeyValuePairs: - '{' pairs+=KeyValuePair (',' (pairs+=KeyValuePair))* ','? '}'; + '{' ( pairs+=KeyValuePair (',' (pairs+=KeyValuePair))* )? ','? '}'; KeyValuePair: name=Kebab ':' value=Element; Array: - '[' elements+=Element (',' (elements+=Element))* ','? ']'; + '[' ( elements+=Element (',' (elements+=Element))* )? ','? ']' + | '[]'; // remember this is tokenized as a single token in LF Element: keyvalue=KeyValuePairs From b1b29d04dd9448c7150b3735ab81f1206fe65f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 28 Sep 2021 13:00:11 +0200 Subject: [PATCH 2/4] Revert changes to array --- org.lflang/src/org/lflang/LinguaFranca.xtext | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 25b2441c65..bfac72d076 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -256,9 +256,8 @@ KeyValuePairs: KeyValuePair: name=Kebab ':' value=Element; -Array: - '[' ( elements+=Element (',' (elements+=Element))* )? ','? ']' - | '[]'; // remember this is tokenized as a single token in LF +Array: // todo allow empty array in grammar, replace with validator error + '[' elements+=Element (',' (elements+=Element))* ','? ']'; Element: keyvalue=KeyValuePairs From 1a9baeae96ad2cd713e7402d5fc20e5e03271c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 29 Sep 2021 15:31:46 +0200 Subject: [PATCH 3/4] Disallow `{,}` Co-authored-by: Marten Lohstroh --- org.lflang/src/org/lflang/LinguaFranca.xtext | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index bfac72d076..9ad861332e 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -251,7 +251,7 @@ Serializer: /////////// For target parameters KeyValuePairs: - '{' ( pairs+=KeyValuePair (',' (pairs+=KeyValuePair))* )? ','? '}'; + {KeyValuePairs} '{' (pairs+=KeyValuePair (',' (pairs+=KeyValuePair))* ','?)? '}'; KeyValuePair: name=Kebab ':' value=Element; From ce66faf81ac85e2adab235c264d5402ecdaeb436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 29 Sep 2021 15:32:37 +0200 Subject: [PATCH 4/4] Add test case --- org.lflang.tests/src/org/lflang/tests/LFParsingTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java b/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java index 1be4167b04..487c3b21e5 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java @@ -29,8 +29,9 @@ public class LFParsingTest { @Test public void testLexingEmptyTargetProperties() throws Exception { assertNoParsingErrorsIn("target C { }; \nreactor Foo {}"); - assertNoParsingErrorsIn("target C {,}; \nreactor Foo {}"); assertNoParsingErrorsIn("target C {a:b,}; \nreactor Foo {}"); + expectParsingErrorIn("target C {,}; \nreactor Foo {}"); + // array elements // assertNoParsingErrorsIn("target C {x:[ ]}; \nreactor Foo {}"); // assertNoParsingErrorsIn("target C {x:[]}; \nreactor Foo {}");