Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Added support for literal multi-line string at the end of file ([#42](https://github.com/MaybeJustJames/yaml/pull/42) by [miniBill](https://github.com/miniBill))

## [2.1.5]
### Fixed
Expand Down
36 changes: 23 additions & 13 deletions src/Yaml/Parser/Util.elm
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,33 @@ multilineStep indent lines =
multilineString lines_ =
String.join "\n" (List.reverse lines_)

conclusion line emptyLineCount indent_ =
if indent_ > indent then
P.Loop
((line ++ String.repeat emptyLineCount "\n")
:: lines
)

else
P.Done (multilineString (line :: lines))
conclusion line next =
case next of
Just ( emptyLineCount, indent_ ) ->
if indent_ > indent then
P.Loop
((line ++ String.repeat emptyLineCount "\n")
:: lines
)

else
P.Done (multilineString (line :: lines))

Nothing ->
P.Done (multilineString (line :: lines))
in
P.oneOf
[ P.succeed conclusion
|= characters (not << isNewLine)
|. P.chompIf isNewLine
|. spaces
|= emptyLines
|= P.getCol
|= P.oneOf
[ P.succeed (\e i -> Just ( e, i ))
|. P.chompIf isNewLine
|. spaces
|= emptyLines
|= P.getCol
, P.succeed Nothing
|. P.end
]
, P.succeed (P.Done <| multilineString lines)
]

Expand Down
11 changes: 11 additions & 0 deletions tests/TestParser.elm
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,17 @@ aaa: bbb"""
"""
aaa: { key1: value1, key1: value2 }
"""
, Test.test "multiline string at the end of file" <|
\_ ->
expectValue
"key: |\n indented string"
-- important: this test is checking the _lack_ of final \n
(Ast.Record_
(Dict.fromList
[ ( "key", Ast.String_ "indented string" )
]
)
)

-- TODO: This is temporarily removed because it is a valid test case that should pass
-- , Test.test "weird colon record" <|
Expand Down