diff --git a/src/Yaml/Parser.elm b/src/Yaml/Parser.elm index 49b06f7..20254d1 100644 --- a/src/Yaml/Parser.elm +++ b/src/Yaml/Parser.elm @@ -299,7 +299,9 @@ recordOrString indent indent_ = let withString string = P.oneOf - [ P.succeed (Ast.fromString string) + [ P.succeed (Ast.Record_ (Dict.singleton ":" Ast.Null_)) + |. P.end + , P.succeed (Ast.fromString string) |. P.end , recordProperty indent_ string , P.succeed (addRemaining string) @@ -312,24 +314,13 @@ recordOrString indent indent_ = ] addRemaining string remaining = - Ast.fromString <| U.postProcessString (removeComment string ++ remaining) - - removeComment string = - string - |> String.split "#" - |> List.head - |> Maybe.withDefault "" + Ast.String_ (string ++ remaining) in P.oneOf - [ quotedString indent_ - , P.succeed identity - |. P.chompIf (U.neither U.isColon U.isNewLine) - |. P.chompWhile (U.neither U.isColon U.isNewLine) - |> P.getChompedString - |> P.andThen withString + [ P.succeed Ast.Null_ + |. P.end , P.succeed identity - |. P.chompWhile U.isColon - |> P.getChompedString + |= U.characters (not << U.isColon) |> P.andThen withString ] diff --git a/src/Yaml/Parser/Util.elm b/src/Yaml/Parser/Util.elm index 6493e05..9563643 100644 --- a/src/Yaml/Parser/Util.elm +++ b/src/Yaml/Parser/Util.elm @@ -1,5 +1,6 @@ module Yaml.Parser.Util exposing - ( doubleQuotes + ( characters + , doubleQuotes , either , indented , isColon diff --git a/tests/TestParser.elm b/tests/TestParser.elm index 2cd2e5f..3373b3e 100644 --- a/tests/TestParser.elm +++ b/tests/TestParser.elm @@ -557,11 +557,10 @@ aaa: bbb""" """ aaa: { key1: value1, key1: value2 } """ - - -- TODO: This is temporarily removed because it is a valid test case that should pass - -- , Test.test "weird colon record" <| - -- \_ -> - -- expectValue "::" <| Ast.Record_ (Dict.singleton ":" Ast.Null_) + , Test.test "colon as key" <| + \_ -> + expectValue "::" <| + Ast.Record_ (Dict.singleton ":" Ast.Null_) ] @@ -573,12 +572,12 @@ expectRawAst subject expected = expectValue : String -> Ast.Value -> Expect.Expectation expectValue subject expected = - case ( Parser.fromString subject, expected ) of - ( Ok (Ast.Float_ got), Ast.Float_ want ) -> - expectCloseTo got want + case (Parser.fromString subject, expected) of + (Ok got, _) -> + Expect.equal got expected - ( got, _ ) -> - Expect.equal got (Ok expected) + (Err err, _) -> + Expect.fail err expectErr : String -> Expect.Expectation