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

Add Julia comment style #815

Merged
merged 2 commits into from
Sep 23, 2023
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
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Contributors

- roberto-red <roberto@redradix.com>

- Shun Sakai

Translators
-----------

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ CLI command and its behaviour. There are no guarantees of stability for the

### Added

- More file types are recognised:
- Julia (`.jl`) (#815)

### Changed

### Deprecated
Expand Down
21 changes: 19 additions & 2 deletions src/reuse/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# SPDX-FileCopyrightText: 2023 Redradix S.L. <info@redradix.com>
# SPDX-FileCopyrightText: 2023 Kevin Meagher
# SPDX-FileCopyrightText: 2023 Mathias Dannesbo <md@magenta.dk>
# SPDX-FileCopyrightText: 2023 Shun Sakai <sorairolake@protonmail.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -130,9 +131,13 @@ def parse_comment(cls, text: str) -> str:
:raises CommentParseError: if *text* could not be parsed.
"""
try:
return cls._parse_comment_single(text)
except CommentParseError:
# Attempt to parse multi-line comments first, in case of comment
# styles like Julia, where '#=' starts a multi-line comment, and '#'
# starts a single-line comment. If we parsed single-line comments
# first, '#=' would be a valid single-line comment.
return cls._parse_comment_multi(text)
except CommentParseError:
return cls._parse_comment_single(text)

@classmethod
def _parse_comment_single(cls, text: str) -> str:
Expand Down Expand Up @@ -386,6 +391,17 @@ class JinjaCommentStyle(CommentStyle):
MULTI_LINE = MultiLineSegments("{#", "", "#}")


class JuliaCommentStyle(CommentStyle):
"""Julia comment style."""

SHORTHAND = "julia"

SINGLE_LINE = "#"
INDENT_AFTER_SINGLE = " "
MULTI_LINE = MultiLineSegments("#=", "", "=#")
SHEBANGS = ["#!"]


class LispCommentStyle(CommentStyle):
"""Lisp comment style."""

Expand Down Expand Up @@ -580,6 +596,7 @@ class XQueryCommentStyle(CommentStyle):
".java": CCommentStyle,
".jinja": JinjaCommentStyle,
".jinja2": JinjaCommentStyle,
".jl": JuliaCommentStyle,
".js": CCommentStyle,
".json": UncommentableCommentStyle,
".jsp": AspxCommentStyle,
Expand Down
Loading