Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/support and then and or else operators #25

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion blark/iec.lark
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ LOGICAL_OR: "OR"i
LOGICAL_XOR: "XOR"i
LOGICAL_AND: "AND"i
LOGICAL_NOT: "NOT"i
LOGICAL_AND_THEN: "AND_THEN"i
LOGICAL_OR_ELSE: "OR_ELSE"i
MODULO: "MOD"i
EQUALS: "="
EQUALS_NOT: "<>"
Expand All @@ -623,7 +625,11 @@ ASSIGNMENT: ":="

expression: assignment_expression ( ASSIGNMENT assignment_expression )*

assignment_expression: xor_expression ( LOGICAL_OR xor_expression )*
assignment_expression: or_else_expression ( LOGICAL_OR_ELSE or_else_expression )*

or_else_expression: and_then_expression ( LOGICAL_AND_THEN and_then_expression )*

and_then_expression: xor_expression ( LOGICAL_OR xor_expression )*

xor_expression: and_expression ( LOGICAL_XOR and_expression )*

Expand Down
20 changes: 20 additions & 0 deletions blark/tests/source/and_then_or_else.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(*<textarea rows="15" cols="81">
********************************************************************************
**** a great, big, long multiline comment
********************************************************************************
</textarea>*)
METHOD Split : POINTER TO STRING (*Returns a pointer to an error string.
Returns zero on success.*)
VAR_IN_OUT
(* The class_SELString containing the combination of characters to denote
the locations where the split shall occur.*)
sep : class_Object;
END_VAR

IF TestOne AND_THEN TestTwo THEN
DoSomething();
ELSIF TestThree OR_ELSE TestFour THEN
DoSomethingElse();
END_IF

END_METHOD
15 changes: 14 additions & 1 deletion blark/tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def test_check_unhandled_rules(grammar):
# handled as tree
"global_var_list",
"var_body",

}

todo_rules = set()
Expand Down Expand Up @@ -784,6 +783,20 @@ def test_fb_roundtrip(rule_name, value):
END_IF
"""
)),
param("if_statement", tf.multiline_code_block(
"""
IF 1 AND_THEN 1 THEN
y();
END_IF
"""
)),
param("if_statement", tf.multiline_code_block(
"""
IF 0 OR_ELSE 1 THEN
y();
END_IF
"""
)),
param("case_statement", tf.multiline_code_block(
"""
CASE expr OF
Expand Down
2 changes: 2 additions & 0 deletions blark/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,8 @@ def __str__(self) -> str:
"expression",
"add_expression",
"and_expression",
"and_then_expression",
"or_else_expression",
"assignment_expression",
"xor_expression",
"comparison_expression",
Expand Down