Skip to content

Commit

Permalink
Further fix number parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Nov 26, 2023
1 parent aa6c431 commit 1721293
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
17 changes: 7 additions & 10 deletions coconut/compiler/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,21 +801,18 @@ class Grammar(object):
| integer + Optional(dot + Optional(integer))
)
sci_e = combine((caseless_literal("e") | fixto(Literal("\u23e8"), "e")) + Optional(plus | neg_minus))
numitem = combine(
# don't match 0_, 0b_, 0o_, or 0x_
regex_item(r"(?!0([0-9_]|[box][0-9_]))").suppress()
+ basenum + Optional(sci_e + integer)
)
numitem = combine(basenum + Optional(sci_e + integer))
imag_num = combine(numitem + imag_j)
maybe_imag_num = combine(numitem + Optional(imag_j))
bin_num = combine(caseless_literal("0b") + Optional(underscore.suppress()) + binint)
oct_num = combine(caseless_literal("0o") + Optional(underscore.suppress()) + octint)
hex_num = combine(caseless_literal("0x") + Optional(underscore.suppress()) + hexint)
number = any_of(
maybe_imag_num,
hex_num,
bin_num,
oct_num,
number = (
hex_num
| bin_num
| oct_num
# must come last to avoid matching "0" in "0b"
| maybe_imag_num
)
# make sure that this gets addspaced not condensed so it doesn't produce a SyntaxError
num_atom = addspace(number + Optional(condense(dot + unsafe_name)))
Expand Down
2 changes: 1 addition & 1 deletion coconut/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
VERSION = "3.0.4"
VERSION_NAME = None
# False for release, int >= 1 for develop
DEVELOP = 2
DEVELOP = 3
ALPHA = True # for pre releases rather than post releases

assert DEVELOP is False or DEVELOP >= 1, "DEVELOP must be False or an int >= 1"
Expand Down
2 changes: 2 additions & 0 deletions coconut/tests/src/cocotest/agnostic/primary_2.coco
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ def primary_test_2() -> bool:
assert 0x0 == 0 == 0b0
x = 10
assert 0x == 0 == 0 x
assert 0xff == 255 == 0x100-1
assert 11259375 == 0xabcdef

with process_map.multiple_sequential_calls(): # type: ignore
assert map((+), range(3), range(4)$[:-1], strict=True) |> list == [0, 2, 4] == process_map((+), range(3), range(4)$[:-1], strict=True) |> list # type: ignore
Expand Down

0 comments on commit 1721293

Please sign in to comment.