Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for duplicated semicolons
Browse files Browse the repository at this point in the history
RobertoRoos committed Nov 28, 2024
1 parent f240279 commit 3932470
Showing 3 changed files with 17 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/plcdoc/st_declaration.tx
Original file line number Diff line number Diff line change
@@ -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
*/
2 changes: 2 additions & 0 deletions tests/plc_code/FB_Variables.txt
Original file line number Diff line number Diff line change
@@ -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;

7 changes: 4 additions & 3 deletions tests/test_st_grammar.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 3932470

Please sign in to comment.