From dc3ac07f9a48632de7c17e862e407e9c29cd1900 Mon Sep 17 00:00:00 2001 From: z80 Date: Wed, 8 Nov 2023 10:30:21 -0500 Subject: [PATCH 1/3] support '_' separator in dec/oct/float numbers Allows 100_000 in place of 100000 --- vyper/ast/grammar.lark | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vyper/ast/grammar.lark b/vyper/ast/grammar.lark index ca9979b2a3..0db11545bc 100644 --- a/vyper/ast/grammar.lark +++ b/vyper/ast/grammar.lark @@ -298,11 +298,11 @@ _NEWLINE: ( /\r?\n[\t ]*/ | COMMENT )+ STRING: /b?("(?!"").*?(? Date: Wed, 8 Nov 2023 19:55:21 -0500 Subject: [PATCH 2/3] feat: add tests confirming underscore sep --- examples/wallet/wallet.vy | 2 +- tests/grammar/test_grammar.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/wallet/wallet.vy b/examples/wallet/wallet.vy index 5fd5229136..31996feafc 100644 --- a/examples/wallet/wallet.vy +++ b/examples/wallet/wallet.vy @@ -58,7 +58,7 @@ def approve(_seq: int128, to: address, _value: uint256, data: Bytes[4096], sigda # Increase the number of approved transactions by 1 self.seq += 1 # Use raw_call to send the transaction - return raw_call(to, data, max_outsize=4096, gas=3000000, value=_value) + return raw_call(to, data, max_outsize=4096, gas=3_000_000, value=_value) @external diff --git a/tests/grammar/test_grammar.py b/tests/grammar/test_grammar.py index aa0286cfa5..b828d28e43 100644 --- a/tests/grammar/test_grammar.py +++ b/tests/grammar/test_grammar.py @@ -22,6 +22,11 @@ def test_basic_grammar(): def one_two_three() -> uint256: return 123123123 """ + code_nums = """ + x: constant(uint256) = 100_000 + y: constant(uint256) = 0o100_000 + z: constant(decimal) = 1.100_000_007 + """ assert parse_vyper_source(code, dedent=True) assert parse_to_ast(textwrap.dedent(code)) @@ -29,6 +34,9 @@ def one_two_three() -> uint256: assert parse_vyper_source(code_func, dedent=True) assert parse_to_ast(textwrap.dedent(code_func)) + assert parse_vyper_source(code_nums, dedent=True) + assert parse_to_ast(textwrap.dedent(code_nums)) + def test_basic_grammar_empty(): code = """ From 48a8d4e3dedd44802129103612bb9886ad3c9ab8 Mon Sep 17 00:00:00 2001 From: z80 Date: Wed, 8 Nov 2023 20:02:45 -0500 Subject: [PATCH 3/3] fix: simplify unit tests --- tests/grammar/test_grammar.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/grammar/test_grammar.py b/tests/grammar/test_grammar.py index b828d28e43..40e01e7171 100644 --- a/tests/grammar/test_grammar.py +++ b/tests/grammar/test_grammar.py @@ -20,12 +20,7 @@ def test_basic_grammar(): code_func = """ @external def one_two_three() -> uint256: - return 123123123 - """ - code_nums = """ - x: constant(uint256) = 100_000 - y: constant(uint256) = 0o100_000 - z: constant(decimal) = 1.100_000_007 + return 123_123_123 """ assert parse_vyper_source(code, dedent=True) @@ -34,9 +29,6 @@ def one_two_three() -> uint256: assert parse_vyper_source(code_func, dedent=True) assert parse_to_ast(textwrap.dedent(code_func)) - assert parse_vyper_source(code_nums, dedent=True) - assert parse_to_ast(textwrap.dedent(code_nums)) - def test_basic_grammar_empty(): code = """