Improve parsing of string types in idl definitions

This commit is contained in:
Marko Durkovic 2023-01-13 12:16:05 +01:00
parent eaa64002b8
commit aa18bec9d1
2 changed files with 6 additions and 6 deletions

View File

@ -73,8 +73,8 @@ typedef_dcl
= 'typedef' type_declarator
type_declarator
= ( simple_type_spec
/ template_type_spec
= ( template_type_spec
/ simple_type_spec
/ constr_type_dcl
) any_declarators
@ -169,7 +169,7 @@ octet_type
string_type
= 'string' '<' expression '>'
/ 'string\b'
/ r'string\b'
scoped_name
= identifier '::' scoped_name
@ -491,10 +491,10 @@ class VisitorIDL(Visitor): # pylint: disable=too-many-public-methods
def visit_string_type(
self,
children: Union[StringNode, tuple[LiteralMatch, LiteralMatch, LiteralNode, LiteralMatch]],
children: Union[str, tuple[LiteralMatch, LiteralMatch, LiteralNode, LiteralMatch]],
) -> Union[StringNode, tuple[Nodetype, str, LiteralNode]]:
"""Prrocess string type specifier."""
if len(children) == 2:
if isinstance(children, str):
return (Nodetype.BASE, 'string')
assert len(children) == 4

View File

@ -307,7 +307,7 @@ def test_parse_idl() -> None:
assert consts == []
assert len(fields) == 1
assert fields[0][0] == 'values'
assert fields[0][1] == (Nodetype.ARRAY, ((Nodetype.NAME, 'string'), 3))
assert fields[0][1] == (Nodetype.ARRAY, ((Nodetype.BASE, 'string'), 3))
def test_register_types() -> None: