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

Fix: インクルードガードの前の空行やコメント行を許容するようにしました #410

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions onlinejudge_verify/languages/cplusplus_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ def update(self, path: pathlib.Path) -> None:
if re.match(rb'\s*#\s*pragma\s+once\s*', line): # #pragma once は comment 扱いで消されてしまう
logger.debug('%s: line %s: #pragma once', str(path), i + 1)
if non_guard_line_found:
# 先頭以外で #pragma once されてた場合は諦める
raise BundleErrorAt(path, i + 1, "#pragma once found in a non-first line")
# #pragma once の前にコードが書かれていた場合に落とす
raise BundleErrorAt(path, i + 1, "found codes before #pragma once")
if include_guard_macro is not None:
raise BundleErrorAt(path, i + 1, "#pragma once found in an include guard with #ifndef")
if path.resolve() in self.pragma_once:
Expand Down Expand Up @@ -346,7 +346,11 @@ def update(self, path: pathlib.Path) -> None:
continue

if uncommented_line:
non_guard_line_found = True
if not non_guard_line_found and uncommented_line == b"\n":
# include guard の前がコメントまたは空行の場合は non_guard_line_found を True にしない
pass
else:
non_guard_line_found = True
Comment on lines 348 to +353
Copy link
Contributor

Choose a reason for hiding this comment

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

if uncommented_line and not re.match(rb"^\s*$", uncommented_line): とすると

      // インデント付コメント
#pragma once

みたいなのも除外できるのでベターなのではないかと思います。

if include_guard_macro is not None and not include_guard_define_found:
# 先頭に #ifndef が見付かっても #define が続かないならそれは include guard ではない
include_guard_macro = None
Expand Down