diff --git a/dhall/src/Dhall/Parser/Expression.hs b/dhall/src/Dhall/Parser/Expression.hs index 93a5f830b..e49d89143 100644 --- a/dhall/src/Dhall/Parser/Expression.hs +++ b/dhall/src/Dhall/Parser/Expression.hs @@ -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 "#!" diff --git a/dhall/src/Dhall/Parser/Token.hs b/dhall/src/Dhall/Parser/Token.hs index ce3c63206..a070faa6a 100644 --- a/dhall/src/Dhall/Parser/Token.hs +++ b/dhall/src/Dhall/Parser/Token.hs @@ -8,6 +8,7 @@ module Dhall.Parser.Token ( validCodepoint, whitespace, lineComment, + lineCommentPrefix, blockComment, nonemptyWhitespace, bashEnvironmentVariable, @@ -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