diff --git a/src/passes/1-parser/pascaligo/LexToken.mll b/src/passes/1-parser/pascaligo/LexToken.mll index 4b6ab211c..5711bbac6 100644 --- a/src/passes/1-parser/pascaligo/LexToken.mll +++ b/src/passes/1-parser/pascaligo/LexToken.mll @@ -364,6 +364,7 @@ let keywords = [ (fun reg -> Or reg); (fun reg -> Patch reg); (fun reg -> Record reg); + (fun reg -> Recursive reg); (fun reg -> Remove reg); (fun reg -> Set reg); (fun reg -> Skip reg); diff --git a/src/passes/1-parser/pascaligo/Parser.mly b/src/passes/1-parser/pascaligo/Parser.mly index 9dbaeafe8..20b89b278 100644 --- a/src/passes/1-parser/pascaligo/Parser.mly +++ b/src/passes/1-parser/pascaligo/Parser.mly @@ -263,47 +263,13 @@ fun_expr: (* Function declarations *) open_fun_decl: - "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" + "recursive"? "function" fun_name parameters ":" type_expr "is" block "with" expr { Scoping.check_reserved_name $3; let stop = expr_to_region $10 in let region = cover $2 stop - and value = {kwd_recursive= Some($1); - kwd_function = $2; + and value = {kwd_recursive= $1; + kwd_function = $2; fun_name = $3; param = $4; colon = $5; @@ -315,11 +281,11 @@ open_fun_decl: attributes = None} 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; let stop = expr_to_region $8 in let region = cover $2 stop - and value = {kwd_recursive= Some($1); + and value = {kwd_recursive= $1; kwd_function = $2; fun_name = $3; param = $4; diff --git a/src/passes/1-parser/pascaligo/ParserLog.ml b/src/passes/1-parser/pascaligo/ParserLog.ml index 93c5f7352..ccca02968 100644 --- a/src/passes/1-parser/pascaligo/ParserLog.ml +++ b/src/passes/1-parser/pascaligo/ParserLog.ml @@ -609,8 +609,8 @@ and print_field_path_assign state {value; _} = print_nsepseq state "field_path" print_var field_path; print_token state equal "="; print_expr state field_expr - -and print_update_expr state {value; _} = + +and print_update_expr state {value; _} = let {record; kwd_with; updates} = value in print_path state record; print_token state kwd_with "with"; @@ -859,20 +859,26 @@ and pp_declaration state = function and pp_attr_decl state = pp_ne_injection pp_string state 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 state = state#pad arity 0 in + let state = state#pad arity start in pp_ident state decl.fun_name in let () = - let state = state#pad arity 1 in + let state = state#pad arity (start + 1) in pp_node state ""; pp_parameters state decl.param in let () = - let state = state#pad arity 2 in + let state = state#pad arity (start + 2) in pp_node state ""; pp_type_expr (state#pad 1 0) decl.ret_type in let () = - let state = state#pad arity 3 in + let state = state#pad arity (start + 3) in pp_node state ""; let statements = match decl.block_with with @@ -880,7 +886,7 @@ and pp_fun_decl state decl = | None -> Instr (Skip Region.ghost), [] in pp_statements state statements in let () = - let state = state#pad arity 4 in + let state = state#pad arity (start + 4) in pp_node state ""; pp_expr (state#pad 1 0) decl.return in ()