-
Notifications
You must be signed in to change notification settings - Fork 11
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
val eol = Parser.commentToEOL.void | Parser.toEOL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be spaceComment *> termination. |
||
val parsePack = Padding | ||
.parser( | ||
(P.string("package") | ||
.soft ~ spaces) *> PackageName.parser <* Parser.toEOL | ||
.soft ~ spaces) *> PackageName.parser <* eol, | ||
spaceComment | ||
) | ||
.map(_.padded) | ||
val pname: P0[PackageName] = | ||
|
@@ -204,12 +207,13 @@ object Package { | |
case Some(p) => parsePack.?.map(_.getOrElse(p)) | ||
} | ||
|
||
val im = Padding.parser(Import.parser <* Parser.toEOL).map(_.padded).rep0 | ||
val im = Padding.parser(Import.parser <* eol, spaceComment).map(_.padded).rep0 | ||
val ex = Padding | ||
.parser( | ||
(P.string("export") | ||
.soft ~ spaces) *> ExportedName.parser.itemsMaybeParens | ||
.map(_._2) <* Parser.toEOL | ||
.map(_._2) <* eol, | ||
spaceComment | ||
) | ||
.map(_.padded) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -448,7 +448,11 @@ object Parser { | |
(P.char('(') ~ ws) *> pa <* (ws ~ P.char(')')) | ||
|
||
val newline: P[Unit] = P.char('\n') | ||
val toEOL: P0[Unit] = maybeSpace *> newline.orElse(P.end) | ||
// 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 commentThe 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. |
||
val toEOL: P0[Unit] = maybeSpace *> termination | ||
val toEOL1: P[Unit] = maybeSpace.with1 *> newline | ||
|
||
def optionParse[A](pa: P0[A], str: String): Option[A] = | ||
|
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.