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 support for a trailing comment without a newline #2309

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion dhall/src/Dhall/Parser/Expression.hs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ parsers :: forall a. Parser a -> Parsers a
parsers embedded = Parsers{..}
where
completeExpression_ =
many shebang *> whitespace *> expression <* whitespace
many shebang
*> whitespace
*> expression
<* whitespace
<* optional lineCommentPrefix

shebang = do
_ <- text "#!"
Expand Down
16 changes: 10 additions & 6 deletions dhall/src/Dhall/Parser/Token.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Dhall.Parser.Token (
validCodepoint,
whitespace,
lineComment,
lineCommentPrefix,
blockComment,
nonemptyWhitespace,
bashEnvironmentVariable,
Expand Down Expand Up @@ -464,20 +465,23 @@ hexNumber = choice [ hexDigit, hexUpper, hexLower ]
where
predicate c = 'a' <= c && c <= 'f'

-- | Parse a Dhall's single-line comment, starting from `--` and until the
-- last character of the line /before/ the end-of-line character
lineComment :: Parser Text
lineComment = do
-- | Same as `lineComment` except that this doesn't parse the end-of-line
-- character
lineCommentPrefix :: Parser Text
lineCommentPrefix = do
_ <- text "--"

let predicate c = ('\x20' <= c && c <= '\x10FFFF') || c == '\t'

commentText <- Dhall.Parser.Combinators.takeWhile predicate

_ <- endOfLine

return ("--" <> commentText)

-- | Parse a Dhall's single-line comment, starting from `--` and until the
-- last character of the line /before/ the end-of-line character
lineComment :: Parser Text
lineComment = try (lineCommentPrefix <* endOfLine)

-- | Parsed text doesn't include opening braces
blockComment :: Parser Text
blockComment = do
Expand Down