Skip to content

Commit

Permalink
[rosidl_adapter, rosidl_parser] Pass comments in ros interface consta…
Browse files Browse the repository at this point in the history
…nts 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]>
  • Loading branch information
ivanpauno authored Nov 16, 2021
1 parent e3f8156 commit 0ac4130
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
10 changes: 10 additions & 0 deletions rosidl_adapter/rosidl_adapter/resource/struct.idl.em
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ else:
@[if msg.constants]@
module @(msg.msg_name)_Constants {
@[ for constant in msg.constants]@
@[ if constant.annotations.get('comment', [])]@
@@verbatim (language="comment", text=
@[ for i, line in enumerate(constant.annotations['comment'])]@
@(string_to_idl_string_literal(line))@
@[ if i < len(constant.annotations.get('comment')) - 1]@
"\n"@
@[ end if]@
@[ end for]@
)
@[ end if]@
const @(get_idl_type(constant.type)) @(constant.name) = @(to_idl_literal(get_idl_type(constant.type), constant.value));
@[ end for]@
};
Expand Down
4 changes: 2 additions & 2 deletions rosidl_parser/rosidl_parser/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ scoped_name.1: IDENTIFIER
// separate rule to identify the separator
scoped_name_separator: "::"

// (5)
const_dcl: "const" const_type IDENTIFIER "=" const_expr
// (5), 7.4.15.2
const_dcl: annotation_appl* "const" const_type IDENTIFIER "=" const_expr

// (6)
const_type: integer_type
Expand Down
12 changes: 7 additions & 5 deletions rosidl_parser/rosidl_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ def extract_content_from_ast(tree):
constants = {}
const_dcls = tree.find_data('const_dcl')
for const_dcl in const_dcls:
annotations = get_annotations(const_dcl)
const_type = next(const_dcl.find_data('const_type'))
const_expr = next(const_dcl.find_data('const_expr'))
module_identifiers = get_module_identifier_values(tree, const_dcl)
module_comments = constants.setdefault(
module_identifiers[-1], [])
value = get_const_expr_value(const_expr)
module_comments.append(Constant(
get_first_identifier_value(const_dcl),
value = get_const_expr_value(const_dcl.children[-1])
constant = Constant(
get_child_identifier_value(const_dcl),
get_abstract_type_from_const_expr(const_type, value),
value))
value)
constant.annotations = annotations
module_comments.append(constant)

typedefs = {}
typedef_dcls = tree.find_data('typedef_dcl')
Expand Down

0 comments on commit 0ac4130

Please sign in to comment.