Skip to content

Commit db6c88f

Browse files
author
Andy C
committed
[osh] Introduce word_.PieceOperator()
Also change from PieceOperator -> PieceQuoted for brace digit expansion The usage Piece('3', quoted=False, do_split=False) is the same as Piece('3', quoted=True, do_split=False) That's because '3' isn't a metacharacter, so it won't be glob-escaped. [soil] Ignore IOError that happens because of race condition
1 parent 80ccd5a commit db6c88f

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

osh/word_.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,22 @@ def PieceQuoted(s):
3636
For 'hi' "$x"
3737
and $[myexpr] in YSH
3838
"""
39+
# quoted=True, do_split=False
3940
return Piece(s, True, False)
4041

4142

43+
def PieceOperator(s):
44+
# type: (str) -> Piece
45+
"""
46+
For Extended glob @(--verbose|help)
47+
And BashRegexGroup [[ foo =~ x(a b)y ]
48+
49+
We don't want ( to become \(, so quoted=False
50+
"""
51+
# quoted=False, do_split=False
52+
return Piece(s, False, False)
53+
54+
4255
def LiteralId(part):
4356
# type: (word_part_t) -> Id_t
4457
"""If the WordPart consists of a single literal token, return its Id.

osh/word_eval.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,16 +1781,14 @@ def _EvalExtGlob(self, part, part_vals):
17811781
op_str = '@('
17821782
else:
17831783
op_str = lexer.LazyStr(op)
1784-
# Do NOT split these.
1785-
# TODO: should be PieceQuoted
1786-
part_vals.append(Piece(op_str, False, False))
1784+
part_vals.append(word_.PieceOperator(op_str))
17871785

17881786
for i, w in enumerate(part.arms):
17891787
if i != 0:
1790-
part_vals.append(Piece('|', False, False)) # separator
1788+
part_vals.append(word_.PieceOperator('|')) # separator
17911789
# FLATTEN the tree of extglob "arms".
17921790
self._EvalWordToParts(w, part_vals, EXTGLOB_NESTED)
1793-
part_vals.append(Piece(')', False, False)) # closing )
1791+
part_vals.append(word_.PieceOperator(')')) # closing )
17941792

17951793
def _TranslateExtGlob(self, part_vals, w, glob_parts, fnmatch_parts):
17961794
# type: (List[part_value_t], CompoundWord, List[str], List[str]) -> None
@@ -1857,9 +1855,8 @@ def _EvalWordPart(self, part, part_vals, flags):
18571855

18581856
elif case(word_part_e.BracedRangeDigit):
18591857
part = cast(word_part.BracedRangeDigit, UP_part)
1860-
# This is the '5' in {1..10} - whether it's quoted should not
1861-
# matter - it doesn't look like a glob
1862-
v = Piece(part.s, False, False)
1858+
# This is the '5' in {1..10}
1859+
v = word_.PieceQuoted(part.s)
18631860
part_vals.append(v)
18641861

18651862
elif case(word_part_e.EscapedLiteral):
@@ -1928,10 +1925,10 @@ def _EvalWordPart(self, part, part_vals, flags):
19281925
elif case(word_part_e.BashRegexGroup):
19291926
part = cast(word_part.BashRegexGroup, UP_part)
19301927

1931-
part_vals.append(Piece('(', False, False)) # not quoted
1928+
part_vals.append(word_.PieceOperator('('))
19321929
if part.child:
19331930
self._EvalWordToParts(part.child, part_vals, 0)
1934-
part_vals.append(Piece(')', False, False))
1931+
part_vals.append(word_.PieceOperator(')'))
19351932

19361933
elif case(word_part_e.Splice):
19371934
part = cast(word_part.Splice, UP_part)

osh/word_parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ def _ReadBashRegexGroup(self):
10161016
# type: () -> word_part.BashRegexGroup
10171017
"""
10181018
Grammar:
1019-
BashRegexGroup = '(' WORD? ')
1019+
BashRegexGroup = '(' WORD? ')
10201020
"""
10211021
left_token = self.cur_token
10221022
assert left_token.id == Id.BashRegex_LParen, left_token

soil/web.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,13 @@ def ParseJobs(stdin):
211211
#if i % 20 == 0:
212212
# log('job %d = %s', i, json_path)
213213

214-
with open(json_path) as f:
215-
meta = json.load(f)
214+
try:
215+
with open(json_path) as f:
216+
meta = json.load(f)
217+
except IOError as e:
218+
# We do concurrent deletions, and we can't rely on sorting beforehand
219+
log('Ignoring file that was probably deleted %s: %s', json_path, e)
220+
continue
216221
#print(meta)
217222

218223
tsv_path = json_path[:-5] + '.tsv'

0 commit comments

Comments
 (0)