Skip to content

Commit

Permalink
[frontend] Add right token to word_part.ExtGlob
Browse files Browse the repository at this point in the history
Use Tokens and not spids in location.py
  • Loading branch information
Andy C committed May 15, 2023
1 parent 0fe42d5 commit 41646d8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions frontend/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ def _OfWordPartRight(part):

elif case(word_part_e.ArithSub):
part = cast(word_part.ArithSub, UP_part)
return part.spids[1]
return part.right.span_id

elif case(word_part_e.ExtGlob):
part = cast(word_part.ExtGlob, UP_part)
return part.spids[1]
return part.right.span_id

# TODO: Do Splice and FuncCall need it?
else:
Expand Down
2 changes: 1 addition & 1 deletion frontend/syntax.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ module syntax
| BracedRange(id kind, str start, str end, int step)
# note: optional int may need special handling in ASDL
# extended globs are parsed statically, unlike globs
| ExtGlob(Token op, List[CompoundWord] arms)
| ExtGlob(Token op, List[CompoundWord] arms, Token right)

# Oil word_part extensions

Expand Down
9 changes: 3 additions & 6 deletions osh/word_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,8 @@ def _ReadExtGlob(self):
Compound includes ExtGlob
"""
left_token = self.cur_token
right_token = None # type: Token
arms = [] # type: List[CompoundWord]
spids = [] # type: List[int]
spids.append(left_token.span_id)

self.lexer.PushHint(Id.Op_RParen, Id.Right_ExtGlob)
self._Next(lex_mode_e.ExtGlob) # advance past LEFT
Expand All @@ -783,7 +782,7 @@ def _ReadExtGlob(self):
if self.token_type == Id.Right_ExtGlob:
if not read_word:
arms.append(CompoundWord([]))
spids.append(self.cur_token.span_id)
right_token = self.cur_token
break

elif self.token_type == Id.Op_Pipe:
Expand All @@ -805,9 +804,7 @@ def _ReadExtGlob(self):
else:
raise AssertionError(self.cur_token)

part = word_part.ExtGlob(left_token, arms)
part.spids.extend(spids)
return part
return word_part.ExtGlob(left_token, arms, right_token)

def _ReadLikeDQ(self, left_token, is_oil_expr, out_parts):
# type: (Optional[Token], bool, List[word_part_t]) -> None
Expand Down

0 comments on commit 41646d8

Please sign in to comment.