Skip to content

Commit 8c6b097

Browse files
author
Andy Chu
committed
[oil-language] Create a token to parse for @{.myproc arg1}
Related to #799. [refactor] Planning out parsing of where (x > 10) Barely starting #955.
1 parent 327c4ec commit 8c6b097

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

frontend/id_kind_def.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def AddKinds(spec):
215215
spec.AddKind('Lit', [
216216
'Chars', 'VarLike', 'ArrayLhsOpen', 'ArrayLhsClose',
217217
'Splice', # @func(a, b)
218+
'AtLBraceDot', # @{.myproc arg1}
218219
'Other', 'EscapedChar', 'RegexMeta',
219220
'LBracket', 'RBracket', # for assoc array literals, static globs
220221
'Star', 'QMark',

frontend/lexer_def.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def R(pat, tok_type):
325325

326326
# @array and @func(1, c)
327327
R('@' + VAR_NAME_RE, Id.Lit_Splice), # for Oil splicing
328+
C('@{.', Id.Lit_AtLBraceDot), # for split builtin sub @{.myproc arg1}
328329

329330
R(FD_NUM + r'<', Id.Redir_Less),
330331
R(FD_NUM + r'>', Id.Redir_Great),

osh/cmd_parse.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,22 +1661,29 @@ def ParseFunctionDef(self):
16611661
self.lexer.PushHint(Id.Op_RParen, Id.Right_ShFunction)
16621662
self._Next()
16631663

1664-
self._Eat2(Id.Right_ShFunction, 'Expected ) in function definition')
1664+
self._Peek()
1665+
if self.c_id == Id.Right_ShFunction:
1666+
# 'f ()' implies a function definition, since invoking it with no args
1667+
# would just be 'f'
1668+
self._Next()
16651669

1666-
after_name_spid = word_.LeftMostSpanForWord(self.cur_word) + 1
1670+
after_name_spid = word_.LeftMostSpanForWord(self.cur_word) + 1
16671671

1668-
self._NewlineOk()
1672+
self._NewlineOk()
16691673

1670-
func = command.ShFunction()
1671-
func.name = name
1672-
with ctx_VarChecker(self.var_checker, blame_tok):
1673-
func.body = self.ParseCompoundCommand()
1674+
func = command.ShFunction()
1675+
func.name = name
1676+
with ctx_VarChecker(self.var_checker, blame_tok):
1677+
func.body = self.ParseCompoundCommand()
16741678

1675-
# matches ParseKshFunctionDef below
1676-
func.spids.append(left_spid)
1677-
func.spids.append(left_spid) # name_spid is same as left_spid in this case
1678-
func.spids.append(after_name_spid)
1679-
return func
1679+
# matches ParseKshFunctionDef below
1680+
func.spids.append(left_spid)
1681+
func.spids.append(left_spid) # name_spid is same as left_spid in this case
1682+
func.spids.append(after_name_spid)
1683+
return func
1684+
else:
1685+
p_die('Expected ) in function definition', word=self.cur_word)
1686+
return None
16801687

16811688
def ParseKshFunctionDef(self):
16821689
# type: () -> command__ShFunction

osh/word_parse.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,10 @@ def _MaybeReadWholeWord(self, is_first, lex_mode, parts):
14211421
p_die('Unexpected token after array splice', token=self.cur_token)
14221422
done = True
14231423

1424+
elif (is_first and self.parse_opts.parse_at() and
1425+
self.token_type == Id.Lit_AtLBraceDot):
1426+
p_die('TODO: @{.myproc builtin sub}', token=self.cur_token)
1427+
14241428
elif (is_first and self.parse_opts.parse_at_all() and
14251429
self.token_type == Id.Lit_At):
14261430
# Because $[x] ${x} and perhaps $/x/ are reserved, it makes sense for @

0 commit comments

Comments
 (0)