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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ 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. |
// 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
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.