-
-
Notifications
You must be signed in to change notification settings - Fork 164
Oil Dev Tips
andychu edited this page Jun 2, 2022
·
8 revisions
Back to Contributing
If you do anything with the AST, use the -n
flag to preview it
$ bin/oil -n -c 'proc p(x, @y) { echo hi }'
(command.Proc
name: <p>
sig: (proc_sig.Closed untyped:[(UntypedParam name:<Id.Expr_Name x>)] rest:<Id.Expr_Name y>)
body: (BraceGroup children:[(C {<echo>} {<hi>})])
)
If you want to see the parse trees, uncomment the if 0
blocks in frontend/parse_lib.py
. Those are the entry points into the Oil parser, which uses a pgen2 grammar.
$ bin/oil -n -c 'proc p(x, @y) { echo hi }'
0 oil_proc -
0 Op_LParen None
1 proc_params x
0 proc_param x
0 Expr_Name x
1 Arith_Comma None
2 proc_param @
0 Expr_At @
1 Expr_Name y
2 Op_RParen None
3 Op_LBrace None
(command.Proc
name: <p>
sig: (proc_sig.Closed untyped:[(UntypedParam name:<Id.Expr_Name x>)] rest:<Id.Expr_Name y>)
body: (BraceGroup children:[(C {<echo>} {<hi>})])
)