diff --git a/src/rosbags/typesys/msg.py b/src/rosbags/typesys/msg.py index 71e5f20a..5ee4df97 100644 --- a/src/rosbags/typesys/msg.py +++ b/src/rosbags/typesys/msg.py @@ -45,7 +45,9 @@ comment const_dcl = 'string' identifier r'=(?!={79}\n)' r'[^\n]+' + / type_spec identifier '=' float_literal / type_spec identifier '=' integer_literal + / type_spec identifier '=' boolean_literal field_dcl = type_spec identifier default_value? @@ -82,15 +84,17 @@ default_value = literal literal - = boolean_literal - / float_literal + = float_literal / integer_literal + / boolean_literal / string_literal / array_literal boolean_literal - = 'true' - / 'false' + = r'[tT][rR][uU][eE]' + / r'[fF][aA][lL][sS][eE]' + / '0' + / '1' integer_literal = hexadecimal_literal @@ -283,7 +287,7 @@ class VisitorMSG(Visitor): def visit_boolean_literal(self, children: Any) -> Any: """Process boolean literal.""" - return children[1] == 'TRUE' + return children.lower() in ['true', '1'] def visit_float_literal(self, children: Any) -> Any: """Process float literal.""" diff --git a/tests/test_parse.py b/tests/test_parse.py index edce9ab7..dc552975 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -17,7 +17,9 @@ from rosbags.typesys.types import FIELDDEFS MSG = """ # comment +bool b=true int32 global=42 +float32 f=1.33 string str= foo bar\t std_msgs/Header header @@ -195,7 +197,12 @@ def test_parse_msg() -> None: ret = get_types_from_msg(MSG, 'test_msgs/msg/Foo') assert 'test_msgs/msg/Foo' in ret consts, fields = ret['test_msgs/msg/Foo'] - assert consts == [('global', 'int32', 42), ('str', 'string', 'foo bar')] + assert consts == [ + ('b', 'bool', True), + ('global', 'int32', 42), + ('f', 'float32', 1.33), + ('str', 'string', 'foo bar'), + ] assert fields[0][0] == 'header' assert fields[0][1][1] == 'std_msgs/msg/Header' assert fields[1][0] == 'bool'