Add support to _
in number literals
#185
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for
_
in number literals (int and float) (#163).The underscore must be between the digits, not at the beginning or end, like in Zig and Go.
Since Zig already has this feature, we don't have to ignore the
_
character and can leverage Zig'sstd.fmt.parseInt
/std.fmt.parseFloat
.On hex and binary literals, it works like this,
_
after theb
orx
is not valid, mimicking Zig's behavior, so0b_000
and0x_fff
are not valid:I've added some simple test case in
tests/001-basic-types.buzz
. Please let me know if I should add more extensive tests.This file is also compiling and running as expected:
I've also tried a modified version of the example on the website:
It prints the expected:
Please let me know if I'm missing something or should do something differently. I'd be happy to update this PR if requested.
Closes #163