Skip to content

Commit

Permalink
no parens around item(...) or item[...]
Browse files Browse the repository at this point in the history
  • Loading branch information
EasyArray committed Mar 19, 2022
1 parent b5ea7d7 commit 6b13aa5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions phosphorus/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ def mylog(s): log(s,"Span.update")
self[n + 1].string == Token.delims[self[n - 1].string]
)
onlyItem = len(self) == 2 and n == 0 # check if result of substitution is the only thing in self
# if len == 1, then there is only one token in item, so parens aren't needed
if not (outerParens or onlyItem or len(item) == 1):
singleItem = ( #check if we have one item or item(...) or item[...]
len(item) == 1 or
(len(item) == 2 and isinstance(item[1], Span))
)
if not (outerParens or onlyItem or singleItem):
# add surrounding parens if needed
item = Span.parse(spaces + "(" + s + ")")
DEBUGGING and mylog(f"Parsed: |{item}|") #Costly
Expand All @@ -147,8 +150,12 @@ def mylog(s): log(s,"Span.update")
self[n + 2].string == Token.delims[self[n - 1].string]
)
onlyItem = len(self) == 2 and n == 0 # check if lambda call is the only thing in self
# if len == 1, then there is only one token in item, so parens aren't needed
if not (outerParens or onlyItem or len(Span.parse(item)) == 1):
sp = Span.parse(item)
singleItem = ( #check if we have one item or item(...) or item[...]
len(sp) == 1 or
(len(sp) == 2 and isinstance(sp[1], Span))
)
if not (outerParens or onlyItem or singleItem):
# add surrounding parens if needed
item = "(" + item + ")"
next(enum) #skip the arg
Expand Down

0 comments on commit 6b13aa5

Please sign in to comment.