Add string constant support to msg parser
This commit is contained in:
parent
203131b777
commit
1333cf1168
@ -44,7 +44,8 @@ comment
|
|||||||
= r'#[^\n]*'
|
= r'#[^\n]*'
|
||||||
|
|
||||||
const_dcl
|
const_dcl
|
||||||
= type_spec identifier '=' integer_literal
|
= 'string' identifier '=' r'[^\n]+'
|
||||||
|
/ type_spec identifier '=' integer_literal
|
||||||
|
|
||||||
field_dcl
|
field_dcl
|
||||||
= type_spec identifier
|
= type_spec identifier
|
||||||
@ -172,7 +173,12 @@ class VisitorMSG(Visitor):
|
|||||||
|
|
||||||
def visit_const_dcl(self, children: Any) -> Any:
|
def visit_const_dcl(self, children: Any) -> Any:
|
||||||
"""Process const declaration, suppress output."""
|
"""Process const declaration, suppress output."""
|
||||||
return Nodetype.CONST, (children[0][1], children[1][1], children[3])
|
typ = children[0][1]
|
||||||
|
if typ == 'string':
|
||||||
|
value = children[3].strip()
|
||||||
|
else:
|
||||||
|
value = children[3]
|
||||||
|
return Nodetype.CONST, (typ, children[1][1], value)
|
||||||
|
|
||||||
def visit_specification(self, children: Any) -> Typesdict:
|
def visit_specification(self, children: Any) -> Typesdict:
|
||||||
"""Process start symbol."""
|
"""Process start symbol."""
|
||||||
|
|||||||
@ -18,6 +18,7 @@ MSG = """
|
|||||||
# comment
|
# comment
|
||||||
|
|
||||||
int32 global=42
|
int32 global=42
|
||||||
|
string str= foo bar\t
|
||||||
|
|
||||||
std_msgs/Header header
|
std_msgs/Header header
|
||||||
std_msgs/msg/Bool bool
|
std_msgs/msg/Bool bool
|
||||||
@ -115,7 +116,7 @@ def test_parse_msg():
|
|||||||
ret = get_types_from_msg(MSG, 'test_msgs/msg/Foo')
|
ret = get_types_from_msg(MSG, 'test_msgs/msg/Foo')
|
||||||
assert 'test_msgs/msg/Foo' in ret
|
assert 'test_msgs/msg/Foo' in ret
|
||||||
consts, fields = ret['test_msgs/msg/Foo']
|
consts, fields = ret['test_msgs/msg/Foo']
|
||||||
assert consts == [('global', 'int32', 42)]
|
assert consts == [('global', 'int32', 42), ('str', 'string', 'foo bar')]
|
||||||
assert fields[0][0] == 'header'
|
assert fields[0][0] == 'header'
|
||||||
assert fields[0][1][1] == 'std_msgs/msg/Header'
|
assert fields[0][1][1] == 'std_msgs/msg/Header'
|
||||||
assert fields[1][0] == 'bool'
|
assert fields[1][0] == 'bool'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user