Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with : #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix bug with : #40

wants to merge 2 commits into from

Conversation

ABBThales
Copy link

@ABBThales ABBThales commented Dec 5, 2024

This pull request addresses the issue where the YAML parser does not correctly handle cases where a colon (:) is used as a key. The change ensures that the parser produces an Ast.Record_ with the key : and value Ast.Null_ when encountering such cases. This fix is related to the issue #10 (link to the issue).

Comment on lines +302 to +303
[ P.succeed (Ast.Record_ (Dict.singleton ":" Ast.Null_))
|. P.end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right. Where is the parser consuming a ":" character?

Comment on lines -315 to +317
Ast.fromString <| U.postProcessString (removeComment string ++ remaining)

removeComment string =
string
|> String.split "#"
|> List.head
|> Maybe.withDefault ""
Ast.String_ (string ++ remaining)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated? Why is removeComment being removed?

, P.succeed identity
|. P.chompWhile U.isColon
|> P.getChompedString
|= U.characters (not << U.isColon)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see what you're going for here but Yaml.Parser.Util doesn't export the characters function. Consider exporting that function for use here

Comment on lines -560 to +563

-- 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_)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

Comment on lines -576 to +580
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. Comparing floating point values for equality should be done more carefully. Also, such a change should be done in another PR since it is unrelated to colon keys. Once again, I think I see where you're going and, in principle, I would accept this function being cleaned up a bit but please do this in a separate RP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants