Skip to content

Commit 0ac4130

Browse files
authored
[rosidl_adapter, rosidl_parser] Pass comments in ros interface constants to the .idl generated files (#630)
* [rosidl_adapter] Pass comments through for constants declarations. * [rosidl_paraser] Parse annotations for constants declarations. Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent e3f8156 commit 0ac4130

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

rosidl_adapter/rosidl_adapter/resource/struct.idl.em

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ else:
4040
@[if msg.constants]@
4141
module @(msg.msg_name)_Constants {
4242
@[ for constant in msg.constants]@
43+
@[ if constant.annotations.get('comment', [])]@
44+
@@verbatim (language="comment", text=
45+
@[ for i, line in enumerate(constant.annotations['comment'])]@
46+
@(string_to_idl_string_literal(line))@
47+
@[ if i < len(constant.annotations.get('comment')) - 1]@
48+
"\n"@
49+
@[ end if]@
50+
@[ end for]@
51+
)
52+
@[ end if]@
4353
const @(get_idl_type(constant.type)) @(constant.name) = @(to_idl_literal(get_idl_type(constant.type), constant.value));
4454
@[ end for]@
4555
};

rosidl_parser/rosidl_parser/grammar.lark

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ scoped_name.1: IDENTIFIER
113113
// separate rule to identify the separator
114114
scoped_name_separator: "::"
115115

116-
// (5)
117-
const_dcl: "const" const_type IDENTIFIER "=" const_expr
116+
// (5), 7.4.15.2
117+
const_dcl: annotation_appl* "const" const_type IDENTIFIER "=" const_expr
118118

119119
// (6)
120120
const_type: integer_type

rosidl_parser/rosidl_parser/parser.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,18 @@ def extract_content_from_ast(tree):
103103
constants = {}
104104
const_dcls = tree.find_data('const_dcl')
105105
for const_dcl in const_dcls:
106+
annotations = get_annotations(const_dcl)
106107
const_type = next(const_dcl.find_data('const_type'))
107-
const_expr = next(const_dcl.find_data('const_expr'))
108108
module_identifiers = get_module_identifier_values(tree, const_dcl)
109109
module_comments = constants.setdefault(
110110
module_identifiers[-1], [])
111-
value = get_const_expr_value(const_expr)
112-
module_comments.append(Constant(
113-
get_first_identifier_value(const_dcl),
111+
value = get_const_expr_value(const_dcl.children[-1])
112+
constant = Constant(
113+
get_child_identifier_value(const_dcl),
114114
get_abstract_type_from_const_expr(const_type, value),
115-
value))
115+
value)
116+
constant.annotations = annotations
117+
module_comments.append(constant)
116118

117119
typedefs = {}
118120
typedef_dcls = tree.find_data('typedef_dcl')

0 commit comments

Comments
 (0)