Skip to content
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