diff --git a/src/plcdoc/st_declaration.tx b/src/plcdoc/st_declaration.tx index 7b4a5a1..059761f 100644 --- a/src/plcdoc/st_declaration.tx +++ b/src/plcdoc/st_declaration.tx @@ -68,7 +68,7 @@ TypeEnum: ')' (base_type=Fqn)? (default=EnumDefault)? - ';' + SemiColon ; EnumOption: @@ -89,7 +89,7 @@ TypeAlias: base=VariableType CommentAny* // Catch trailing comments here, not at the end of `Variable` - ';' + SemiColon ; /* @@ -106,7 +106,7 @@ Function: ('EXTENDS' extends=Fqn)? ('IMPLEMENTS' implements=Fqn)? (':' return=VariableType (arglist=ArgList)?)? - (';')? + (SemiColon)? lists*=VariableList ; @@ -167,7 +167,7 @@ Variable: type=VariableType (arglist=ArgList)? (AssignmentSymbol value=AssignmentValue)? - ';' + SemiColon comment=CommentLine? ; @@ -235,6 +235,13 @@ Fqn[noskipws]: /\s/*- ; +/* +Semi-colons may be repeated in valid code +*/ +SemiColon: + ';'+ +; + /* Anything that is considered a value: a literal, a variable, or e.g. a sum */ diff --git a/tests/plc_code/FB_Variables.txt b/tests/plc_code/FB_Variables.txt index 490c5eb..8028425 100644 --- a/tests/plc_code/FB_Variables.txt +++ b/tests/plc_code/FB_Variables.txt @@ -54,6 +54,8 @@ myfloat_no_ws:REAL; mypointer2 : REFERENCE TO UDINT; mypointer3 : REFERENCE TO FB_Motor REF= _motor; + extra_semicolons : INT := 7;;;;;;;;;; + timeout1 : TIME := T#2S; timeout2 : TIME := T#12m13s14ms; diff --git a/tests/test_st_grammar.py b/tests/test_st_grammar.py index 66b447b..f829f9a 100644 --- a/tests/test_st_grammar.py +++ b/tests/test_st_grammar.py @@ -80,8 +80,8 @@ def test_grammar_variables(meta_model): filepath = os.path.realpath(tests_dir + "/plc_code/" + filename) try: model = meta_model.model_from_file(filepath) - except: - pytest.fail(f"Error when analyzing the file `{filename}`") + except TextXSyntaxError as err: + pytest.fail(f"Error when analyzing the file `{filename}`: {err}") else: assert model.functions fb = model.functions[0] @@ -145,12 +145,13 @@ def test_grammar_variables(meta_model): ("mypointer1", "UDINT", None, None, None, "POINTER"), ("mypointer2", "UDINT", None, None, None, "REFERENCE"), ("mypointer3", "FB_Motor", "_motor", None, None, "REFERENCE"), + ("extra_semicolons", "INT", "7", None, None, None), ("timeout1", "TIME", "T#2S", None, None, None), ("timeout2", "TIME", "T#12m13s14ms", None, None, None), ("inline1", "INT", None, None, None, None), ] - assert len(variables) == 44 + assert len(variables) == 45 for i, expected in enumerate(expected_list): assert_variable(variables[i], expected)