Skip to content

Commit 9f0dd67

Browse files
Add support for a trailing comment without a newline (#2309)
… as standardized in dhall-lang/dhall-lang#1226 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 8eead56 commit 9f0dd67

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

dhall/src/Dhall/Parser/Expression.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ parsers :: forall a. Parser a -> Parsers a
241241
parsers embedded = Parsers{..}
242242
where
243243
completeExpression_ =
244-
many shebang *> whitespace *> expression <* whitespace
244+
many shebang
245+
*> whitespace
246+
*> expression
247+
<* whitespace
248+
<* optional lineCommentPrefix
245249

246250
shebang = do
247251
_ <- text "#!"

dhall/src/Dhall/Parser/Token.hs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Dhall.Parser.Token (
88
validCodepoint,
99
whitespace,
1010
lineComment,
11+
lineCommentPrefix,
1112
blockComment,
1213
nonemptyWhitespace,
1314
bashEnvironmentVariable,
@@ -464,20 +465,23 @@ hexNumber = choice [ hexDigit, hexUpper, hexLower ]
464465
where
465466
predicate c = 'a' <= c && c <= 'f'
466467

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

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

475476
commentText <- Dhall.Parser.Combinators.takeWhile predicate
476477

477-
_ <- endOfLine
478-
479478
return ("--" <> commentText)
480479

480+
-- | Parse a Dhall's single-line comment, starting from `--` and until the
481+
-- last character of the line /before/ the end-of-line character
482+
lineComment :: Parser Text
483+
lineComment = try (lineCommentPrefix <* endOfLine)
484+
481485
-- | Parsed text doesn't include opening braces
482486
blockComment :: Parser Text
483487
blockComment = do

0 commit comments

Comments
 (0)