From 066596dcd37fb510d8e652691438ce27ed4911bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 1 Nov 2022 15:45:33 +0100 Subject: [PATCH] Tokenize empty bracket pairs properly --- .../tests/compiler/LinguaFrancaParsingTest.java | 12 ++++++++++++ org.lflang/src/org/lflang/LinguaFranca.xtext | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java index 397ed8aa99..083220c528 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java @@ -94,6 +94,18 @@ main reactor(@b parm: int) { parseWithoutError(testCase); } + @Test + public void testTokenizeEmptyWidth() throws Exception { + String testCase = """ + target C; + main reactor { + state foo: int[]; + state foo: int[ ]; //spaces are allowed + } + """; + parseWithoutError(testCase); + } + private Model parseWithoutError(String s) throws Exception { Model model = parser.parse(s); Assertions.assertNotNull(model); diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 4049f297fe..cd175fab09 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -332,11 +332,11 @@ Type: ; ArraySpec: - ofVariableLength?='[]' | '[' length=INT ']'; - + '[' ( ofVariableLength?=']' | length=INT ']' ); + WidthSpec: - ofVariableLength?='[]' | '[' (terms+=WidthTerm) ('+' terms+=WidthTerm)* ']'; - + '[' ( ofVariableLength?=']' | (terms+=WidthTerm) ('+' terms+=WidthTerm)* ']' ); + WidthTerm: width=INT | parameter=[Parameter] @@ -502,7 +502,7 @@ Token: // Braces '(' | ')' | '{' | '}' | // Brackets - '[' | ']' | '<' | '>' | '[]' | + '[' | ']' | '<' | '>' | // Punctuation ':' | ';' | ',' | '.' | '::' | // Slashes