diff --git a/CHANGELOG.md b/CHANGELOG.md index 717851f..f7813b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Yaml/Parser/Util.elm b/src/Yaml/Parser/Util.elm index 76729eb..e7cdb25 100644 --- a/src/Yaml/Parser/Util.elm +++ b/src/Yaml/Parser/Util.elm @@ -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) ] diff --git a/tests/TestParser.elm b/tests/TestParser.elm index ba4cb00..c5b5b4a 100644 --- a/tests/TestParser.elm +++ b/tests/TestParser.elm @@ -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" <|