Closed mcbattirola closed 9 months ago
Thanks @giann, I've fixed the trailing _
and squashed the commits.
I've also implemented _
in binary and hex literals, as it felt wrong to allow _
in base 10 literals and not on hex/bin. Please let me know if you'd prefer those to be in a separate PR.
Thanks!
This PR adds support for
_
in number literals (int and float) (https://github.com/buzz-language/buzz/issues/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 https://github.com/buzz-language/buzz/issues/163