Skip to content
Closed
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
9 changes: 6 additions & 3 deletions ament_copyright/ament_copyright/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def search_copyright_information(content):
year = '\d{4}'
year_range = '%s-%s' % (year, year)
year_or_year_range = '(?:%s|%s)' % (year, year_range)
pattern = '^[^\n\r]?\s*Copyright(?:\s+\(c\))?\s+(%s(?:,\s*%s)*),?\s+([^\n\r]+)$' % \
pattern = '^[^\n\r]?[\s\w]*Copyright(?:\s+\(c\))?\s+(%s(?:,\s*%s)*),?\s+([^\n\r]+)$' % \
(year_or_year_range, year_or_year_range)
regex = re.compile(pattern, re.DOTALL | re.MULTILINE)

Expand All @@ -198,7 +198,8 @@ def scan_past_coding_and_shebang_lines(content):
while (
is_comment_line(content, index) and
(is_coding_line(content, index) or
is_shebang_line(content, index))
is_shebang_line(content, index) or
is_empty_line(content, index))
):
index = get_index_of_next_line(content, index)
return index
Expand Down Expand Up @@ -239,7 +240,7 @@ def is_shebang_line(content, index):

def get_comment_block(content, index):
# regex for matching the beginning of the first comment
pattern = '^(#|//)'
pattern = '^(#|//|/\*\*|/\*)'
regex = re.compile(pattern, re.MULTILINE)

match = regex.search(content, index)
Expand All @@ -248,6 +249,8 @@ def get_comment_block(content, index):
comment_token = match.group(1)
start_index = match.start(1)

if comment_token in ['/*', '/**']:
comment_token = ' *'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is rather unfortunate -- does anyone see a better way?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the leading space should not be required. This should be valid:

/**
* text
*/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok -- I can add that functionality.

/**
text
*/

is that also acceptable?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking something like this:

if comment_token in ['/*', '/**']:
    comment_token = '*'
"""
more code
"""
lines = [line[line.index(comment_token) + 1:] for line in lines]

That works for the existing copyright cases, but not for the new ones.

end_index = start_index
while True:
end_index = get_index_of_next_line(content, end_index)
Expand Down