Skip to content

Commit

Permalink
Rename "structure_member" to field since that seems easier to type an…
Browse files Browse the repository at this point in the history
…d is a good term
  • Loading branch information
andy31415 committed Jan 20, 2022
1 parent f826b76 commit 1597804
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
10 changes: 5 additions & 5 deletions scripts/idl/matter_grammar.lark
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions scripts/idl/matter_idl_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Set


class MemberAttribute(enum.Enum):
class FieldAttribute(enum.Enum):
OPTIONAL = enum.auto()
NULLABLE = enum.auto()

Expand Down Expand Up @@ -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


Expand All @@ -62,7 +62,7 @@ class Event:
priority: EventPriority
name: str
code: int
members: List[StructureMember]
fields: List[Field]


@dataclass
Expand Down
22 changes: 11 additions & 11 deletions scripts/idl/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
30 changes: 15 additions & 15 deletions scripts/idl/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)),
]
)])
Expand All @@ -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=[
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1597804

Please sign in to comment.