@@ -34,7 +34,7 @@ type pexp' =
34
34
| PEXP_str of string
35
35
| PEXP_mutable of pexp
36
36
| PEXP_exterior of pexp
37
- | PEXP_custom of Ast .name * (token array ) * (string option )
37
+ | PEXP_custom of Ast .name * (pexp array ) * (string option )
38
38
39
39
and plval =
40
40
PLVAL_ident of Ast. ident
@@ -691,18 +691,10 @@ and parse_bottom_pexp (ps:pstate) : pexp =
691
691
| POUND ->
692
692
bump ps;
693
693
let name = parse_name ps in
694
- let toks =
694
+ let args =
695
695
match peek ps with
696
696
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
706
698
| _ -> [| |]
707
699
in
708
700
let str =
@@ -718,7 +710,7 @@ and parse_bottom_pexp (ps:pstate) : pexp =
718
710
in
719
711
let bpos = lexpos ps in
720
712
span ps apos bpos
721
- (PEXP_custom (name, toks , str))
713
+ (PEXP_custom (name, args , str))
722
714
723
715
| LPAREN ->
724
716
begin
@@ -971,10 +963,12 @@ and parse_pexp_list (ps:pstate) : pexp array =
971
963
972
964
let expand_pexp_custom
973
965
(ps :pstate )
966
+ (dst_lval :Ast.lval )
974
967
(name :Ast.name )
975
- (args :token array )
968
+ (args :Ast.atom array )
976
969
(body :string option )
977
- : pexp' =
970
+ (spanner :'a -> 'a identified )
971
+ : (Ast.stmt array) =
978
972
let nstr = Fmt. fmt_to_str Ast. fmt_name name in
979
973
match (nstr, (Array. length args), body) with
980
974
@@ -990,7 +984,7 @@ let expand_pexp_custom
990
984
ignore (Unix. close_process_in c);
991
985
Buffer. contents b
992
986
in
993
- PEXP_str (r () )
987
+ [| spanner ( Ast. STMT_init_str (dst_lval, r () )) |]
994
988
995
989
| _ ->
996
990
raise (err (" unsupported syntax extension: " ^ nstr) ps)
@@ -1093,7 +1087,8 @@ and desugar_expr_atom
1093
1087
| PEXP_chan _
1094
1088
| PEXP_call _
1095
1089
| PEXP_bind _
1096
- | PEXP_spawn _ ->
1090
+ | PEXP_spawn _
1091
+ | PEXP_custom _ ->
1097
1092
let (_, tmp, decl_stmt) = build_tmp ps slot_auto apos bpos in
1098
1093
let stmts = desugar_expr_init ps tmp pexp in
1099
1094
(Array. append [| decl_stmt |] stmts,
@@ -1112,10 +1107,6 @@ and desugar_expr_atom
1112
1107
| PEXP_mutable _ ->
1113
1108
raise (err " mutable keyword in atom context" ps)
1114
1109
1115
- | PEXP_custom (n , a , b ) ->
1116
- desugar_expr_atom ps
1117
- { pexp with node = expand_pexp_custom ps n a b }
1118
-
1119
1110
1120
1111
and desugar_expr_mode_mut_atom
1121
1112
(ps :pstate )
@@ -1331,8 +1322,11 @@ and desugar_expr_init
1331
1322
raise (err " mutable keyword in initialiser context" ps)
1332
1323
1333
1324
| 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
1336
1330
1337
1331
1338
1332
and atom_lval (ps :pstate ) (at :Ast.atom ) : Ast.lval =
0 commit comments