Skip to content

Commit

Permalink
[rename] Oil -> YshExpr in frontend/syntax.asdl
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy C committed May 21, 2023
1 parent ebdce70 commit 0d2f731
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
23 changes: 11 additions & 12 deletions frontend/syntax.asdl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Data types for the Oil AST, aka "Lossless Syntax Tree".
# Data types for the Oils AST, aka "Lossless Syntax Tree".
#
# Invariant: the source text can be reconstructed byte-for-byte from this
# tree. The test/arena.sh file partially verifies this.
Expand Down Expand Up @@ -118,7 +118,7 @@ module syntax
suffix_op =
Nullary %Token # ${x@Q} or ${!prefix@} (which also has prefix_op)
| Unary(Token op, rhs_word arg_word) # e.g. ${v:-default}
# TODO: Implement Oil's ${x|html} and ${x %.3f}
# TODO: Implement YSH ${x|html} and ${x %.3f}
| Static(Token tok, str arg)
| PatSub(CompoundWord pat, rhs_word replace, id replace_mode, Token slash_tok)
# begin is optional with ${array::1}
Expand Down Expand Up @@ -180,7 +180,7 @@ module syntax
# extended globs are parsed statically, unlike globs
| ExtGlob(Token op, List[CompoundWord] arms, Token right)

# Oil word_part extensions
# YSH word_part extensions

# @myarray
| Splice(Token blame_tok, str var_name)
Expand Down Expand Up @@ -254,7 +254,7 @@ module syntax

condition =
Shell(List[command] commands) # if false; true; then echo hi; fi
| Oil(expr e) # if (x > 0) { echo hi }
| YshExpr(expr e) # if (x > 0) { echo hi }

# Each arm tests one word against multiple words
# shell: *.cc|*.h) echo C++ ;;
Expand All @@ -277,7 +277,7 @@ module syntax
# commands we match against a word.
case_arg =
Word(word w)
| OilExpr(expr e)
| YshExpr(expr e)

# Each if arm starts with either an "if" or "elif" keyword
# In YSH, the then keyword is not used (replaced by braces {})
Expand All @@ -286,10 +286,10 @@ module syntax
List[int] spids)

for_iter =
Args # for x; do echo $x; done # implicit "$@"
| Words(List[word] words) # for x in 'foo' *.py { echo $x }
# like ShArrayLiteral, but no location for %(
| Oil(expr e, Token blame) # for x in (mylist) { echo $x }
Args # for x; do echo $x; done # implicit "$@"
| Words(List[word] words) # for x in 'foo' *.py { echo $x }
# like ShArrayLiteral, but no location for %(
| YshExpr(expr e, Token blame) # for x in (mylist) { echo $x }

