From aa18bec9d1b27b48630aec3a8e0e9d7a9f537fe6 Mon Sep 17 00:00:00 2001 From: Marko Durkovic Date: Fri, 13 Jan 2023 12:16:05 +0100 Subject: [PATCH] Improve parsing of string types in idl definitions --- src/rosbags/typesys/idl.py | 10 +++++----- tests/test_parse.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rosbags/typesys/idl.py b/src/rosbags/typesys/idl.py index 821ec173..348e2e18 100644 --- a/src/rosbags/typesys/idl.py +++ b/src/rosbags/typesys/idl.py @@ -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 diff --git a/tests/test_parse.py b/tests/test_parse.py index 6eeee92c..f0fc7755 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -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: