Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy C committed Jun 26, 2024
1 parent 2b67988 commit 5d2e6a6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions osh/word_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,26 +278,27 @@ def _ReadSliceVarOp(self):
cur_id = self.a_parser.CurrentId()
#log('after begin %s', Id_str(cur_id))

# e.g. Id.Arith_Colon for the second colon, e.g. ${a:42:}
if cur_id == Id.Arith_Colon: # Id.Arith_Colon is a pun for Id.VOp2_Colon
if cur_id == Id.Arith_RBrace: # ${a:1} or ${@:1}
no_length = None # type: Optional[arith_expr_t] # No length specified
return suffix_op.Slice(begin, no_length)

elif cur_id == Id.Arith_Colon: # ${a:1:} or ${@:1:}
self._SetNext(lex_mode_e.Arith)
self._GetToken()

if self.token_type != Id.Arith_RBrace:
length = self._ReadArithExpr(Id.Arith_RBrace)
else:
# quirky bash behavior:
# ${a:1:} or ${a::} means zero length
# ${a:1:} or ${a::} means length ZERO
# but ${a:1} or ${a:} means length N
length = arith_expr.EmptyZero

return suffix_op.Slice(begin, length)

elif cur_id == Id.Arith_RBrace: # ${a:1} or ${@:1}
no_length = None # type: Optional[arith_expr_t] # No length specified
return suffix_op.Slice(begin, no_length)
else:
p_die("Expected : or } in slice", self.cur_token)

p_die("Expected : or } in slice", self.cur_token)
raise AssertionError() # for MyPy

def _ReadPatSubVarOp(self):
Expand Down

0 comments on commit 5d2e6a6

Please sign in to comment.