BraceGroup = (
Token left, Token? doc_token, List[command] children,
Expand Down Expand Up @@ -351,7 +351,7 @@ module syntax
# 4. Subshell # single child that's a CommandList
| CommandList(List[command] children)

# Oil stuff
# YSH command constructs

# For 'x = myexpr'. There's no type and no comma allowed.
| BareDecl(Token lhs, expr rhs)
Expand Down Expand Up @@ -525,8 +525,7 @@ module syntax
# (Starred is NOT used for {k:v, **a}. That used a blank "keys"
# attribute.)

# In Oil, "spreading" will be @[1 ...array2] [b, ...list2] and
# {k: v, ...dict2}. We don't need two different symbols.
# I think we can use { **pairs } like Python
| Spread(expr child, expr_context ctx)

#
Expand Down
12 changes: 6 additions & 6 deletions osh/cmd_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,9 @@ def _EvalCondition(self, cond, blame_tok):

b = cond_status == 0

elif case(condition_e.Oil):
elif case(condition_e.YshExpr):
if mylib.PYTHON:
cond = cast(condition.Oil, UP_cond)
cond = cast(condition.YshExpr, UP_cond)
obj = self.expr_ev.EvalExpr(cond.e, blame_tok)
b = bool(obj)

Expand All @@ -635,9 +635,9 @@ def _EvalCaseArg(self, arg, blame):
arg = cast(case_arg.Word, UP_arg)
return self.word_ev.EvalWordToString(arg.w).s

elif case(case_arg_e.OilExpr):
elif case(case_arg_e.YshExpr):
if mylib.PYTHON:
arg = cast(case_arg.OilExpr, UP_arg)
arg = cast(case_arg.YshExpr, UP_arg)
obj = self.expr_ev.EvalExpr(arg.e, blame)
return str(obj) # TODO: handle typed args

Expand Down Expand Up @@ -1186,8 +1186,8 @@ def _Dispatch(self, node, cmd_st):
words = braces.BraceExpandWords(iterable.words)
iter_list = self.word_ev.EvalWordSequence(words)

elif case(for_iter_e.Oil):
iterable = cast(for_iter.Oil, UP_iterable)
elif case(for_iter_e.YshExpr):
iterable = cast(for_iter.YshExpr, UP_iterable)
iter_expr = iterable.e
iter_expr_blame = iterable.blame

Expand Down
10 changes: 5 additions & 5 deletions osh/cmd_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ def _ParseForEachLoop(self, for_kw):
self._Next() # skip in
if self.w_parser.LookPastSpace() == Id.Op_LParen:
enode, last_token = self.parse_ctx.ParseOilExpr(self.lexer, grammar_nt.oil_expr)
node.iterable = for_iter.Oil(enode, last_token)
node.iterable = for_iter.YshExpr(enode, last_token)

# For simplicity, we don't accept for x in (obj); do ...
self._Peek()
Expand Down Expand Up @@ -1288,7 +1288,7 @@ def ParseWhileUntil(self, keyword):

if self.parse_opts.parse_paren() and self.w_parser.LookPastSpace() == Id.Op_LParen:
enode, _ = self.parse_ctx.ParseOilExpr(self.lexer, grammar_nt.oil_expr)
cond = condition.Oil(enode) # type: condition_t
cond = condition.YshExpr(enode) # type: condition_t
else:
self.allow_block = False
commands = self._ParseCommandList()
Expand Down Expand Up @@ -1447,7 +1447,7 @@ def ParseOilCase(self, case_node):
Call this after we're past 'case'.
"""
enode, _ = self.parse_ctx.ParseOilExpr(self.lexer, grammar_nt.oil_expr)
case_node.to_match = case_arg.OilExpr(enode)
case_node.to_match = case_arg.YshExpr(enode)

ate = self._Eat(Id.Lit_LBrace)
case_node.arms_start = word_.BraceToken(ate)
Expand Down Expand Up @@ -1526,7 +1526,7 @@ def _ParseOilElifElse(self, if_node):
if (self.parse_opts.parse_paren() and
self.w_parser.LookPastSpace() == Id.Op_LParen):
enode, _ = self.parse_ctx.ParseOilExpr(self.lexer, grammar_nt.oil_expr)
cond = condition.Oil(enode) # type: condition_t
cond = condition.YshExpr(enode) # type: condition_t
else:
self.allow_block = False
commands= self._ParseCommandList()
Expand Down Expand Up @@ -1627,7 +1627,7 @@ def ParseIf(self):
# Remove ambiguity with if cd / {
if self.parse_opts.parse_paren() and self.w_parser.LookPastSpace() == Id.Op_LParen:
enode, _ = self.parse_ctx.ParseOilExpr(self.lexer, grammar_nt.oil_expr)
cond = condition.Oil(enode) # type: condition_t
cond = condition.YshExpr(enode) # type: condition_t
else:
self.allow_block = False
commands = self._ParseCommandList()
Expand Down
4 changes: 2 additions & 2 deletions tools/osh2oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def DoCommand(self, node, local_symbols, at_top_level=False):
elif case(for_iter_e.Words):
pass

elif case(for_iter_e.Oil):
elif case(for_iter_e.YshExpr):
pass

if node.semi_tok is not None:
Expand Down Expand Up @@ -734,7 +734,7 @@ def DoCommand(self, node, local_symbols, at_top_level=False):

to_match = None # type: word_t
with tagswitch(node.to_match) as case:
if case(case_arg_e.OilExpr):
if case(case_arg_e.YshExpr):
#self.cursor.PrintUntilSpid(arms_end_spid)
#self.cursor.SkipUntilSpid(arms_end_spid + 1)
return
Expand Down

0 comments on commit 0d2f731

Please sign in to comment.