Skip to content

Commit

Permalink
Remove null states
Browse files Browse the repository at this point in the history
Ref. #700
  • Loading branch information
treiher committed May 8, 2023
1 parent fc1ca64 commit 534cee6
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 34 deletions.
5 changes: 2 additions & 3 deletions parser/language/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@
),
declaration=Or(grammar.renaming_declaration, grammar.variable_declaration),
description_aspect=ast.Description("Desc", "=>", grammar.string_literal),
null_state_body=ast.NullStateBody("null", "state"),
assignment_statement=ast.Assignment(
grammar.unqualified_identifier, ":=", grammar.extended_expression
),
Expand Down Expand Up @@ -534,7 +533,7 @@
),
transition=ast.Transition(
"goto",
Or(ast.NullID("null"), grammar.unqualified_identifier),
grammar.unqualified_identifier,
Opt("with", grammar.description_aspect),
),
state_body=ast.StateBody(
Expand All @@ -553,7 +552,7 @@
grammar.unqualified_identifier,
Opt("with", grammar.description_aspect),
"is",
Or(grammar.null_state_body, grammar.state_body),
grammar.state_body,
),
session_declaration=ast.SessionDecl(
"generic",
Expand Down
13 changes: 2 additions & 11 deletions parser/language/rflx_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,6 @@ class RenamingDecl(LocalDecl):
expression = Field(type=Expr)


@abstract
class BaseStateBody(RFLXNode):
"""Base class for session state body."""


class NullStateBody(BaseStateBody):
pass


@abstract
class Statement(RFLXNode):
"""Base class for statements."""
Expand Down Expand Up @@ -270,7 +261,7 @@ class ConditionalTransition(Transition):
condition = Field(type=Expr)


class StateBody(BaseStateBody):
class StateBody(RFLXNode):
"""Body of a session state."""

declarations = Field(type=LocalDecl.list)
Expand All @@ -286,7 +277,7 @@ class State(RFLXNode):

identifier = Field(type=UnqualifiedID)
description = Field(type=Description)
body = Field(type=BaseStateBody)
body = Field(type=StateBody)


class SessionDecl(Declaration):
Expand Down
4 changes: 1 addition & 3 deletions parser/tests/data/session/tls_handshake_session.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -1486,10 +1486,8 @@ package TLS_Handshake_Session is
Application_Control_Channel'Write (GreenTLS::Application_Control_Message'(Tag => GreenTLS::APPLICATION_ALERT, Length => Data'Size, Data => Data)
where Data = GreenTLS::Alert_Message'(Description => Error));
transition
goto TERMINATED
goto null
end ERROR_SEND_LOCAL;

state TERMINATED is null state;
end Client;

end TLS_Handshake_Session;
4 changes: 1 addition & 3 deletions parser/tests/data/session/tls_record_session.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,8 @@ package TLS_Record_Session is
Client_Key_Update_Message'Reset;
Server_Key_Update_Message'Reset;
transition
goto TERMINATED
goto null
end TERMINATING;

state TERMINATED is null state;
end Client;

end TLS_Record_Session;
12 changes: 2 additions & 10 deletions parser/tests/grammar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3269,12 +3269,10 @@ def test_state(string: str, expected: Dict[str, str]) -> None:
begin
Z := False;
transition
goto B
goto null
if Z = False
goto A
end A;
state B is null state;
end Session
""",
{
Expand Down Expand Up @@ -3375,7 +3373,7 @@ def test_state(string: str, expected: Dict[str, str]) -> None:
},
},
"description": None,
"target": {"_kind": "UnqualifiedID", "_value": "B"},
"target": {"_kind": "UnqualifiedID", "_value": "null"},
}
],
"declarations": [
Expand Down Expand Up @@ -3417,12 +3415,6 @@ def test_state(string: str, expected: Dict[str, str]) -> None:
"description": None,
"identifier": {"_kind": "UnqualifiedID", "_value": "A"},
},
{
"_kind": "State",
"body": {"_kind": "NullStateBody", "_value": "null state"},
"description": None,
"identifier": {"_kind": "UnqualifiedID", "_value": "B"},
},
],
},
),
Expand Down
4 changes: 0 additions & 4 deletions parser/tests/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,6 @@ def test_suffix_precedence() -> None:
"begin transition goto {keyword} end {keyword}",
librflxlang.GrammarRule.state_body_rule,
),
(
"state {keyword} is null state",
librflxlang.GrammarRule.state_rule,
),
(
"generic session {keyword} is begin end {keyword}",
librflxlang.GrammarRule.session_declaration_rule,
Expand Down

0 comments on commit 534cee6

Please sign in to comment.