Skip to content

Commit

Permalink
Fix bug with :
Browse files Browse the repository at this point in the history
  • Loading branch information
ABBThales committed Dec 5, 2024
1 parent 9fd5622 commit 4c6aec8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
23 changes: 7 additions & 16 deletions src/Yaml/Parser.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
]

Expand Down
19 changes: 9 additions & 10 deletions tests/TestParser.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
]


Expand All @@ -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
Expand Down

0 comments on commit 4c6aec8

Please sign in to comment.