Skip to content

Commit

Permalink
Change message syntax
Browse files Browse the repository at this point in the history
Ref. #380
  • Loading branch information
treiher committed Aug 6, 2020
1 parent f483948 commit 4bc411b
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ package TLV is
message
Tag : Tag
then Length
if Tag = Msg_Data,
if Tag = Msg_Data
then null
if Tag = Msg_Error;
Length : Length
Expand Down
6 changes: 3 additions & 3 deletions doc/Language-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ A message type is a collection components. Additional then clauses allow to defi
*message_definition* ::= __message__ [ *null_component* ] *component* { *component* } __end message__ | __null message__

*component* ::= *component_name* __:__ *component_type*
[ *then_clause* ] { __,__ *then_clause* } __;__
{ *then_clause* } __;__

*null_component* ::= __null__
*then_clause* __;__
Expand Down Expand Up @@ -120,7 +120,7 @@ type Frame is
EtherType : U16
then Payload
with Length => EtherType * 8
if EtherType <= 1500,
if EtherType <= 1500
then Payload
with Length => Message'Last - EtherType'Last
if EtherType >= 1536;
Expand Down Expand Up @@ -230,7 +230,7 @@ package Ethernet is
EtherType : U16
then Payload
with Length => EtherType * 8
if EtherType <= 1500,
if EtherType <= 1500
then Payload
with Length => Message'Last - EtherType'Last
if EtherType >= 1536;
Expand Down
16 changes: 8 additions & 8 deletions examples/ping/specs/icmp.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ package ICMP is
message
Tag : Tag
then Code_Destination_Unreachable
if Tag = Destination_Unreachable,
if Tag = Destination_Unreachable
then Code_Time_Exceeded
if Tag = Time_Exceeded,
if Tag = Time_Exceeded
then Code_Redirect
if Tag = Redirect,
if Tag = Redirect
then Code_Zero
if (Tag = Echo_Reply
or Tag = Echo_Request
Expand All @@ -74,16 +74,16 @@ package ICMP is
then Unused_32
if (Tag = Destination_Unreachable
or Tag = Source_Quench
or Tag = Time_Exceeded),
or Tag = Time_Exceeded)
then Identifier
if (Tag = Echo_Request
or Tag = Echo_Reply
or Tag = Timestamp_Msg
or Tag = Timestamp_Reply
or Tag = Information_Request
or Tag = Information_Reply),
or Tag = Information_Reply)
then Pointer
if Tag = Parameter_Problem,
if Tag = Parameter_Problem
then Gateway_Internet_Address
if Tag = Redirect;
Gateway_Internet_Address : Gateway_Internet_Address
Expand All @@ -99,9 +99,9 @@ package ICMP is
Identifier : Identifier;
Sequence_Number : Sequence_Number
then Originate_Timestamp
if Tag = Timestamp_Msg or Tag = Timestamp_Reply,
if Tag = Timestamp_Msg or Tag = Timestamp_Reply
then null
if Tag = Information_Request or Tag = Information_Reply,
if Tag = Information_Request or Tag = Information_Reply
then Data
with Length => Message'Last - Sequence_Number'Last
if Tag = Echo_Reply or Tag = Echo_Request;
Expand Down
2 changes: 1 addition & 1 deletion examples/ping/specs/ipv4_option.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package IPv4_Option is
Option_Class : Option_Class;
Option_Number : Option_Number
then null
if Option_Class = Control and Option_Number = 1,
if Option_Class = Control and Option_Number = 1
then Option_Length
if Option_Number > 1;
Option_Length : Option_Length
Expand Down
5 changes: 3 additions & 2 deletions rflx/parser/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,16 @@ def message_type_definition() -> Token:
- Group(Optional(value_constraint()))
)
then.setParseAction(parse_then)
then_list = then + ZeroOrMore(comma() - then)
then_list = ZeroOrMore(then)
then_list.setParseAction(lambda t: [t.asList()])

component_item = (
~Keyword("end")
+ ~CaselessKeyword("Message")
- unqualified_identifier()
+ Literal(":")
- qualified_identifier()
- Optional(then_list)
- then_list
- semicolon()
)
component_item.setParseAction(
Expand Down
4 changes: 2 additions & 2 deletions specs/ethernet.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package Ethernet is
Type_Length_TPID : Type_Length
then TPID
with First => Type_Length_TPID'First
if Type_Length_TPID = 16#8100#,
if Type_Length_TPID = 16#8100#
then Type_Length
with First => Type_Length_TPID'First
if Type_Length_TPID /= 16#8100#;
Expand All @@ -21,7 +21,7 @@ package Ethernet is
Type_Length : Type_Length
then Payload
with Length => Type_Length * 8
if Type_Length <= 1500,
if Type_Length <= 1500
then Payload
with Length => Message'Last - Type_Length'Last
if Type_Length >= 1536;
Expand Down
18 changes: 9 additions & 9 deletions specs/icmp.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ package ICMP is
message
Tag : Tag
then Code_Destination_Unreachable
if Tag = Destination_Unreachable,
if Tag = Destination_Unreachable
then Code_Time_Exceeded
if Tag = Time_Exceeded,
if Tag = Time_Exceeded
then Code_Redirect
if Tag = Redirect,
if Tag = Redirect
then Code_Zero
if (Tag = Echo_Reply
or Tag = Echo_Request
Expand All @@ -74,16 +74,16 @@ package ICMP is
then Unused_32
if (Tag = Destination_Unreachable
or Tag = Source_Quench
or Tag = Time_Exceeded),
or Tag = Time_Exceeded)
then Identifier
if (Tag = Echo_Request
or Tag = Echo_Reply
or Tag = Timestamp_Msg
or Tag = Timestamp_Reply
or Tag = Information_Request
or Tag = Information_Reply),
or Tag = Information_Reply)
then Pointer
if Tag = Parameter_Problem,
if Tag = Parameter_Problem
then Gateway_Internet_Address
if Tag = Redirect;
Gateway_Internet_Address : Gateway_Internet_Address
Expand All @@ -99,9 +99,9 @@ package ICMP is
Identifier : Identifier;
Sequence_Number : Sequence_Number
then Originate_Timestamp
if Tag = Timestamp_Msg or Tag = Timestamp_Reply,
if Tag = Timestamp_Msg or Tag = Timestamp_Reply
then null
if Tag = Information_Request or Tag = Information_Reply,
if Tag = Information_Request or Tag = Information_Reply
then Data
with Length => Message'Last - Sequence_Number'Last
if Tag = Echo_Reply or Tag = Echo_Request;
Expand All @@ -112,4 +112,4 @@ package ICMP is
Data : Opaque;
end message;

