-
Notifications
You must be signed in to change notification settings - Fork 45
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
Allow optional underscores in numberLiteral parsers #2
Comments
I agree, an option to skip underscores in numeric literals as supported by Java and F# would be a good addition. |
I've implemented an With this option the Note that this doesn't affect the Changing the defaults for |
I don't want to change the defaults of What you describe about stripping the underscores from the string is pretty much what I did in my own code: I implemented a parser to parse a sequence of digits with optional underscores in between, and returned a string of the digits without the underscores which I then forwarded to let digitsWithUnderscores = stringsSepBy (many1Satisfy isDigit)
(underscore >>% "")
|> notEmpty In the case of parsing floats, I used that digitsWithUnderscores parser in three different places in the float parser I wrote, and since it drops underscores, I could hand the whole thing off to I like the idea of different variants, but I can't come up with good names for them. The names should be short, preferably a single character appended to the existing names (e.g., I'm not thrilled about the idea of So I don't have any good ideas so far for function names, but if I come up with a bright idea over the next few days I'll mention it. |
Having a It would be great if you could maybe try out the new |
Well, I've finally been able to try this branch out, and here are my thoughts: First, there are some differences between various syntaxes out there that allow underscores between digits. For example, in Java and F#, Or perhaps that second flag isn't worth adding just yet, until we see whether anyone complains about
I'll poke around some more and offer further thoughts in a few days. |
There's a second language syntax besides TOML that disallows multiple underscores: Python just added underscores in numeric literals in Python 3.6, but the rules are "just one underscore between digits", like TOML. And it looks like TOML won't be changing. So there are now two broad "families" of language specs that allow underscores in numeric literals:
Since both styles have multiple examples that aren't likely to change, it looks like alternative 1 from my previous comment is the way to go. I propose another flag, maybe |
Now that Java and F# allow underscores in numeric literals, and some configuration file syntaxes like TOML do as well, it would be nice if the
numberLiteral
parser had an optional flag for allowing underscores between digits. As it is, if I want to write a TOML parser, I won't be able to leveragenumberLiteral
and I'll have to essentially reimplement it myself.The text was updated successfully, but these errors were encountered: