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

Handling Booleans bug #376

Closed
haski007 opened this issue Oct 25, 2023 · 3 comments
Closed

Handling Booleans bug #376

haski007 opened this issue Oct 25, 2023 · 3 comments

Comments

@haski007
Copy link

In cases when we need to parse "true" or "false" into bool in examples you use :
Bool *bool `| @("true" | "false")
but this never handles right: in all cases "true" or "false" in our string - we will get true all the time

@alecthomas
Copy link
Owner

Correct. This is discussed in the README.

@haski007
Copy link
Author

My bad.
Here is issue with example of .toml parser:
false can't be captured
field is:

Bool     *bool    `| (@"true" | "false")`

for this file:

# This is a TOML document.
test = false
test2 = true

We will get:

&main.TOML{
  Pos: Position{Filename: "t.toml", Offset: 27, Line: 2, Column: 1},
  Entries: []*main.Entry{
    {
      Field: &main.Field{
        Key: "test",
        Value: &main.Value{
        },
      },
    },
    {
      Field: &main.Field{
        Key: "test2",
        Value: &main.Value{
          Bool: &true,
        },
      },
    },
  },
}

Or it works as planned ?

@alecthomas
Copy link
Owner

It's just a bug in the TOML example. If you could send a PR that would be welcome.

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

No branches or pull requests

2 participants