Skip to content

Commit

Permalink
Merge pull request #49 from benber86/fix/neg_sign
Browse files Browse the repository at this point in the history
Fix spacing error with unitary operator spacing before signed number
  • Loading branch information
benber86 authored Dec 27, 2024
2 parents 37c55cd + e4f1757 commit 746541e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/mamushi/formatting/whitespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def whitespace(leaf: Leaf) -> str:
DOUBLESPACE: Final = " "
t = leaf.type
p = leaf.parent
v = leaf.value

if t in ALWAYS_NO_SPACE:
return NO
Expand Down Expand Up @@ -123,7 +122,7 @@ def whitespace(leaf: Leaf) -> str:
# decorators
return NO

elif v.isnumeric() and p.type in tokens.UNARY:
elif t in tokens.NUMBERS and p.type in tokens.UNARY:
# no space for signed numbers
return NO

Expand Down
3 changes: 2 additions & 1 deletion src/mamushi/parsing/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
NAME = "NAME"
RBRACE = "RBRACE"
LBRACE = "LBRACE"
FLOAT_NUMBER = "FLOAT_NUMBER"
DEC_NUMBER = "DEC_NUMBER"
HEX_NUMBER = "HEX_NUMBER"
BIN_NUMBER = "BIN_NUMBER"
OCT_NUMBER = "OCT_NUMBER"
NUMBERS = {DEC_NUMBER, HEX_NUMBER, BIN_NUMBER, OCT_NUMBER}
NUMBERS = {DEC_NUMBER, FLOAT_NUMBER, HEX_NUMBER, BIN_NUMBER, OCT_NUMBER}
AT = "AT"
BRACKET_MAP = {LPAR: RPAR, LSQB: RSQB, LBRACE: RBRACE}
OPENING_BRACKETS = set(BRACKET_MAP.keys())
Expand Down
15 changes: 15 additions & 0 deletions tests/data/assignments/operator_negative_numbers_spacing.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@external
def foo(x: int256) -> int256:
if x <= - 41_446_531_673_892_822_313:
return empty(int256)
a: int256 = x + ( - 123)
b: int256 = 100 * - 2
return a * - b * -convert(1e-8, int256)
# output
@external
def foo(x: int256) -> int256:
if x <= -41_446_531_673_892_822_313:
return empty(int256)
a: int256 = x + (-123)
b: int256 = 100 * -2
return a * -b * -convert(1e-8, int256)

0 comments on commit 746541e

Please sign in to comment.