Skip to content

Commit

Permalink
Add support for global tag parsing after idl updated in master
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Jan 20, 2022
1 parent 64564f5 commit b4408df
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
5 changes: 3 additions & 2 deletions scripts/idl/matter_grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ event: event_priority "event"i id "=" number "{" struct_field* "}"
| "info"i -> info_priority
| "debug"i -> debug_priority

attribute: attribute_access? "attribute"i field
attribute_access: "readonly"i -> readonly
attribute: attribute_tag* "attribute"i field
attribute_tag: "readonly"i -> attr_readonly
| "global"i -> attr_global

request_struct: "request"i struct
response_struct: "response"i struct
Expand Down
22 changes: 13 additions & 9 deletions scripts/idl/matter_idl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def optional(self, _):
def nullable(self, _):
return FieldAttribute.NULLABLE

def readonly(self, _):
return AttributeAccess.READONLY
def attr_readonly(self, _):
return AttributeTag.READABLE

def writable(self, _):
return AttributeAccess.READWRITE
def attr_global(self, _):
return AttributeTag.GLOBAL

def critical_priority(self, _):
return EventPriority.CRITICAL
Expand Down Expand Up @@ -113,11 +113,15 @@ def event(self, args):
return Event(priority=args[0], name=args[1], code=args[2], fields=args[3:], )

def attribute(self, args):
access = AttributeAccess.READWRITE # default
if len(args) > 1:
access = args[0]

return Attribute(access=access, definition=args[-1])
tags = set(args[:-1])
# until we support write only (and need a bit of a reshuffle)
# if the 'attr_readonly == READABLE' is not in the list, we make things
# read/write
if AttributeTag.READABLE not in tags:
tags.add(AttributeTag.READABLE)
tags.add(AttributeTag.WRITABLE)

return Attribute(definition=args[-1], tags=tags)

@v_args(inline=True)
def struct(self, id, *fields):
Expand Down
21 changes: 17 additions & 4 deletions scripts/idl/matter_idl_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ class FieldAttribute(enum.Enum):
NULLABLE = enum.auto()


class AttributeAccess(enum.Enum):
READONLY = enum.auto()
READWRITE = enum.auto()
class AttributeTag(enum.Enum):
READABLE = enum.auto()
WRITABLE = enum.auto()
GLOBAL = enum.auto()


class EventPriority(enum.Enum):
Expand Down Expand Up @@ -46,8 +47,20 @@ class Field:

@dataclass
class Attribute:
access: AttributeAccess
definition: Field
tags: Set[AttributeTag] = field(default_factory=set())

@property
def is_readable(self):
return AttributeTag.READABLE in self.tags

@property
def is_writable(self):
return AttributeTag.WRITABLE in self.tags

@property
def is_global(self):
return AttributeTag.GLOBAL in self.tags


@dataclass
Expand Down
10 changes: 8 additions & 2 deletions scripts/idl/test_matter_idl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def test_cluster_attribute(self):
server cluster MyCluster = 0x321 {
readonly attribute int8u roAttr = 1;
attribute int32u rwAttr[] = 123;
global attribute int32u grwAttr[] = 124;
readonly global attribute int32u groAttr[] = 125;
}
""")

Expand All @@ -99,10 +101,14 @@ def test_cluster_attribute(self):
name="MyCluster",
code=0x321,
attributes=[
Attribute(access=AttributeAccess.READONLY, definition=Field(
Attribute(tags=set([AttributeTag.READABLE]), definition=Field(
data_type="int8u", code=1, name="roAttr")),
Attribute(access=AttributeAccess.READWRITE, definition=Field(
Attribute(tags=set([AttributeTag.READABLE, AttributeTag.WRITABLE]), definition=Field(
data_type="int32u", code=123, name="rwAttr", is_list=True)),
Attribute(tags=set([AttributeTag.GLOBAL, AttributeTag.READABLE, AttributeTag.WRITABLE]), definition=Field(
data_type="int32u", code=124, name="grwAttr", is_list=True)),
Attribute(tags=set([AttributeTag.GLOBAL, AttributeTag.READABLE]), definition=Field(
data_type="int32u", code=125, name="groAttr", is_list=True)),
]
)])
self.assertEqual(actual, expected)
Expand Down

0 comments on commit b4408df

Please sign in to comment.