Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Sep 25, 2019
1 parent 2b0466c commit 6487c8e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions core/id_kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ def AddKinds(spec):
'SetVar', # for OSH compatibility
'Proc', 'Func',

# for printing
'Pass', 'Pp',

'Match', 'With', # matching
# not sure: yield
# mycpp
Expand Down
2 changes: 2 additions & 0 deletions frontend/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@
C('set', Id.KW_Set),
C('func', Id.KW_Func),
C('proc', Id.KW_Proc),
C('pass', Id.KW_Pass),
C('pp', Id.KW_Pp),
]

# These are treated like builtins in bash, but keywords in OSH. However, we
Expand Down
6 changes: 4 additions & 2 deletions frontend/syntax.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,10 @@ module syntax
| VarDecl(token? keyword, expr lhs, type_expr? typ, token op, expr rhs)
-- setvar/set, auto
| PlaceMutation(token? keyword, expr lhs, expr rhs)
| Do(expr e) -- an expression for its side effects
| Return(token keyword, expr e) -- returnin an Obj, not an int-like string
-- do, pp, pass. An expression for its side effects
| Expr(token keyword, expr e)
-- return an Obj, not an int-like string
| Return(token keyword, expr e)
| OilCondition(expr e) -- for if/while
-- C-style for loop? Currently unused.
| OilFor3(expr? init, expr? cond, expr? update, command? body)
Expand Down
2 changes: 1 addition & 1 deletion oil_lang/expr_to_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def Expr(self, pnode):
# oil_expr: '(' testlist ')'
return self.Expr(children[1])

if typ == grammar_nt.return_expr:
if typ == grammar_nt.command_expr:
# return_expr: testlist end_stmt
return self.Expr(children[0])

Expand Down
2 changes: 1 addition & 1 deletion oil_lang/grammar.pgen2
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ oil_arglist: '(' [arglist] ')'
# for if (x > 0) etc.
oil_expr: '(' testlist ')'
# e.g. return 1 + 2 * 3
return_expr: testlist end_stmt
command_expr: testlist end_stmt

# Example: for (a Int, b Int in expr) { ... }
oil_for: '(' place_list 'in' testlist ')'
Expand Down
2 changes: 1 addition & 1 deletion osh/cmd_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ def ParseCommand(self):

keyword = self.cur_word.parts[0].token
self._Next()
enode = self.w_parser.ParseReturn()
enode = self.w_parser.ParseCommandExpr()
node = command.Return(keyword, enode)
return node

Expand Down
6 changes: 3 additions & 3 deletions osh/word_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,17 +855,17 @@ def ParseBareShAssignment(self):
self._Peek()
op = self.cur_token # TODO: Don't need this
enode, last_token = self.parse_ctx.ParseOilExpr(self.lexer,
grammar_nt.return_expr)
grammar_nt.command_expr)
if last_token.id == Id.Op_RBrace:
last_token.id = Id.Lit_RBrace
self.buffered_word = word.Token(last_token)
self._Next(lex_mode_e.ShCommand)
return op, enode

def ParseReturn(self):
def ParseCommandExpr(self):
# type: () -> expr_t
enode, last_token = self.parse_ctx.ParseOilExpr(self.lexer,
grammar_nt.return_expr)
grammar_nt.command_expr)
if last_token.id == Id.Op_RBrace:
last_token.id = Id.Lit_RBrace
self.buffered_word = word.Token(last_token)
Expand Down

0 comments on commit 6487c8e

Please sign in to comment.