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

Support comments in headers #1168

Merged
merged 2 commits into from Mar 16, 2024
Merged

Support comments in headers #1168

merged 2 commits into from Mar 16, 2024

Conversation

johnynek
Copy link
Owner

this allows comments in headers, but discards them: it does not retain them in the parsed AST.

This is convenient when we are really strict about imports and exports.

@codecov-commenter
Copy link

codecov-commenter commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.60%. Comparing base (04a0e87) to head (6e9219a).
Report is 9 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1168      +/-   ##
==========================================
+ Coverage   91.32%   91.60%   +0.28%     
==========================================
  Files          96       96              
  Lines       11846    12010     +164     
  Branches     2675     2778     +103     
==========================================
+ Hits        10818    11002     +184     
+ Misses       1028     1008      -20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// The comment excluding the leading # up to the EOL or EOF
val termination: P0[Unit] = newline.orElse(P.end)
val commentToEOL: P[String] =
P.char('#') *> P.charsWhile0(_ != '\n') <* termination
Copy link
Owner Author

Choose a reason for hiding this comment

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

This only parses a single comment to EOL. We could have several. This isn't a problem for the code as it is now due to the way it's used but it's dangerous to leave it around since it isn't clear if it parses one or many lines.

Also it doesn't allow space then a comment which makes it rarely useful.

// TODO: support comments before the Statement
val spaceComment: P0[Unit] =
(Parser.spaces | (P.char('#') <* P.charsWhile0(_ != '\n'))).?.void
val eol = Parser.commentToEOL.void | Parser.toEOL
Copy link
Owner Author

Choose a reason for hiding this comment

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

This should be spaceComment *> termination.

Copy link
Owner Author

@johnynek johnynek left a comment

Choose a reason for hiding this comment

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

Should add tests of header parsing.

@@ -191,11 +191,14 @@ object Package {
}

def headerParser(defaultPack: Option[PackageName]): P0[Header] = {
// TODO: support comments before the Statement
val spaceComment: P0[Unit] =
(Parser.spaces | (P.char('#') <* P.charsWhile0(_ != '\n'))).?.void
Copy link
Owner Author

Choose a reason for hiding this comment

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

Parser should be moved to a private val above.

@johnynek johnynek merged commit 4689044 into main Mar 16, 2024
9 checks passed
@johnynek johnynek deleted the oscar/20240315_comment_header branch March 16, 2024 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants