Fixed parsing and source pretty-printing of recursive functions.
This commit is contained in:
parent
68b6e6d3b0
commit
b51818bc4e
@ -364,6 +364,7 @@ let keywords = [
|
|||||||
(fun reg -> Or reg);
|
(fun reg -> Or reg);
|
||||||
(fun reg -> Patch reg);
|
(fun reg -> Patch reg);
|
||||||
(fun reg -> Record reg);
|
(fun reg -> Record reg);
|
||||||
|
(fun reg -> Recursive reg);
|
||||||
(fun reg -> Remove reg);
|
(fun reg -> Remove reg);
|
||||||
(fun reg -> Set reg);
|
(fun reg -> Set reg);
|
||||||
(fun reg -> Skip reg);
|
(fun reg -> Skip reg);
|
||||||
|
@ -263,46 +263,12 @@ fun_expr:
|
|||||||
(* Function declarations *)
|
(* Function declarations *)
|
||||||
|
|
||||||
open_fun_decl:
|
open_fun_decl:
|
||||||
"function" fun_name parameters ":" type_expr "is"
|
"recursive"? "function" fun_name parameters ":" type_expr "is"
|
||||||
block "with" expr {
|
|
||||||
Scoping.check_reserved_name $2;
|
|
||||||
let stop = expr_to_region $9 in
|
|
||||||
let region = cover $1 stop
|
|
||||||
and value = {kwd_recursive= None;
|
|
||||||
kwd_function = $1;
|
|
||||||
fun_name = $2;
|
|
||||||
param = $3;
|
|
||||||
colon = $4;
|
|
||||||
ret_type = $5;
|
|
||||||
kwd_is = $6;
|
|
||||||
block_with = Some ($7, $8);
|
|
||||||
return = $9;
|
|
||||||
terminator = None;
|
|
||||||
attributes = None}
|
|
||||||
in {region; value}
|
|
||||||
}
|
|
||||||
| "function" fun_name parameters ":" type_expr "is" expr {
|
|
||||||
Scoping.check_reserved_name $2;
|
|
||||||
let stop = expr_to_region $7 in
|
|
||||||
let region = cover $1 stop
|
|
||||||
and value = {kwd_recursive= None;
|
|
||||||
kwd_function = $1;
|
|
||||||
fun_name = $2;
|
|
||||||
param = $3;
|
|
||||||
colon = $4;
|
|
||||||
ret_type = $5;
|
|
||||||
kwd_is = $6;
|
|
||||||
block_with = None;
|
|
||||||
return = $7;
|
|
||||||
terminator = None;
|
|
||||||
attributes = None}
|
|
||||||
in {region; value} }
|
|
||||||
| "recursive" "function" fun_name parameters ":" type_expr "is"
|
|
||||||
block "with" expr {
|
block "with" expr {
|
||||||
Scoping.check_reserved_name $3;
|
Scoping.check_reserved_name $3;
|
||||||
let stop = expr_to_region $10 in
|
let stop = expr_to_region $10 in
|
||||||
let region = cover $2 stop
|
let region = cover $2 stop
|
||||||
and value = {kwd_recursive= Some($1);
|
and value = {kwd_recursive= $1;
|
||||||
kwd_function = $2;
|
kwd_function = $2;
|
||||||
fun_name = $3;
|
fun_name = $3;
|
||||||
param = $4;
|
param = $4;
|
||||||
@ -315,11 +281,11 @@ open_fun_decl:
|
|||||||
attributes = None}
|
attributes = None}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| "recursive" "function" fun_name parameters ":" type_expr "is" expr {
|
| "recursive"? "function" fun_name parameters ":" type_expr "is" expr {
|
||||||
Scoping.check_reserved_name $3;
|
Scoping.check_reserved_name $3;
|
||||||
let stop = expr_to_region $8 in
|
let stop = expr_to_region $8 in
|
||||||
let region = cover $2 stop
|
let region = cover $2 stop
|
||||||
and value = {kwd_recursive= Some($1);
|
and value = {kwd_recursive= $1;
|
||||||
kwd_function = $2;
|
kwd_function = $2;
|
||||||
fun_name = $3;
|
fun_name = $3;
|
||||||
param = $4;
|
param = $4;
|
||||||
|
@ -859,20 +859,26 @@ and pp_declaration state = function
|
|||||||
and pp_attr_decl state = pp_ne_injection pp_string state
|
and pp_attr_decl state = pp_ne_injection pp_string state
|
||||||
|
|
||||||
and pp_fun_decl state decl =
|
and pp_fun_decl state decl =
|
||||||
let arity = 5 in
|
let arity, start =
|
||||||
|
match decl.kwd_recursive with
|
||||||
|
None -> 5,0
|
||||||
|
| Some _ ->
|
||||||
|
let state = state#pad 6 0 in
|
||||||
|
let () = pp_node state "recursive"
|
||||||
|
in 6,1 in
|
||||||
let () =
|
let () =
|
||||||
let state = state#pad arity 0 in
|
let state = state#pad arity start in
|
||||||
pp_ident state decl.fun_name in
|
pp_ident state decl.fun_name in
|
||||||
let () =
|
let () =
|
||||||
let state = state#pad arity 1 in
|
let state = state#pad arity (start + 1) in
|
||||||
pp_node state "<parameters>";
|
pp_node state "<parameters>";
|
||||||
pp_parameters state decl.param in
|
pp_parameters state decl.param in
|
||||||
let () =
|
let () =
|
||||||
let state = state#pad arity 2 in
|
let state = state#pad arity (start + 2) in
|
||||||
pp_node state "<return type>";
|
pp_node state "<return type>";
|
||||||
pp_type_expr (state#pad 1 0) decl.ret_type in
|
pp_type_expr (state#pad 1 0) decl.ret_type in
|
||||||
let () =
|
let () =
|
||||||
let state = state#pad arity 3 in
|
let state = state#pad arity (start + 3) in
|
||||||
pp_node state "<body>";
|
pp_node state "<body>";
|
||||||
let statements =
|
let statements =
|
||||||
match decl.block_with with
|
match decl.block_with with
|
||||||
@ -880,7 +886,7 @@ and pp_fun_decl state decl =
|
|||||||
| None -> Instr (Skip Region.ghost), [] in
|
| None -> Instr (Skip Region.ghost), [] in
|
||||||
pp_statements state statements in
|
pp_statements state statements in
|
||||||
let () =
|
let () =
|
||||||
let state = state#pad arity 4 in
|
let state = state#pad arity (start + 4) in
|
||||||
pp_node state "<return>";
|
pp_node state "<return>";
|
||||||
pp_expr (state#pad 1 0) decl.return
|
pp_expr (state#pad 1 0) decl.return
|
||||||
in ()
|
in ()
|
||||||
|
Loading…
Reference in New Issue
Block a user