Skip to content

Commit 746541e

Browse files
authored
Merge pull request #49 from benber86/fix/neg_sign
Fix spacing error with unitary operator spacing before signed number
2 parents 37c55cd + e4f1757 commit 746541e

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/mamushi/formatting/whitespace.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def whitespace(leaf: Leaf) -> str:
2424
DOUBLESPACE: Final = " "
2525
t = leaf.type
2626
p = leaf.parent
27-
v = leaf.value
2827

2928
if t in ALWAYS_NO_SPACE:
3029
return NO
@@ -123,7 +122,7 @@ def whitespace(leaf: Leaf) -> str:
123122
# decorators
124123
return NO
125124

126-
elif v.isnumeric() and p.type in tokens.UNARY:
125+
elif t in tokens.NUMBERS and p.type in tokens.UNARY:
127126
# no space for signed numbers
128127
return NO
129128

src/mamushi/parsing/tokens.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
NAME = "NAME"
1010
RBRACE = "RBRACE"
1111
LBRACE = "LBRACE"
12+
FLOAT_NUMBER = "FLOAT_NUMBER"
1213
DEC_NUMBER = "DEC_NUMBER"
1314
HEX_NUMBER = "HEX_NUMBER"
1415
BIN_NUMBER = "BIN_NUMBER"
1516
OCT_NUMBER = "OCT_NUMBER"
16-
NUMBERS = {DEC_NUMBER, HEX_NUMBER, BIN_NUMBER, OCT_NUMBER}
17+
NUMBERS = {DEC_NUMBER, FLOAT_NUMBER, HEX_NUMBER, BIN_NUMBER, OCT_NUMBER}
1718
AT = "AT"
1819
BRACKET_MAP = {LPAR: RPAR, LSQB: RSQB, LBRACE: RBRACE}
1920
OPENING_BRACKETS = set(BRACKET_MAP.keys())
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@external
2+
def foo(x: int256) -> int256:
3+
if x <= - 41_446_531_673_892_822_313:
4+
return empty(int256)
5+
a: int256 = x + ( - 123)
6+
b: int256 = 100 * - 2
7+
return a * - b * -convert(1e-8, int256)
8+
# output
9+
@external
10+
def foo(x: int256) -> int256:
11+
if x <= -41_446_531_673_892_822_313:
12+
return empty(int256)
13+
a: int256 = x + (-123)
14+
b: int256 = 100 * -2
15+
return a * -b * -convert(1e-8, int256)

0 commit comments

Comments
 (0)