end ICMP;
end ICMP;
2 changes: 1 addition & 1 deletion specs/ipv4.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package IPv4 is
Option_Class : Option_Class;
Option_Number : Option_Number
then null
if Option_Class = Control and Option_Number = 1,
if Option_Class = Control and Option_Number = 1
then Option_Length
if Option_Number > 1;
Option_Length : Option_Length
Expand Down
4 changes: 2 additions & 2 deletions specs/tls_handshake.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ package TLS_Handshake is
with Length => Legacy_Compression_Methods_Length * 8;
Legacy_Compression_Methods : Opaque
then null
if Message'Last / 8 = Legacy_Compression_Methods'Last / 8,
if Message'Last / 8 = Legacy_Compression_Methods'Last / 8
then Extensions_Length
if Message'Last / 8 /= Legacy_Compression_Methods'Last / 8;
Extensions_Length : Client_Hello_Extensions_Length
Expand Down Expand Up @@ -165,7 +165,7 @@ package TLS_Handshake is
Extensions_Length : Server_Hello_Extensions_Length
then Extensions
with Length => Extensions_Length * 8
if Random /= (16#CF#, 16#21#, 16#AD#, 16#74#, 16#E5#, 16#9A#, 16#61#, 16#11#, 16#BE#, 16#1D#, 16#8C#, 16#02#, 16#1E#, 16#65#, 16#B8#, 16#91#, 16#C2#, 16#A2#, 16#11#, 16#16#, 16#7A#, 16#BB#, 16#8C#, 16#5E#, 16#07#, 16#9E#, 16#09#, 16#E2#, 16#C8#, 16#A8#, 16#33#, 16#9C#),
if Random /= (16#CF#, 16#21#, 16#AD#, 16#74#, 16#E5#, 16#9A#, 16#61#, 16#11#, 16#BE#, 16#1D#, 16#8C#, 16#02#, 16#1E#, 16#65#, 16#B8#, 16#91#, 16#C2#, 16#A2#, 16#11#, 16#16#, 16#7A#, 16#BB#, 16#8C#, 16#5E#, 16#07#, 16#9E#, 16#09#, 16#E2#, 16#C8#, 16#A8#, 16#33#, 16#9C#)
then HRR_Extensions
with Length => Extensions_Length * 8
if Random = (16#CF#, 16#21#, 16#AD#, 16#74#, 16#E5#, 16#9A#, 16#61#, 16#11#, 16#BE#, 16#1D#, 16#8C#, 16#02#, 16#1E#, 16#65#, 16#B8#, 16#91#, 16#C2#, 16#A2#, 16#11#, 16#16#, 16#7A#, 16#BB#, 16#8C#, 16#5E#, 16#07#, 16#9E#, 16#09#, 16#E2#, 16#C8#, 16#A8#, 16#33#, 16#9C#);
Expand Down
2 changes: 1 addition & 1 deletion specs/tls_record.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package TLS_Record is
Length : Length
then Fragment
with Length => Length * 8
if Tag /= APPLICATION_DATA and Length <= 2**14,
if Tag /= APPLICATION_DATA and Length <= 2**14
then Encrypted_Record
with Length => Length * 8
if Tag = APPLICATION_DATA and Legacy_Record_Version = TLS_1_2;
Expand Down
2 changes: 1 addition & 1 deletion specs/tlv.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package TLV is
message
Tag : Tag
then Length
if Tag = Msg_Data,
if Tag = Msg_Data
then null
if Tag = Msg_Error;
Length : Length
Expand Down
2 changes: 1 addition & 1 deletion tests/message_type.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package Message_Type is
message
Foo : T
then Bar
if Foo <= 16#1E#,
if Foo <= 16#1E#
then Baz
if Foo > 16#1E#;
Bar : T;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_potential_name_conflicts_fields_literals() -> None:
message
A : E
then null
if A = F_A,
if A = F_A
then B
if A = F_B;
B : E;
Expand Down
2 changes: 1 addition & 1 deletion tests/tlv_with_checksum.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package TLV_With_Checksum is
message
Tag : Tag
then Length
if Tag = Msg_Data,
if Tag = Msg_Data
then null
if Tag = Msg_Error;
Length : Length
Expand Down

0 comments on commit 4bc411b

Please sign in to comment.