Skip to content

Commit 0d9565a

Browse files
committed
Rearrange pexp-custom stuff a bit.
1 parent 72c6c60 commit 0d9565a

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/boot/fe/pexp.ml

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type pexp' =
3434
| PEXP_str of string
3535
| PEXP_mutable of pexp
3636
| PEXP_exterior of pexp
37-
| PEXP_custom of Ast.name * (token array) * (string option)
37+
| PEXP_custom of Ast.name * (pexp array) * (string option)
3838

3939
and plval =
4040
PLVAL_ident of Ast.ident
@@ -691,18 +691,10 @@ and parse_bottom_pexp (ps:pstate) : pexp =
691691
| POUND ->
692692
bump ps;
693693
let name = parse_name ps in
694-
let toks =
694+
let args =
695695
match peek ps with
696696
LPAREN ->
697-
bump ps;
698-
let toks = Queue.create () in
699-
while (peek ps) <> RPAREN
700-
do
701-
Queue.add (peek ps) toks;
702-
bump ps;
703-
done;
704-
expect ps RPAREN;
705-
queue_to_arr toks
697+
parse_pexp_list ps
706698
| _ -> [| |]
707699
in
708700
let str =
@@ -718,7 +710,7 @@ and parse_bottom_pexp (ps:pstate) : pexp =
718710
in
719711
let bpos = lexpos ps in
720712
span ps apos bpos
721-
(PEXP_custom (name, toks, str))
713+
(PEXP_custom (name, args, str))
722714

723715
| LPAREN ->
724716
begin
@@ -971,10 +963,12 @@ and parse_pexp_list (ps:pstate) : pexp array =
971963

972964
let expand_pexp_custom
973965
(ps:pstate)
966+
(dst_lval:Ast.lval)
974967
(name:Ast.name)
975-
(args:token array)
968+
(args:Ast.atom array)
976969
(body:string option)
977-
: pexp' =
970+
(spanner:'a -> 'a identified)
971+
: (Ast.stmt array) =
978972
let nstr = Fmt.fmt_to_str Ast.fmt_name name in
979973
match (nstr, (Array.length args), body) with
980974

@@ -990,7 +984,7 @@ let expand_pexp_custom
990984
ignore (Unix.close_process_in c);
991985
Buffer.contents b
992986
in
993-
PEXP_str (r ())
987+
[| spanner (Ast.STMT_init_str (dst_lval, r())) |]
994988

995989
| _ ->
996990
raise (err ("unsupported syntax extension: " ^ nstr) ps)
@@ -1093,7 +1087,8 @@ and desugar_expr_atom
10931087
| PEXP_chan _
10941088
| PEXP_call _
10951089
| PEXP_bind _
1096-
| PEXP_spawn _ ->
1090+
| PEXP_spawn _
1091+
| PEXP_custom _ ->
10971092
let (_, tmp, decl_stmt) = build_tmp ps slot_auto apos bpos in
10981093
let stmts = desugar_expr_init ps tmp pexp in
10991094
(Array.append [| decl_stmt |] stmts,
@@ -1112,10 +1107,6 @@ and desugar_expr_atom
11121107
| PEXP_mutable _ ->
11131108
raise (err "mutable keyword in atom context" ps)
11141109

1115-
| PEXP_custom (n, a, b) ->
1116-
desugar_expr_atom ps
1117-
{ pexp with node = expand_pexp_custom ps n a b }
1118-
11191110

11201111
and desugar_expr_mode_mut_atom
11211112
(ps:pstate)
@@ -1331,8 +1322,11 @@ and desugar_expr_init
13311322
raise (err "mutable keyword in initialiser context" ps)
13321323

13331324
| PEXP_custom (n, a, b) ->
1334-
desugar_expr_init ps dst_lval
1335-
{ pexp with node = expand_pexp_custom ps n a b }
1325+
let (arg_stmts, args) = desugar_expr_atoms ps a in
1326+
let stmts =
1327+
expand_pexp_custom ps dst_lval n args b ss
1328+
in
1329+
aa arg_stmts stmts
13361330

13371331

13381332
and atom_lval (ps:pstate) (at:Ast.atom) : Ast.lval =

0 commit comments

Comments
 (0)