Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rosidl_adapter] Ignore multiple # characters and dedent comments #594

Merged
merged 3 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions rosidl_adapter/rosidl_adapter/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import re
import sys
import textwrap

PACKAGE_NAME_MESSAGE_TYPE_SEPARATOR = '/'
COMMENT_DELIMITER = '#'
Expand Down Expand Up @@ -472,15 +473,15 @@ def parse_message_string(pkg_name, msg_name, message_string):

# file-level comment line
if index == 0 and not file_level_ended:
message_comments.append(line[len(COMMENT_DELIMITER):])
message_comments.append(line.lstrip(COMMENT_DELIMITER))
continue

file_level_ended = True

# comment
comment = None
if index >= 0:
comment = line[index + len(COMMENT_DELIMITER):]
comment = line[index:].lstrip(COMMENT_DELIMITER)
line = line[:index]

if comment is not None:
Expand Down Expand Up @@ -580,6 +581,9 @@ def process_comments(instance):
length -= 1
continue
i += 1
if lines:
text = '\n'.join(lines)
instance.annotations['comment'] = textwrap.dedent(text).split('\n')


def parse_value_string(type_, value_string):
Expand Down
6 changes: 3 additions & 3 deletions rosidl_adapter/test/data/action/Test.expected.idl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module test_msgs {
module action {
@verbatim (language="comment", text=
" goal definition")
"goal definition")
struct Test_Goal {
boolean bool_value;

Expand Down Expand Up @@ -38,12 +38,12 @@ module test_msgs {
};
struct Test_Result {
@verbatim (language="comment", text=
" result definition")
"result definition")
boolean ok;
};
struct Test_Feedback {
@verbatim (language="comment", text=
" feedback definition")
"feedback definition")
sequence<int32> sequence;
};
};
Expand Down
20 changes: 10 additions & 10 deletions rosidl_adapter/test/test_extract_message_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def test_extract_message_comments():
assert len(msg_spec.annotations) == 1
assert 'comment' in msg_spec.annotations
assert len(msg_spec.annotations['comment']) == 3
assert msg_spec.annotations['comment'][0] == ' comment 1'
assert msg_spec.annotations['comment'][0] == 'comment 1'
assert msg_spec.annotations['comment'][1] == ''
assert msg_spec.annotations['comment'][2] == ' comment 2'
assert msg_spec.annotations['comment'][2] == 'comment 2'

assert len(msg_spec.fields) == 1
assert len(msg_spec.fields[0].annotations) == 1
Expand All @@ -35,28 +35,28 @@ def test_extract_message_comments():
assert len(msg_spec.annotations) == 1
assert 'comment' in msg_spec.annotations
assert len(msg_spec.annotations['comment']) == 1
assert msg_spec.annotations['comment'] == [' comment 1']
assert msg_spec.annotations['comment'] == ['comment 1']

assert len(msg_spec.fields) == 1
assert len(msg_spec.fields[0].annotations) == 1
assert 'comment' in msg_spec.fields[0].annotations
assert len(msg_spec.fields[0].annotations['comment']) == 1
assert msg_spec.fields[0].annotations['comment'][0] == ' comment 2'
assert msg_spec.fields[0].annotations['comment'][0] == 'comment 2'

# file-level comment, trailing and indented field-level comment
msg_spec = parse_message_string(
'pkg', 'Foo', '# comment 1\nbool value # comment 2\n # comment 3\nbool value2')
assert len(msg_spec.annotations) == 1
assert 'comment' in msg_spec.annotations
assert len(msg_spec.annotations['comment']) == 1
assert msg_spec.annotations['comment'] == [' comment 1']
assert msg_spec.annotations['comment'] == ['comment 1']

assert len(msg_spec.fields) == 2
assert len(msg_spec.fields[0].annotations) == 1
assert 'comment' in msg_spec.fields[0].annotations
assert len(msg_spec.fields[0].annotations['comment']) == 2
assert msg_spec.fields[0].annotations['comment'][0] == ' comment 2'
assert msg_spec.fields[0].annotations['comment'][1] == ' comment 3'
assert msg_spec.fields[0].annotations['comment'][0] == 'comment 2'
assert msg_spec.fields[0].annotations['comment'][1] == 'comment 3'

assert len(msg_spec.fields[1].annotations) == 1
assert 'comment' in msg_spec.fields[1].annotations
Expand All @@ -73,12 +73,12 @@ def test_extract_message_comments():
assert len(msg_spec.fields[0].annotations) == 1
assert 'comment' in msg_spec.fields[0].annotations
assert len(msg_spec.fields[0].annotations['comment']) == 1
assert msg_spec.fields[0].annotations['comment'][0] == ' comment 2'
assert msg_spec.fields[0].annotations['comment'][0] == 'comment 2'

assert len(msg_spec.fields[1].annotations) == 1
assert 'comment' in msg_spec.fields[1].annotations
assert len(msg_spec.fields[1].annotations['comment']) == 1
assert msg_spec.fields[1].annotations['comment'][0] == ' comment 3'
assert msg_spec.fields[1].annotations['comment'][0] == 'comment 3'

# field-level comment with a unit
msg_spec = parse_message_string(
Expand All @@ -88,7 +88,7 @@ def test_extract_message_comments():
assert len(msg_spec.fields[0].annotations) == 2
assert 'comment' in msg_spec.fields[0].annotations
assert len(msg_spec.fields[0].annotations['comment']) == 1
assert msg_spec.fields[0].annotations['comment'][0] == ' comment'
assert msg_spec.fields[0].annotations['comment'][0] == 'comment'

assert 'unit' in msg_spec.fields[0].annotations
assert msg_spec.fields[0].annotations['unit'] == 'unit'