From 15978047d15da30499d594a095ee606c0ec29145 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 19 Jan 2022 16:05:32 -0500 Subject: [PATCH] Rename "structure_member" to field since that seems easier to type and is a good term --- scripts/idl/matter_grammar.lark | 10 +++++----- scripts/idl/matter_idl_types.py | 12 ++++++------ scripts/idl/parser.py | 22 +++++++++++----------- scripts/idl/test_parsing.py | 30 +++++++++++++++--------------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/scripts/idl/matter_grammar.lark b/scripts/idl/matter_grammar.lark index 73ec7be44549cd..baa87a21b62990 100644 --- a/scripts/idl/matter_grammar.lark +++ b/scripts/idl/matter_grammar.lark @@ -1,13 +1,13 @@ -struct: "struct"i id "{" struct_member* "}" +struct: "struct"i id "{" struct_field* "}" enum: "enum"i id ":" type "{" enum_entry* "}" -event: event_priority "event"i id "=" number "{" struct_member* "}" +event: event_priority "event"i id "=" number "{" struct_field* "}" ?event_priority: "critical"i -> critical_priority | "info"i -> info_priority | "debug"i -> debug_priority -attribute: "attribute"i "(" attribute_access ")" named_member +attribute: "attribute"i "(" attribute_access ")" field attribute_access: "readonly"i -> readonly | "writable"i -> writable @@ -29,12 +29,12 @@ endpoint_cluster: endpoint_cluster_type "cluster"i id ";" enum_entry: id "=" number ";" number: POSITIVE_INTEGER | HEX_INTEGER -struct_member: member_attribute* named_member +struct_field: member_attribute* field member_attribute: "optional"i -> optional | "nullable"i -> nullable -named_member: type id list_marker? "=" number ";" +field: type id list_marker? "=" number ";" list_marker: "[" "]" id: ID diff --git a/scripts/idl/matter_idl_types.py b/scripts/idl/matter_idl_types.py index d3f5d676659e8e..89dd63b0ad614c 100644 --- a/scripts/idl/matter_idl_types.py +++ b/scripts/idl/matter_idl_types.py @@ -4,7 +4,7 @@ from typing import List, Set -class MemberAttribute(enum.Enum): +class FieldAttribute(enum.Enum): OPTIONAL = enum.auto() NULLABLE = enum.auto() @@ -36,24 +36,24 @@ class EndpointContentType(enum.Enum): @dataclass -class StructureMember: +class Field: data_type: str code: int name: str is_list: bool = False - attributes: Set[MemberAttribute] = field(default_factory=set) + attributes: Set[FieldAttribute] = field(default_factory=set) @dataclass class Attribute: access: AttributeAccess - definition: StructureMember + definition: Field @dataclass class Struct: name: str - members: List[StructureMember] + fields: List[Field] tag: StructTag = None @@ -62,7 +62,7 @@ class Event: priority: EventPriority name: str code: int - members: List[StructureMember] + fields: List[Field] @dataclass diff --git a/scripts/idl/parser.py b/scripts/idl/parser.py index 6d4861cc4f55a8..a688bc3a02e80e 100755 --- a/scripts/idl/parser.py +++ b/scripts/idl/parser.py @@ -54,18 +54,18 @@ def enum_entry(self, id, number): def enum(self, id, type, *entries): return Enum(name=id, base_type=type, entries=list(entries)) - def named_member(self, args): + def field(self, args): data_type, name = args[0], args[1] is_list = (len(args) == 4) code = args[-1] - return StructureMember(data_type=data_type, name=name, code=code, is_list=is_list) + return Field(data_type=data_type, name=name, code=code, is_list=is_list) def optional(self, _): - return MemberAttribute.OPTIONAL + return FieldAttribute.OPTIONAL def nullable(self, _): - return MemberAttribute.NULLABLE + return FieldAttribute.NULLABLE def readonly(self, _): return AttributeAccess.READONLY @@ -88,12 +88,12 @@ def endpoint_server_cluster(self, _): def endpoint_binding_to_cluster(self, _): return EndpointContentType.CLIENT_BINDING - def struct_member(self, args): + def struct_field(self, args): # Last argument is the named_member, the rest # are attributes - member = args[-1] - member.attributes = set(args[:-1]) - return member + field = args[-1] + field.attributes = set(args[:-1]) + return field def server_cluster(self, _): return ClusterSide.SERVER @@ -110,15 +110,15 @@ def command(self, args): return Command(name=args[0], input_param=param_in, output_param=args[-2], code=args[-1]) def event(self, args): - return Event(priority=args[0], name=args[1], code=args[2], members=args[3:], ) + return Event(priority=args[0], name=args[1], code=args[2], fields=args[3:], ) @v_args(inline=True) def attribute(self, attribute_access, named_member): return Attribute(access=attribute_access, definition=named_member) @v_args(inline=True) - def struct(self, id, *members): - return Struct(name=id, members=list(members)) + def struct(self, id, *fields): + return Struct(name=id, fields=list(fields)) @v_args(inline=True) def request_struct(self, value): diff --git a/scripts/idl/test_parsing.py b/scripts/idl/test_parsing.py index fb9cd522c21b0f..59fd7440b480dc 100644 --- a/scripts/idl/test_parsing.py +++ b/scripts/idl/test_parsing.py @@ -67,13 +67,13 @@ def test_global_struct(self): expected = Idl(structs=[ Struct(name='Something', - members=[ - StructureMember( + fields=[ + Field( data_type="CHAR_STRING", code=1, name="astring", ), - StructureMember(data_type="CLUSTER_ID", code=2, name="idlist", is_list=True, attributes=set( - [MemberAttribute.OPTIONAL])), - StructureMember(data_type="int", code=0x123, name="valueThatIsNullable", attributes=set( - [MemberAttribute.NULLABLE])), + Field(data_type="CLUSTER_ID", code=2, name="idlist", is_list=True, attributes=set( + [FieldAttribute.OPTIONAL])), + Field(data_type="int", code=0x123, name="valueThatIsNullable", attributes=set( + [FieldAttribute.NULLABLE])), ])] ) self.assertEqual(actual, expected) @@ -91,9 +91,9 @@ def test_cluster_attribute(self): name="MyCluster", code=0x321, attributes=[ - Attribute(access=AttributeAccess.READONLY, definition=StructureMember( + Attribute(access=AttributeAccess.READONLY, definition=Field( data_type="int8u", code=1, name="roAttr")), - Attribute(access=AttributeAccess.READWRITE, definition=StructureMember( + Attribute(access=AttributeAccess.READWRITE, definition=Field( data_type="int32u", code=123, name="rwAttr", is_list=True)), ] )]) @@ -115,10 +115,10 @@ def test_cluster_commands(self): name="WithCommands", code=1, structs=[ - Struct(name="FreeStruct", members=[]), - Struct(name="InParam", members=[], + Struct(name="FreeStruct", fields=[]), + Struct(name="InParam", fields=[], tag=StructTag.REQUEST), - Struct(name="OutParam", members=[], + Struct(name="OutParam", fields=[], tag=StructTag.RESPONSE), ], commands=[ @@ -167,14 +167,14 @@ def test_cluster_events(self): name="EventTester", code=0x123, events=[ - Event(priority=EventPriority.CRITICAL, name="StartUp", code=0, members=[ - StructureMember(data_type="INT32U", + Event(priority=EventPriority.CRITICAL, name="StartUp", code=0, fields=[ + Field(data_type="INT32U", code=0, name="softwareVersion"), ]), Event(priority=EventPriority.INFO, - name="Hello", code=1, members=[]), + name="Hello", code=1, fields=[]), Event(priority=EventPriority.DEBUG, - name="GoodBye", code=2, members=[]), + name="GoodBye", code=2, fields=[]), ])]) self.assertEqual(actual, expected)