Skip to content

Commit 3932470

Browse files
committed
Added support for duplicated semicolons
1 parent f240279 commit 3932470

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/plcdoc/st_declaration.tx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ TypeEnum:
6868
')'
6969
(base_type=Fqn)?
7070
(default=EnumDefault)?
71-
';'
71+
SemiColon
7272
;
7373

7474
EnumOption:
@@ -89,7 +89,7 @@ TypeAlias:
8989
base=VariableType
9090
CommentAny*
9191
// Catch trailing comments here, not at the end of `Variable`
92-
';'
92+
SemiColon
9393
;
9494

9595
/*
@@ -106,7 +106,7 @@ Function:
106106
('EXTENDS' extends=Fqn)?
107107
('IMPLEMENTS' implements=Fqn)?
108108
(':' return=VariableType (arglist=ArgList)?)?
109-
(';')?
109+
(SemiColon)?
110110
lists*=VariableList
111111
;
112112

@@ -167,7 +167,7 @@ Variable:
167167
type=VariableType
168168
(arglist=ArgList)?
169169
(AssignmentSymbol value=AssignmentValue)?
170-
';'
170+
SemiColon
171171
comment=CommentLine?
172172
;
173173

@@ -235,6 +235,13 @@ Fqn[noskipws]:
235235
/\s/*-
236236
;
237237

238+
/*
239+
Semi-colons may be repeated in valid code
240+
*/
241+
SemiColon:
242+
';'+
243+
;
244+
238245
/*
239246
Anything that is considered a value: a literal, a variable, or e.g. a sum
240247
*/

tests/plc_code/FB_Variables.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ myfloat_no_ws:REAL;
5454
mypointer2 : REFERENCE TO UDINT;
5555
mypointer3 : REFERENCE TO FB_Motor REF= _motor;
5656

57+
extra_semicolons : INT := 7;;;;;;;;;;
58+
5759
timeout1 : TIME := T#2S;
5860
timeout2 : TIME := T#12m13s14ms;
5961

tests/test_st_grammar.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def test_grammar_variables(meta_model):
8080
filepath = os.path.realpath(tests_dir + "/plc_code/" + filename)
8181
try:
8282
model = meta_model.model_from_file(filepath)
83-
except:
84-
pytest.fail(f"Error when analyzing the file `{filename}`")
83+
except TextXSyntaxError as err:
84+
pytest.fail(f"Error when analyzing the file `{filename}`: {err}")
8585
else:
8686
assert model.functions
8787
fb = model.functions[0]
@@ -145,12 +145,13 @@ def test_grammar_variables(meta_model):
145145
("mypointer1", "UDINT", None, None, None, "POINTER"),
146146
("mypointer2", "UDINT", None, None, None, "REFERENCE"),
147147
("mypointer3", "FB_Motor", "_motor", None, None, "REFERENCE"),
148+
("extra_semicolons", "INT", "7", None, None, None),
148149
("timeout1", "TIME", "T#2S", None, None, None),
149150
("timeout2", "TIME", "T#12m13s14ms", None, None, None),
150151
("inline1", "INT", None, None, None, None),
151152
]
152153

153-
assert len(variables) == 44
154+
assert len(variables) == 45
154155

155156
for i, expected in enumerate(expected_list):
156157
assert_variable(variables[i], expected)

0 commit comments

Comments
 (0)