Skip to content

Commit

Permalink
Add scope keyword for variable definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
OdysseasKr committed Nov 14, 2024
1 parent 15f1e49 commit f0a6b68
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions rapidchecker/parser/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@

# Variable definition
var_def = (
(T.PERS | T.VAR | T.CONST)
pp.Optional(T.LOCAL | T.TASK)
+ (T.PERS | T.VAR | T.CONST)
+ datatype
+ identifier
+ pp.Optional("{" + expression + "}")
+ pp.Optional(":=" + expression)
+ ";"
- identifier
- pp.Optional("{" + expression + "}")
- pp.Optional(":=" + expression)
- ";"
)
var_def_section = pp.ZeroOrMore(var_def)

Expand Down
5 changes: 5 additions & 0 deletions rapidchecker/parser/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def __init__(self, *args, **kwargs) -> None:
DEFAULT = RapidKeyword("DEFAULT")
ERROR = RapidKeyword("ERROR")
INOUT = RapidKeyword("INOUT")
TASK = RapidKeyword("TASK")
LOCAL = RapidKeyword("LOCAL")

RESERVED_WORD = (
MODULE
Expand Down Expand Up @@ -98,6 +100,9 @@ def __init__(self, *args, **kwargs) -> None:
| CASE
| DEFAULT
| ERROR
| INOUT
| TASK
| LOCAL
)

MODULE_OPTIONS = oneOf("SYSMODULE NOSTEPIN VIEWONLY READONLY")
1 change: 1 addition & 0 deletions tests/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def test_record_def(input_str: str) -> None:
"VAR robtarget targets{1000};",
"VAR robtarget targets{var1 + var2};",
"CONST num number := 1 + 1;",
"LOCAL CONST num number := 1 + 1;",
],
)
def test_var_def(input_str: str) -> None:
Expand Down

0 comments on commit f0a6b68

Please sign in to comment.