2019-05-13 00:56:22 +04:00
|
|
|
[@@@warning "-42"]
|
|
|
|
|
|
|
|
open Utils
|
|
|
|
open AST
|
|
|
|
open! Region
|
|
|
|
|
|
|
|
(* Printing the tokens with their source regions *)
|
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
let sprintf = Printf.sprintf
|
2019-05-13 00:56:22 +04:00
|
|
|
|
|
|
|
let offsets = ref true
|
2019-10-09 18:07:13 +04:00
|
|
|
let mode = ref `Point
|
2019-05-13 00:56:22 +04:00
|
|
|
|
|
|
|
let compact (region: Region.t) =
|
|
|
|
region#compact ~offsets:!offsets !mode
|
|
|
|
|
|
|
|
let print_nsepseq :
|
2019-10-09 18:07:13 +04:00
|
|
|
Buffer.t -> string -> (Buffer.t -> 'a -> unit) ->
|
|
|
|
('a, Region.t) nsepseq -> unit =
|
|
|
|
fun buffer sep print (head, tail) ->
|
2019-05-13 00:56:22 +04:00
|
|
|
let print_aux (sep_reg, item) =
|
2019-10-09 18:07:13 +04:00
|
|
|
let sep_line = sprintf "%s: %s\n" (compact sep_reg) sep in
|
|
|
|
Buffer.add_string buffer sep_line;
|
|
|
|
print buffer item
|
|
|
|
in print buffer head; List.iter print_aux tail
|
2019-05-13 00:56:22 +04:00
|
|
|
|
|
|
|
let print_sepseq :
|
2019-10-09 18:07:13 +04:00
|
|
|
Buffer.t -> string -> (Buffer.t -> 'a -> unit) ->
|
|
|
|
('a, Region.t) sepseq -> unit =
|
|
|
|
fun buffer sep print -> function
|
2019-05-13 00:56:22 +04:00
|
|
|
None -> ()
|
2019-10-09 18:07:13 +04:00
|
|
|
| Some seq -> print_nsepseq buffer sep print seq
|
|
|
|
|
|
|
|
let print_token buffer region lexeme =
|
|
|
|
let line = sprintf "%s: %s\n"(compact region) lexeme
|
|
|
|
in Buffer.add_string buffer line
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
let print_var buffer {region; value=lexeme} =
|
|
|
|
let line = sprintf "%s: Ident \"%s\"\n"
|
|
|
|
(compact region) lexeme
|
|
|
|
in Buffer.add_string buffer line
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
let print_constr buffer {region; value=lexeme} =
|
|
|
|
let line = sprintf "%s: Constr \"%s\"\n"
|
|
|
|
(compact region) lexeme
|
|
|
|
in Buffer.add_string buffer line
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
let print_string buffer {region; value=lexeme} =
|
|
|
|
let line = sprintf "%s: String %s\n"
|
|
|
|
(compact region) lexeme
|
|
|
|
in Buffer.add_string buffer line
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
let print_bytes buffer {region; value = lexeme, abstract} =
|
|
|
|
let line = sprintf "%s: Bytes (\"%s\", \"0x%s\")\n"
|
|
|
|
(compact region) lexeme
|
|
|
|
(Hex.to_string abstract)
|
|
|
|
in Buffer.add_string buffer line
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
let print_int buffer {region; value = lexeme, abstract} =
|
|
|
|
let line = sprintf "%s: Int (\"%s\", %s)\n"
|
|
|
|
(compact region) lexeme
|
|
|
|
(Z.to_string abstract)
|
|
|
|
in Buffer.add_string buffer line
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-15 23:03:46 +04:00
|
|
|
let print_nat buffer {region; value = lexeme, abstract} =
|
|
|
|
let line = sprintf "%s: Nat (\"%s\", %s)\n"
|
|
|
|
(compact region) lexeme
|
|
|
|
(Z.to_string abstract)
|
|
|
|
in Buffer.add_string buffer line
|
2019-05-13 00:56:22 +04:00
|
|
|
|
|
|
|
(* Main printing function *)
|
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
let rec print_tokens buffer ast =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {decl; eof} = ast in
|
2019-10-09 18:07:13 +04:00
|
|
|
Utils.nseq_iter (print_decl buffer) decl;
|
|
|
|
print_token buffer eof "EOF"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_decl buffer = function
|
|
|
|
TypeDecl decl -> print_type_decl buffer decl
|
|
|
|
| ConstDecl decl -> print_const_decl buffer decl
|
|
|
|
| LambdaDecl decl -> print_lambda_decl buffer decl
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_const_decl buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_const; name; colon; const_type;
|
|
|
|
equal; init; terminator} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_const "const";
|
|
|
|
print_var buffer name;
|
|
|
|
print_token buffer colon ":";
|
|
|
|
print_type_expr buffer const_type;
|
|
|
|
print_token buffer equal "=";
|
|
|
|
print_expr buffer init;
|
|
|
|
print_terminator buffer terminator
|
|
|
|
|
|
|
|
and print_type_decl buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_type; name; kwd_is;
|
|
|
|
type_expr; terminator} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_type "type";
|
|
|
|
print_var buffer name;
|
|
|
|
print_token buffer kwd_is "is";
|
|
|
|
print_type_expr buffer type_expr;
|
|
|
|
print_terminator buffer terminator
|
|
|
|
|
|
|
|
and print_type_expr buffer = function
|
|
|
|
TProd cartesian -> print_cartesian buffer cartesian
|
|
|
|
| TSum sum_type -> print_sum_type buffer sum_type
|
|
|
|
| TRecord record_type -> print_record_type buffer record_type
|
|
|
|
| TApp type_app -> print_type_app buffer type_app
|
|
|
|
| TFun type_fun -> print_type_fun buffer type_fun
|
|
|
|
| TPar par_type -> print_par_type buffer par_type
|
|
|
|
| TAlias type_alias -> print_var buffer type_alias
|
|
|
|
|
|
|
|
and print_cartesian buffer {value; _} =
|
|
|
|
print_nsepseq buffer "*" print_type_expr value
|
|
|
|
|
2019-10-15 23:03:46 +04:00
|
|
|
and print_variant buffer ({value; _}: variant reg) =
|
2019-05-17 18:29:22 +04:00
|
|
|
let {constr; args} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_constr buffer constr;
|
2019-05-17 18:29:22 +04:00
|
|
|
match args with
|
|
|
|
None -> ()
|
2019-10-15 23:03:46 +04:00
|
|
|
| Some (kwd_of, t_expr) ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_of "of";
|
2019-10-15 23:03:46 +04:00
|
|
|
print_type_expr buffer t_expr
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_sum_type buffer {value; _} =
|
|
|
|
print_nsepseq buffer "|" print_variant value
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_record_type buffer record_type =
|
|
|
|
print_injection buffer "record" print_field_decl record_type
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_type_app buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let type_name, type_tuple = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_var buffer type_name;
|
|
|
|
print_type_tuple buffer type_tuple
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_type_fun buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let type_expr_a, arrow, type_expr_b = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_type_expr buffer type_expr_a;
|
|
|
|
print_token buffer arrow "->";
|
|
|
|
print_type_expr buffer type_expr_b
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_par_type buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lpar; inside; rpar} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer lpar "(";
|
|
|
|
print_type_expr buffer inside;
|
|
|
|
print_token buffer rpar ")"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_field_decl buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {field_name; colon; field_type} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_var buffer field_name;
|
|
|
|
print_token buffer colon ":";
|
|
|
|
print_type_expr buffer field_type
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_type_tuple buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lpar; inside; rpar} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer lpar "(";
|
|
|
|
print_nsepseq buffer "," print_type_expr inside;
|
|
|
|
print_token buffer rpar ")"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_lambda_decl buffer = function
|
|
|
|
FunDecl fun_decl -> print_fun_decl buffer fun_decl
|
|
|
|
| ProcDecl proc_decl -> print_proc_decl buffer proc_decl
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_fun_decl buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_function; name; param; colon;
|
|
|
|
ret_type; kwd_is; local_decls;
|
|
|
|
block; kwd_with; return; terminator} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_function "function";
|
|
|
|
print_var buffer name;
|
|
|
|
print_parameters buffer param;
|
|
|
|
print_token buffer colon ":";
|
|
|
|
print_type_expr buffer ret_type;
|
|
|
|
print_token buffer kwd_is "is";
|
|
|
|
print_local_decls buffer local_decls;
|
|
|
|
print_block buffer block;
|
|
|
|
print_token buffer kwd_with "with";
|
|
|
|
print_expr buffer return;
|
|
|
|
print_terminator buffer terminator
|
|
|
|
|
|
|
|
and print_proc_decl buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_procedure; name; param; kwd_is;
|
|
|
|
local_decls; block; terminator} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_procedure "procedure";
|
|
|
|
print_var buffer name;
|
|
|
|
print_parameters buffer param;
|
|
|
|
print_token buffer kwd_is "is";
|
|
|
|
print_local_decls buffer local_decls;
|
|
|
|
print_block buffer block;
|
|
|
|
print_terminator buffer terminator
|
|
|
|
|
|
|
|
and print_parameters buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lpar; inside; rpar} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer lpar "(";
|
|
|
|
print_nsepseq buffer ";" print_param_decl inside;
|
|
|
|
print_token buffer rpar ")"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_param_decl buffer = function
|
|
|
|
ParamConst param_const -> print_param_const buffer param_const
|
|
|
|
| ParamVar param_var -> print_param_var buffer param_var
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_param_const buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_const; var; colon; param_type} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_const "const";
|
|
|
|
print_var buffer var;
|
|
|
|
print_token buffer colon ":";
|
|
|
|
print_type_expr buffer param_type
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_param_var buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_var; var; colon; param_type} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_var "var";
|
|
|
|
print_var buffer var;
|
|
|
|
print_token buffer colon ":";
|
|
|
|
print_type_expr buffer param_type
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_block buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {opening; statements; terminator; closing} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_block_opening buffer opening;
|
|
|
|
print_statements buffer statements;
|
|
|
|
print_terminator buffer terminator;
|
|
|
|
print_block_closing buffer closing
|
|
|
|
|
|
|
|
and print_block_opening buffer = function
|
|
|
|
Block (kwd_block, lbrace) ->
|
|
|
|
print_token buffer kwd_block "block";
|
|
|
|
print_token buffer lbrace "{"
|
|
|
|
| Begin kwd_begin ->
|
|
|
|
print_token buffer kwd_begin "begin"
|
|
|
|
|
|
|
|
and print_block_closing buffer = function
|
|
|
|
Block rbrace -> print_token buffer rbrace "}"
|
|
|
|
| End kwd_end -> print_token buffer kwd_end "end"
|
|
|
|
|
|
|
|
and print_local_decls buffer sequence =
|
|
|
|
List.iter (print_local_decl buffer) sequence
|
|
|
|
|
|
|
|
and print_local_decl buffer = function
|
|
|
|
LocalFun decl -> print_fun_decl buffer decl
|
|
|
|
| LocalProc decl -> print_proc_decl buffer decl
|
|
|
|
| LocalData decl -> print_data_decl buffer decl
|
|
|
|
|
|
|
|
and print_data_decl buffer = function
|
|
|
|
LocalConst decl -> print_const_decl buffer decl
|
|
|
|
| LocalVar decl -> print_var_decl buffer decl
|
|
|
|
|
|
|
|
and print_var_decl buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_var; name; colon; var_type;
|
|
|
|
assign; init; terminator} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_var "var";
|
|
|
|
print_var buffer name;
|
|
|
|
print_token buffer colon ":";
|
|
|
|
print_type_expr buffer var_type;
|
|
|
|
print_token buffer assign ":=";
|
|
|
|
print_expr buffer init;
|
|
|
|
print_terminator buffer terminator
|
|
|
|
|
|
|
|
and print_statements buffer sequence =
|
|
|
|
print_nsepseq buffer ";" print_statement sequence
|
|
|
|
|
|
|
|
and print_statement buffer = function
|
|
|
|
Instr instr -> print_instruction buffer instr
|
|
|
|
| Data data -> print_data_decl buffer data
|
|
|
|
|
|
|
|
and print_instruction buffer = function
|
|
|
|
Single instr -> print_single_instr buffer instr
|
|
|
|
| Block block -> print_block buffer block
|
|
|
|
|
|
|
|
and print_single_instr buffer = function
|
|
|
|
Cond {value; _} -> print_conditional buffer value
|
|
|
|
| CaseInstr {value; _} -> print_case_instr buffer value
|
|
|
|
| Assign assign -> print_assignment buffer assign
|
|
|
|
| Loop loop -> print_loop buffer loop
|
|
|
|
| ProcCall fun_call -> print_fun_call buffer fun_call
|
|
|
|
| Skip kwd_skip -> print_token buffer kwd_skip "skip"
|
|
|
|
| RecordPatch {value; _} -> print_record_patch buffer value
|
|
|
|
| MapPatch {value; _} -> print_map_patch buffer value
|
|
|
|
| SetPatch {value; _} -> print_set_patch buffer value
|
|
|
|
| MapRemove {value; _} -> print_map_remove buffer value
|
|
|
|
| SetRemove {value; _} -> print_set_remove buffer value
|
|
|
|
|
|
|
|
and print_conditional buffer node =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_if; test; kwd_then; ifso; terminator;
|
|
|
|
kwd_else; ifnot} = node in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_if "if";
|
|
|
|
print_expr buffer test;
|
|
|
|
print_token buffer kwd_then "then";
|
|
|
|
print_if_clause buffer ifso;
|
|
|
|
print_terminator buffer terminator;
|
|
|
|
print_token buffer kwd_else "else";
|
|
|
|
print_if_clause buffer ifnot
|
|
|
|
|
|
|
|
and print_if_clause buffer = function
|
|
|
|
ClauseInstr instr -> print_instruction buffer instr
|
2019-05-13 00:56:22 +04:00
|
|
|
| ClauseBlock {value; _} ->
|
|
|
|
let {lbrace; inside; rbrace} = value in
|
|
|
|
let statements, terminator = inside in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer lbrace "{";
|
|
|
|
print_statements buffer statements;
|
|
|
|
print_terminator buffer terminator;
|
|
|
|
print_token buffer rbrace "}"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_case_instr buffer (node : instruction case) =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_case; expr; opening;
|
|
|
|
lead_vbar; cases; closing} = node in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_case "case";
|
|
|
|
print_expr buffer expr;
|
|
|
|
print_opening buffer "of" opening;
|
|
|
|
print_token_opt buffer lead_vbar "|";
|
|
|
|
print_cases_instr buffer cases;
|
|
|
|
print_closing buffer closing
|
|
|
|
|
|
|
|
and print_token_opt buffer = function
|
2019-05-13 00:56:22 +04:00
|
|
|
None -> fun _ -> ()
|
2019-10-09 18:07:13 +04:00
|
|
|
| Some region -> print_token buffer region
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_cases_instr buffer {value; _} =
|
|
|
|
print_nsepseq buffer "|" print_case_clause_instr value
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_case_clause_instr buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {pattern; arrow; rhs} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_pattern buffer pattern;
|
|
|
|
print_token buffer arrow "->";
|
|
|
|
print_instruction buffer rhs
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_assignment buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lhs; assign; rhs} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_lhs buffer lhs;
|
|
|
|
print_token buffer assign ":=";
|
|
|
|
print_rhs buffer rhs
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_rhs buffer e = print_expr buffer e
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_lhs buffer = function
|
|
|
|
Path path -> print_path buffer path
|
|
|
|
| MapPath {value; _} -> print_map_lookup buffer value
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_loop buffer = function
|
|
|
|
While {value; _} -> print_while_loop buffer value
|
|
|
|
| For for_loop -> print_for_loop buffer for_loop
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_while_loop buffer value =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_while; cond; block} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_while "while";
|
|
|
|
print_expr buffer cond;
|
|
|
|
print_block buffer block
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_for_loop buffer = function
|
|
|
|
ForInt for_int -> print_for_int buffer for_int
|
|
|
|
| ForCollect for_collect -> print_for_collect buffer for_collect
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_for_int buffer ({value; _} : for_int reg) =
|
2019-10-13 21:51:01 +04:00
|
|
|
let {kwd_for; assign; kwd_to; bound; block} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_for "for";
|
|
|
|
print_var_assign buffer assign;
|
|
|
|
print_token buffer kwd_to "to";
|
|
|
|
print_expr buffer bound;
|
|
|
|
print_block buffer block
|
|
|
|
|
|
|
|
and print_var_assign buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {name; assign; expr} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_var buffer name;
|
|
|
|
print_token buffer assign ":=";
|
|
|
|
print_expr buffer expr
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_for_collect buffer ({value; _} : for_collect reg) =
|
2019-10-16 03:11:54 +04:00
|
|
|
let {kwd_for; var; bind_to; colon; elt_type;
|
|
|
|
kwd_in; collection; expr; block} = value in
|
|
|
|
print_token buffer kwd_for "for";
|
|
|
|
print_var buffer var;
|
|
|
|
print_bind_to buffer bind_to;
|
|
|
|
print_token buffer colon ":";
|
|
|
|
print_type_expr buffer elt_type;
|
|
|
|
print_token buffer kwd_in "in";
|
|
|
|
print_collection buffer collection;
|
|
|
|
print_expr buffer expr;
|
|
|
|
print_block buffer block
|
|
|
|
|
|
|
|
and print_collection buffer = function
|
|
|
|
Map kwd_map ->
|
|
|
|
print_token buffer kwd_map "map"
|
|
|
|
| Set kwd_set ->
|
|
|
|
print_token buffer kwd_set "set"
|
|
|
|
| List kwd_list ->
|
|
|
|
print_token buffer kwd_list "list"
|
2019-10-09 18:07:13 +04:00
|
|
|
|
|
|
|
and print_bind_to buffer = function
|
2019-05-13 00:56:22 +04:00
|
|
|
Some (arrow, variable) ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer arrow "->";
|
|
|
|
print_var buffer variable
|
2019-05-13 00:56:22 +04:00
|
|
|
| None -> ()
|
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_expr buffer = function
|
|
|
|
ECase {value;_} -> print_case_expr buffer value
|
|
|
|
| EAnnot {value;_} -> print_annot_expr buffer value
|
|
|
|
| ELogic e -> print_logic_expr buffer e
|
|
|
|
| EArith e -> print_arith_expr buffer e
|
|
|
|
| EString e -> print_string_expr buffer e
|
|
|
|
| EList e -> print_list_expr buffer e
|
|
|
|
| ESet e -> print_set_expr buffer e
|
|
|
|
| EConstr e -> print_constr_expr buffer e
|
|
|
|
| ERecord e -> print_record_expr buffer e
|
|
|
|
| EProj e -> print_projection buffer e
|
|
|
|
| EMap e -> print_map_expr buffer e
|
|
|
|
| EVar v -> print_var buffer v
|
|
|
|
| ECall e -> print_fun_call buffer e
|
|
|
|
| EBytes b -> print_bytes buffer b
|
|
|
|
| EUnit r -> print_token buffer r "Unit"
|
|
|
|
| ETuple e -> print_tuple_expr buffer e
|
|
|
|
| EPar e -> print_par_expr buffer e
|
|
|
|
|
|
|
|
and print_annot_expr buffer (expr , type_expr) =
|
|
|
|
print_expr buffer expr;
|
|
|
|
print_type_expr buffer type_expr
|
|
|
|
|
|
|
|
and print_case_expr buffer (node : expr case) =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_case; expr; opening;
|
|
|
|
lead_vbar; cases; closing} = node in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_case "case";
|
|
|
|
print_expr buffer expr;
|
|
|
|
print_opening buffer "of" opening;
|
|
|
|
print_token_opt buffer lead_vbar "|";
|
|
|
|
print_cases_expr buffer cases;
|
|
|
|
print_closing buffer closing
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_cases_expr buffer {value; _} =
|
|
|
|
print_nsepseq buffer "|" print_case_clause_expr value
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_case_clause_expr buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {pattern; arrow; rhs} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_pattern buffer pattern;
|
|
|
|
print_token buffer arrow "->";
|
|
|
|
print_expr buffer rhs
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_map_expr buffer = function
|
|
|
|
MapLookUp {value; _} -> print_map_lookup buffer value
|
|
|
|
| MapInj inj -> print_injection buffer "map" print_binding inj
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_set_expr buffer = function
|
|
|
|
SetInj inj -> print_injection buffer "set" print_expr inj
|
|
|
|
| SetMem mem -> print_set_membership buffer mem
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_set_membership buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {set; kwd_contains; element} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer set;
|
|
|
|
print_token buffer kwd_contains "contains";
|
|
|
|
print_expr buffer element
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_map_lookup buffer {path; index} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lbracket; inside; rbracket} = index.value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_path buffer path;
|
|
|
|
print_token buffer lbracket "[";
|
|
|
|
print_expr buffer inside;
|
|
|
|
print_token buffer rbracket "]"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_path buffer = function
|
|
|
|
Name var -> print_var buffer var
|
|
|
|
| Path path -> print_projection buffer path
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_logic_expr buffer = function
|
|
|
|
BoolExpr e -> print_bool_expr buffer e
|
|
|
|
| CompExpr e -> print_comp_expr buffer e
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_bool_expr buffer = function
|
2019-05-13 00:56:22 +04:00
|
|
|
Or {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "||";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| And {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "&&";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Not {value = {op; arg}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer op "not";
|
|
|
|
print_expr buffer arg
|
|
|
|
| False region ->
|
|
|
|
print_token buffer region "False"
|
|
|
|
| True region ->
|
|
|
|
print_token buffer region "True"
|
|
|
|
|
|
|
|
and print_comp_expr buffer = function
|
2019-05-13 00:56:22 +04:00
|
|
|
Lt {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "<";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Leq {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "<=";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Gt {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op ">";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Geq {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op ">=";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Equal {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "=";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Neq {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "=/=";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_arith_expr buffer = function
|
2019-05-13 00:56:22 +04:00
|
|
|
Add {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "+";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Sub {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "-";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Mult {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "*";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Div {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "/";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Mod {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "mod";
|
|
|
|
print_expr buffer arg2
|
2019-05-13 00:56:22 +04:00
|
|
|
| Neg {value = {op; arg}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer op "-";
|
|
|
|
print_expr buffer arg
|
2019-05-13 00:56:22 +04:00
|
|
|
| Int i
|
|
|
|
| Nat i
|
2019-10-09 18:07:13 +04:00
|
|
|
| Mtz i -> print_int buffer i
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_string_expr buffer = function
|
2019-05-13 00:56:22 +04:00
|
|
|
Cat {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "^";
|
|
|
|
print_expr buffer arg2
|
|
|
|
| String s ->
|
|
|
|
print_string buffer s
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_list_expr buffer = function
|
2019-05-13 00:56:22 +04:00
|
|
|
Cons {value = {arg1; op; arg2}; _} ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer arg1;
|
|
|
|
print_token buffer op "#";
|
|
|
|
print_expr buffer arg2
|
|
|
|
| List e -> print_injection buffer "list" print_expr e
|
|
|
|
| Nil e -> print_nil buffer e
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_constr_expr buffer = function
|
|
|
|
SomeApp e -> print_some_app buffer e
|
|
|
|
| NoneExpr e -> print_none_expr buffer e
|
|
|
|
| ConstrApp e -> print_constr_app buffer e
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_record_expr buffer e =
|
|
|
|
print_injection buffer "record" print_field_assign e
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_field_assign buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {field_name; equal; field_expr} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_var buffer field_name;
|
|
|
|
print_token buffer equal "=";
|
|
|
|
print_expr buffer field_expr
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_projection buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {struct_name; selector; field_path} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_var buffer struct_name;
|
|
|
|
print_token buffer selector ".";
|
|
|
|
print_field_path buffer field_path
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_field_path buffer sequence =
|
|
|
|
print_nsepseq buffer "." print_selection sequence
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_selection buffer = function
|
|
|
|
FieldName name -> print_var buffer name
|
|
|
|
| Component int -> print_int buffer int
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_record_patch buffer node =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_patch; path; kwd_with; record_inj} = node in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_patch "patch";
|
|
|
|
print_path buffer path;
|
|
|
|
print_token buffer kwd_with "with";
|
|
|
|
print_record_expr buffer record_inj
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_set_patch buffer node =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_patch; path; kwd_with; set_inj} = node in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_patch "patch";
|
|
|
|
print_path buffer path;
|
|
|
|
print_token buffer kwd_with "with";
|
|
|
|
print_injection buffer "set" print_expr set_inj
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_map_patch buffer node =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_patch; path; kwd_with; map_inj} = node in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_patch "patch";
|
|
|
|
print_path buffer path;
|
|
|
|
print_token buffer kwd_with "with";
|
|
|
|
print_injection buffer "map" print_binding map_inj
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_map_remove buffer node =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_remove; key; kwd_from; kwd_map; map} = node in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_remove "remove";
|
|
|
|
print_expr buffer key;
|
|
|
|
print_token buffer kwd_from "from";
|
|
|
|
print_token buffer kwd_map "map";
|
|
|
|
print_path buffer map
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_set_remove buffer node =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {kwd_remove; element; kwd_from; kwd_set; set} = node in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd_remove "remove";
|
|
|
|
print_expr buffer element;
|
|
|
|
print_token buffer kwd_from "from";
|
|
|
|
print_token buffer kwd_set "set";
|
|
|
|
print_path buffer set
|
2019-05-13 00:56:22 +04:00
|
|
|
|
|
|
|
and print_injection :
|
2019-10-09 18:07:13 +04:00
|
|
|
'a.Buffer.t -> string -> (Buffer.t -> 'a -> unit) ->
|
|
|
|
'a injection reg -> unit =
|
|
|
|
fun buffer kwd print {value; _} ->
|
2019-05-13 00:56:22 +04:00
|
|
|
let {opening; elements; terminator; closing} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_opening buffer kwd opening;
|
|
|
|
print_sepseq buffer ";" print elements;
|
|
|
|
print_terminator buffer terminator;
|
|
|
|
print_closing buffer closing
|
|
|
|
|
|
|
|
and print_opening buffer lexeme = function
|
|
|
|
Kwd kwd ->
|
|
|
|
print_token buffer kwd lexeme
|
2019-05-13 00:56:22 +04:00
|
|
|
| KwdBracket (kwd, lbracket) ->
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer kwd lexeme;
|
|
|
|
print_token buffer lbracket "{"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_closing buffer = function
|
|
|
|
RBracket rbracket -> print_token buffer rbracket "}"
|
|
|
|
| End kwd_end -> print_token buffer kwd_end "end"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_binding buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {source; arrow; image} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_expr buffer source;
|
|
|
|
print_token buffer arrow "->";
|
|
|
|
print_expr buffer image
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-15 23:03:46 +04:00
|
|
|
and print_tuple_expr buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lpar; inside; rpar} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer lpar "(";
|
|
|
|
print_nsepseq buffer "," print_expr inside;
|
|
|
|
print_token buffer rpar ")"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_nil buffer value = print_token buffer value "nil"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_none_expr buffer value = print_token buffer value "None"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_fun_call buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let fun_name, arguments = value in
|
2019-10-15 23:03:46 +04:00
|
|
|
print_var buffer fun_name;
|
|
|
|
print_tuple_expr buffer arguments
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_constr_app buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let constr, arguments = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_constr buffer constr;
|
2019-06-11 19:10:27 +04:00
|
|
|
match arguments with
|
|
|
|
None -> ()
|
2019-10-15 23:03:46 +04:00
|
|
|
| Some args -> print_tuple_expr buffer args
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_some_app buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let c_Some, arguments = value in
|
2019-10-15 23:03:46 +04:00
|
|
|
print_token buffer c_Some "Some";
|
|
|
|
print_tuple_expr buffer arguments
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_par_expr buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lpar; inside; rpar} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer lpar "(";
|
|
|
|
print_expr buffer inside;
|
|
|
|
print_token buffer rpar ")"
|
|
|
|
|
|
|
|
and print_pattern buffer = function
|
|
|
|
PCons {value; _} -> print_nsepseq buffer "#" print_pattern value
|
|
|
|
| PVar var -> print_var buffer var
|
|
|
|
| PWild wild -> print_token buffer wild "_"
|
|
|
|
| PInt i -> print_int buffer i
|
2019-10-15 23:03:46 +04:00
|
|
|
| PNat n -> print_nat buffer n
|
2019-10-09 18:07:13 +04:00
|
|
|
| PBytes b -> print_bytes buffer b
|
|
|
|
| PString s -> print_string buffer s
|
|
|
|
| PUnit region -> print_token buffer region "Unit"
|
|
|
|
| PFalse region -> print_token buffer region "False"
|
|
|
|
| PTrue region -> print_token buffer region "True"
|
|
|
|
| PNone region -> print_token buffer region "None"
|
|
|
|
| PSome psome -> print_psome buffer psome
|
|
|
|
| PList pattern -> print_list_pattern buffer pattern
|
|
|
|
| PTuple ptuple -> print_ptuple buffer ptuple
|
|
|
|
| PConstr pattern -> print_constr_pattern buffer pattern
|
|
|
|
|
|
|
|
and print_constr_pattern buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let (constr, args) = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_constr buffer constr;
|
2019-06-13 18:57:40 +04:00
|
|
|
match args with
|
|
|
|
None -> ()
|
2019-10-09 18:07:13 +04:00
|
|
|
| Some tuple -> print_ptuple buffer tuple
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_psome buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let c_Some, patterns = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer c_Some "Some";
|
|
|
|
print_patterns buffer patterns
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_patterns buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lpar; inside; rpar} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer lpar "(";
|
|
|
|
print_pattern buffer inside;
|
|
|
|
print_token buffer rpar ")"
|
|
|
|
|
|
|
|
and print_list_pattern buffer = function
|
|
|
|
Sugar sugar ->
|
|
|
|
print_injection buffer "list" print_pattern sugar
|
|
|
|
| PNil kwd_nil ->
|
|
|
|
print_token buffer kwd_nil "nil"
|
|
|
|
| Raw raw ->
|
|
|
|
print_raw buffer raw
|
|
|
|
|
|
|
|
and print_raw buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lpar; inside; rpar} = value in
|
|
|
|
let head, cons, tail = inside in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer lpar "(";
|
|
|
|
print_pattern buffer head;
|
|
|
|
print_token buffer cons "#";
|
|
|
|
print_pattern buffer tail;
|
|
|
|
print_token buffer rpar ")"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_ptuple buffer {value; _} =
|
2019-05-13 00:56:22 +04:00
|
|
|
let {lpar; inside; rpar} = value in
|
2019-10-09 18:07:13 +04:00
|
|
|
print_token buffer lpar "(";
|
|
|
|
print_nsepseq buffer "," print_pattern inside;
|
|
|
|
print_token buffer rpar ")"
|
2019-05-13 00:56:22 +04:00
|
|
|
|
2019-10-09 18:07:13 +04:00
|
|
|
and print_terminator buffer = function
|
|
|
|
Some semi -> print_token buffer semi ";"
|
2019-05-13 00:56:22 +04:00
|
|
|
| None -> ()
|
2019-10-09 18:07:13 +04:00
|
|
|
|
|
|
|
(* Conversion to string *)
|
|
|
|
|
|
|
|
let to_string printer node =
|
|
|
|
let buffer = Buffer.create 131 in
|
|
|
|
let () = printer buffer node
|
|
|
|
in Buffer.contents buffer
|
|
|
|
|
|
|
|
let tokens_to_string = to_string print_tokens
|
|
|
|
let path_to_string = to_string print_path
|
|
|
|
let pattern_to_string = to_string print_pattern
|
|
|
|
let instruction_to_string = to_string print_instruction
|
2019-10-13 01:42:26 +04:00
|
|
|
|
|
|
|
(* Pretty-printing the AST *)
|
|
|
|
|
|
|
|
let mk_pad len rank pc =
|
|
|
|
pc ^ (if rank = len-1 then "`-- " else "|-- "),
|
|
|
|
pc ^ (if rank = len-1 then " " else "| ")
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
let pp_ident buffer ~pad:(pd,_) name =
|
2019-10-13 01:42:26 +04:00
|
|
|
let node = sprintf "%s%s\n" pd name
|
|
|
|
in Buffer.add_string buffer node
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
let pp_string buffer = pp_ident buffer
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
let pp_node buffer = pp_ident buffer
|
|
|
|
|
|
|
|
let rec pp_ast buffer ~pad:(_,pc as pad) {decl; _} =
|
|
|
|
let apply len rank =
|
|
|
|
let pad = mk_pad len rank pc in
|
|
|
|
pp_declaration buffer ~pad in
|
|
|
|
let decls = Utils.nseq_to_list decl in
|
|
|
|
pp_node buffer ~pad "<ast>";
|
|
|
|
List.iteri (List.length decls |> apply) decls
|
|
|
|
|
|
|
|
and pp_declaration buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
TypeDecl {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "TypeDecl";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 2 0 pc) value.name.value;
|
|
|
|
pp_type_expr buffer ~pad:(mk_pad 2 1 pc) value.type_expr
|
|
|
|
| ConstDecl {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ConstDecl";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_const_decl buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
| LambdaDecl lamb ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "LambdaDecl";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_lambda_decl buffer ~pad:(mk_pad 1 0 pc) lamb
|
|
|
|
|
|
|
|
and pp_const_decl buffer ~pad:(_,pc) decl =
|
|
|
|
pp_ident buffer ~pad:(mk_pad 3 0 pc) decl.name.value;
|
|
|
|
pp_type_expr buffer ~pad:(mk_pad 3 1 pc) decl.const_type;
|
|
|
|
pp_expr buffer ~pad:(mk_pad 3 2 pc) decl.init
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_type_expr buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
TProd cartesian ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "TProd";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_cartesian buffer ~pad cartesian
|
|
|
|
| TAlias {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "TAlias";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
| TPar {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "TPar";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_type_expr buffer ~pad:(mk_pad 1 0 pc) value.inside
|
|
|
|
| TApp {value=name,tuple; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "TApp";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 1 0 pc) name.value;
|
|
|
|
pp_type_tuple buffer ~pad:(mk_pad 2 1 pc) tuple
|
|
|
|
| TFun {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "TFun";
|
2019-10-13 01:42:26 +04:00
|
|
|
let apply len rank =
|
|
|
|
let pad = mk_pad len rank pc in
|
|
|
|
pp_type_expr buffer ~pad in
|
|
|
|
let domain, _, range = value in
|
|
|
|
List.iteri (apply 2) [domain; range]
|
|
|
|
| TSum {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "TSum";
|
2019-10-13 01:42:26 +04:00
|
|
|
let apply len rank variant =
|
|
|
|
let pad = mk_pad len rank pc in
|
|
|
|
pp_variant buffer ~pad variant.value in
|
|
|
|
let variants = Utils.nsepseq_to_list value in
|
|
|
|
List.iteri (List.length variants |> apply) variants
|
|
|
|
| TRecord {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "TRecord";
|
2019-10-13 01:42:26 +04:00
|
|
|
let apply len rank field_decl =
|
|
|
|
pp_field_decl buffer ~pad:(mk_pad len rank pc)
|
|
|
|
field_decl.value in
|
|
|
|
let fields = Utils.sepseq_to_list value.elements in
|
|
|
|
List.iteri (List.length fields |> apply) fields
|
|
|
|
|
|
|
|
and pp_cartesian buffer ~pad:(_,pc) {value; _} =
|
|
|
|
let apply len rank =
|
|
|
|
pp_type_expr buffer ~pad:(mk_pad len rank pc) in
|
|
|
|
let components = Utils.nsepseq_to_list value
|
|
|
|
in List.iteri (List.length components |> apply) components
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_variant buffer ~pad:(_,pc as pad) {constr; args} =
|
|
|
|
pp_node buffer ~pad constr.value;
|
2019-10-13 01:42:26 +04:00
|
|
|
match args with
|
|
|
|
None -> ()
|
2019-10-16 03:11:54 +04:00
|
|
|
| Some (_,c) ->
|
|
|
|
pp_type_expr buffer ~pad:(mk_pad 1 0 pc) c
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_field_decl buffer ~pad:(_,pc as pad) decl =
|
|
|
|
pp_node buffer ~pad decl.field_name.value;
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_type_expr buffer ~pad:(mk_pad 1 0 pc) decl.field_type
|
|
|
|
|
|
|
|
and pp_type_tuple buffer ~pad:(_,pc) {value; _} =
|
|
|
|
let components = Utils.nsepseq_to_list value.inside in
|
|
|
|
let apply len rank =
|
|
|
|
pp_type_expr buffer ~pad:(mk_pad len rank pc)
|
|
|
|
in List.iteri (List.length components |> apply) components
|
|
|
|
|
|
|
|
and pp_lambda_decl buffer ~pad = function
|
|
|
|
FunDecl {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "FunDecl";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_fun_decl buffer ~pad value
|
|
|
|
| ProcDecl {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ProcDecl";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_proc_decl buffer ~pad value
|
|
|
|
|
|
|
|
and pp_fun_decl buffer ~pad:(_,pc) decl =
|
|
|
|
let () =
|
|
|
|
let pad = mk_pad 6 0 pc in
|
|
|
|
pp_ident buffer ~pad decl.name.value in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let pad = mk_pad 6 1 pc in
|
|
|
|
pp_node buffer ~pad "<parameters>";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_parameters buffer ~pad decl.param in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let _, pc as pad = mk_pad 6 2 pc in
|
|
|
|
pp_node buffer ~pad "<return type>";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_type_expr buffer ~pad:(mk_pad 1 0 pc) decl.ret_type in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let pad = mk_pad 6 3 pc in
|
|
|
|
pp_node buffer ~pad "<local declarations>";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_local_decls buffer ~pad decl.local_decls in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let pad = mk_pad 6 4 pc in
|
|
|
|
pp_node buffer ~pad "<block>";
|
2019-10-13 01:42:26 +04:00
|
|
|
let statements = decl.block.value.statements in
|
|
|
|
pp_statements buffer ~pad statements in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let _, pc as pad = mk_pad 6 5 pc in
|
|
|
|
pp_node buffer ~pad "<return>";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 1 0 pc) decl.return
|
|
|
|
in ()
|
|
|
|
|
|
|
|
and pp_parameters buffer ~pad:(_,pc) {value; _} =
|
|
|
|
let params = Utils.nsepseq_to_list value.inside in
|
|
|
|
let arity = List.length params in
|
|
|
|
let apply len rank =
|
|
|
|
pp_param_decl buffer ~pad:(mk_pad len rank pc)
|
|
|
|
in List.iteri (apply arity) params
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_param_decl buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
ParamConst {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ParamConst";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 2 0 pc) value.var.value;
|
|
|
|
pp_type_expr buffer ~pad:(mk_pad 2 1 pc) value.param_type
|
|
|
|
| ParamVar {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ParamVar";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 2 0 pc) value.var.value;
|
|
|
|
pp_type_expr buffer ~pad:(mk_pad 2 1 pc) value.param_type
|
|
|
|
|
|
|
|
and pp_statements buffer ~pad:(_,pc) statements =
|
|
|
|
let statements = Utils.nsepseq_to_list statements in
|
|
|
|
let length = List.length statements in
|
|
|
|
let apply len rank =
|
|
|
|
pp_statement buffer ~pad:(mk_pad len rank pc)
|
|
|
|
in List.iteri (apply length) statements
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_statement buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
Instr instr ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Instr";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_instruction buffer ~pad:(mk_pad 1 0 pc) instr
|
|
|
|
| Data data_decl ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Data";
|
|
|
|
pp_data_decl buffer ~pad:(mk_pad 1 0 pc) data_decl
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_instruction buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
Single single_instr ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Single";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_single_instr buffer ~pad:(mk_pad 1 0 pc) single_instr
|
|
|
|
| Block {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Block";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_statements buffer ~pad value.statements
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_single_instr buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
Cond {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Cond";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_conditional buffer ~pad value
|
|
|
|
| CaseInstr {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "CaseInstr";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_case pp_instruction buffer ~pad value
|
|
|
|
| Assign {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Assign";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_assignment buffer ~pad value
|
|
|
|
| Loop loop ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Loop";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_loop buffer ~pad:(mk_pad 1 0 pc) loop
|
2019-10-13 21:51:01 +04:00
|
|
|
| ProcCall {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ProcCall";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_fun_call buffer ~pad value
|
2019-10-13 01:42:26 +04:00
|
|
|
| Skip _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Skip"
|
2019-10-13 01:42:26 +04:00
|
|
|
| RecordPatch {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "RecordPatch";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_record_patch buffer ~pad value
|
2019-10-13 01:42:26 +04:00
|
|
|
| MapPatch {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "MapPatch";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_map_patch buffer ~pad value
|
2019-10-13 01:42:26 +04:00
|
|
|
| SetPatch {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "SetPatch";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_set_patch buffer ~pad value
|
2019-10-13 01:42:26 +04:00
|
|
|
| MapRemove {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "MapRemove";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_map_remove buffer ~pad value
|
2019-10-13 01:42:26 +04:00
|
|
|
| SetRemove {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "SetRemove";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_set_remove buffer ~pad value
|
2019-10-13 01:42:26 +04:00
|
|
|
|
|
|
|
and pp_conditional buffer ~pad:(_,pc) cond =
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let _, pc as pad = mk_pad 3 0 pc in
|
|
|
|
pp_node buffer ~pad "<condition>";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 1 0 pc) cond.test in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let _, pc as pad = mk_pad 3 1 pc in
|
|
|
|
pp_node buffer ~pad "<true>";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_if_clause buffer ~pad:(mk_pad 1 0 pc) cond.ifso in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let _, pc as pad = mk_pad 3 2 pc in
|
|
|
|
pp_node buffer ~pad "<false>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_if_clause buffer ~pad:(mk_pad 1 0 pc) cond.ifnot
|
2019-10-13 01:42:26 +04:00
|
|
|
in ()
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_if_clause buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
ClauseInstr instr ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ClauseInstr";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_instruction buffer ~pad:(mk_pad 1 0 pc) instr
|
|
|
|
| ClauseBlock {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ClauseBlock";
|
2019-10-13 01:42:26 +04:00
|
|
|
let statements, _ = value.inside in
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_statements buffer ~pad statements
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-15 23:03:46 +04:00
|
|
|
and pp_case :
|
|
|
|
'a.(Buffer.t -> pad:(string*string) -> 'a -> unit)
|
|
|
|
-> Buffer.t -> pad:(string*string) -> 'a case -> unit =
|
|
|
|
fun printer buffer ~pad:(_,pc) case ->
|
|
|
|
let clauses = Utils.nsepseq_to_list case.cases.value in
|
|
|
|
let clauses = List.map (fun {value; _} -> value) clauses in
|
2019-10-16 03:11:54 +04:00
|
|
|
let length = List.length clauses + 1 in
|
2019-10-15 23:03:46 +04:00
|
|
|
let apply len rank =
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_case_clause printer buffer ~pad:(mk_pad len (rank+1) pc)
|
2019-10-15 23:03:46 +04:00
|
|
|
in pp_expr buffer ~pad:(mk_pad length 0 pc) case.expr;
|
|
|
|
List.iteri (apply length) clauses
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-15 23:03:46 +04:00
|
|
|
and pp_case_clause :
|
|
|
|
'a.(Buffer.t -> pad:(string*string) -> 'a -> unit)
|
|
|
|
-> Buffer.t -> pad:(string*string) -> 'a case_clause -> unit =
|
2019-10-16 03:11:54 +04:00
|
|
|
fun printer buffer ~pad:(_,pc as pad) clause ->
|
|
|
|
pp_node buffer ~pad "<clause>";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_pattern buffer ~pad:(mk_pad 2 0 pc) clause.pattern;
|
|
|
|
printer buffer ~pad:(mk_pad 2 1 pc) clause.rhs
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_pattern buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
PNone _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PNone"
|
2019-10-13 01:42:26 +04:00
|
|
|
| PSome {value=_,{value=par; _}; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PSome";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_pattern buffer ~pad:(mk_pad 1 0 pc) par.inside
|
|
|
|
| PWild _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PWild"
|
2019-10-13 01:42:26 +04:00
|
|
|
| PConstr {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PConstr";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_constr_pattern buffer ~pad:(mk_pad 1 0 pc) value
|
2019-10-13 01:42:26 +04:00
|
|
|
| PCons {value; _} ->
|
2019-10-15 23:03:46 +04:00
|
|
|
let patterns = Utils.nsepseq_to_list value in
|
|
|
|
let length = List.length patterns in
|
|
|
|
let apply len rank =
|
|
|
|
pp_pattern buffer ~pad:(mk_pad len rank pc) in
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PCons";
|
2019-10-15 23:03:46 +04:00
|
|
|
List.iteri (apply length) patterns
|
2019-10-13 01:42:26 +04:00
|
|
|
| PVar {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PVar";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
| PInt {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PInt";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_int buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| PNat {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PNat";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_int buffer ~pad value
|
2019-10-13 01:42:26 +04:00
|
|
|
| PBytes {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PBytes";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_bytes buffer ~pad value
|
|
|
|
| PString {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PString";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
| PUnit _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PUnit"
|
2019-10-13 01:42:26 +04:00
|
|
|
| PFalse _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PFalse"
|
2019-10-13 01:42:26 +04:00
|
|
|
| PTrue _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PTrue"
|
2019-10-13 01:42:26 +04:00
|
|
|
| PList plist ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PList";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_plist buffer ~pad:(mk_pad 1 0 pc) plist
|
|
|
|
| PTuple {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PTuple";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_tuple_pattern buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
|
|
|
|
and pp_bytes buffer ~pad:(_,pc) (lexeme, hex) =
|
|
|
|
pp_string buffer ~pad:(mk_pad 2 0 pc) lexeme;
|
|
|
|
pp_string buffer ~pad:(mk_pad 2 1 pc) (Hex.to_string hex)
|
|
|
|
|
|
|
|
and pp_int buffer ~pad:(_,pc) (lexeme, z) =
|
|
|
|
pp_string buffer ~pad:(mk_pad 2 0 pc) lexeme;
|
|
|
|
pp_string buffer ~pad:(mk_pad 2 1 pc) (Z.to_string z)
|
|
|
|
|
2019-10-15 23:03:46 +04:00
|
|
|
and pp_constr_pattern buffer ~pad = function
|
2019-10-13 01:42:26 +04:00
|
|
|
{value; _}, None ->
|
|
|
|
pp_ident buffer ~pad value
|
|
|
|
| {value=id; _}, Some {value=ptuple; _} ->
|
|
|
|
pp_ident buffer ~pad id;
|
|
|
|
pp_tuple_pattern buffer ~pad ptuple
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_plist buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
Sugar {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Sugar";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_injection pp_pattern buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
| PNil _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "PNil"
|
2019-10-13 01:42:26 +04:00
|
|
|
| Raw {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Raw";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_raw buffer ~pad:(mk_pad 1 0 pc) value.inside
|
|
|
|
|
|
|
|
and pp_raw buffer ~pad:(_,pc) (head, _, tail) =
|
|
|
|
pp_pattern buffer ~pad:(mk_pad 2 0 pc) head;
|
|
|
|
pp_pattern buffer ~pad:(mk_pad 2 1 pc) tail
|
|
|
|
|
2019-10-13 21:51:01 +04:00
|
|
|
and pp_injection :
|
|
|
|
'a.(Buffer.t -> pad:(string*string) -> 'a -> unit)
|
|
|
|
-> Buffer.t -> pad:(string*string) -> 'a injection -> unit =
|
|
|
|
fun printer buffer ~pad:(_,pc) inj ->
|
2019-10-13 01:42:26 +04:00
|
|
|
let elements = Utils.sepseq_to_list inj.elements in
|
|
|
|
let length = List.length elements in
|
2019-10-15 23:03:46 +04:00
|
|
|
let apply len rank = printer buffer ~pad:(mk_pad len rank pc)
|
2019-10-13 01:42:26 +04:00
|
|
|
in List.iteri (apply length) elements
|
|
|
|
|
|
|
|
and pp_tuple_pattern buffer ~pad:(_,pc) tuple =
|
|
|
|
let patterns = Utils.nsepseq_to_list tuple.inside in
|
|
|
|
let length = List.length patterns in
|
|
|
|
let apply len rank =
|
|
|
|
pp_pattern buffer ~pad:(mk_pad len rank pc)
|
|
|
|
in List.iteri (apply length) patterns
|
|
|
|
|
|
|
|
and pp_assignment buffer ~pad:(_,pc) asgn =
|
|
|
|
pp_lhs buffer ~pad:(mk_pad 2 0 pc) asgn.lhs;
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 2 1 pc) asgn.rhs
|
|
|
|
|
|
|
|
and pp_lhs buffer ~pad:(_,pc as pad) = function
|
|
|
|
Path path ->
|
|
|
|
pp_node buffer ~pad "Path";
|
|
|
|
pp_path buffer ~pad:(mk_pad 1 0 pc) path
|
|
|
|
| MapPath {value; _} ->
|
|
|
|
pp_node buffer ~pad "MapPath";
|
|
|
|
pp_map_lookup buffer ~pad value
|
|
|
|
|
|
|
|
and pp_path buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
Name {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Name";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
| Path {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Path";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_projection buffer ~pad value
|
|
|
|
|
|
|
|
and pp_projection buffer ~pad:(_,pc) proj =
|
|
|
|
let selections = Utils.nsepseq_to_list proj.field_path in
|
|
|
|
let len = List.length selections in
|
|
|
|
let apply len rank =
|
|
|
|
pp_selection buffer ~pad:(mk_pad len rank pc) in
|
|
|
|
pp_ident buffer ~pad:(mk_pad (1+len) 0 pc) proj.struct_name.value;
|
|
|
|
List.iteri (apply len) selections
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_selection buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
FieldName {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "FieldName";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
| Component {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Component";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_int buffer ~pad value
|
|
|
|
|
|
|
|
and pp_map_lookup buffer ~pad:(_,pc) lookup =
|
|
|
|
pp_path buffer ~pad:(mk_pad 2 0 pc) lookup.path;
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 1 pc) lookup.index.value.inside
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_loop buffer ~pad:(_,pc as pad) = function
|
2019-10-13 21:51:01 +04:00
|
|
|
While {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "<while>";
|
2019-10-13 21:51:01 +04:00
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let _, pc as pad = mk_pad 2 0 pc in
|
|
|
|
pp_node buffer ~pad "<condition>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 1 0 pc) value.cond in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let pad = mk_pad 2 1 pc in
|
2019-10-13 21:51:01 +04:00
|
|
|
let statements = value.block.value.statements in
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "<statements>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_statements buffer ~pad statements
|
|
|
|
in ()
|
|
|
|
| For for_loop ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "<for>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_for_loop buffer ~pad:(mk_pad 1 0 pc) for_loop
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_for_loop buffer ~pad = function
|
2019-10-13 21:51:01 +04:00
|
|
|
ForInt {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ForInt";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_for_int buffer ~pad value
|
|
|
|
| ForCollect {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ForCollect";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_for_collect buffer ~pad value
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-13 21:51:01 +04:00
|
|
|
and pp_for_int buffer ~pad:(_,pc) for_int =
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let pad = mk_pad 3 0 pc in
|
|
|
|
pp_node buffer ~pad "<init>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_var_assign buffer ~pad for_int.assign.value in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let _, pc as pad = mk_pad 3 1 pc in
|
|
|
|
pp_node buffer ~pad "<bound>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 1 0 pc) for_int.bound in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let pad = mk_pad 3 2 pc in
|
2019-10-13 21:51:01 +04:00
|
|
|
let statements = for_int.block.value.statements in
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "<statements>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_statements buffer ~pad statements
|
|
|
|
in ()
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-13 21:51:01 +04:00
|
|
|
and pp_var_assign buffer ~pad:(_,pc) asgn =
|
|
|
|
let pad = mk_pad 2 0 pc in
|
|
|
|
pp_ident buffer ~pad asgn.name.value;
|
|
|
|
let pad = mk_pad 2 1 pc in
|
|
|
|
pp_expr buffer ~pad asgn.expr
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-13 21:51:01 +04:00
|
|
|
and pp_for_collect buffer ~pad:(_,pc) collect =
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let pad = mk_pad 4 0 pc in
|
2019-10-13 21:51:01 +04:00
|
|
|
match collect.bind_to with
|
|
|
|
None ->
|
|
|
|
pp_ident buffer ~pad collect.var.value
|
|
|
|
| Some (_, var) ->
|
|
|
|
pp_var_binding buffer ~pad (collect.var, var) in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let _, pc as pad = mk_pad 4 1 pc in
|
|
|
|
pp_node buffer ~pad "<element type>";
|
|
|
|
pp_type_expr buffer ~pad:(mk_pad 1 0 pc) collect.elt_type in
|
|
|
|
let () =
|
|
|
|
let _, pc as pad = mk_pad 4 2 pc in
|
|
|
|
pp_node buffer ~pad "<collection>";
|
|
|
|
pp_collection buffer ~pad:(mk_pad 2 0 pc) collect.collection;
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 1 0 pc) collect.expr in
|
|
|
|
let () =
|
2019-10-16 03:11:54 +04:00
|
|
|
let pad = mk_pad 4 3 pc in
|
2019-10-13 21:51:01 +04:00
|
|
|
let statements = collect.block.value.statements in
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "<statements>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_statements buffer ~pad statements
|
|
|
|
in ()
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_collection buffer ~pad = function
|
|
|
|
Map _ -> pp_string buffer ~pad "map"
|
|
|
|
| Set _ -> pp_string buffer ~pad "set"
|
|
|
|
| List _ -> pp_string buffer ~pad "list"
|
|
|
|
|
|
|
|
and pp_var_binding buffer ~pad:(_,pc as pad) (source, image) =
|
|
|
|
pp_node buffer ~pad "<binding>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 2 0 pc) source.value;
|
|
|
|
pp_ident buffer ~pad:(mk_pad 2 1 pc) image.value
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-15 23:03:46 +04:00
|
|
|
and pp_fun_call buffer ~pad:(_,pc) (name, args) =
|
2019-10-13 21:51:01 +04:00
|
|
|
let args = Utils.nsepseq_to_list args.value.inside in
|
|
|
|
let arity = List.length args in
|
|
|
|
let apply len rank =
|
|
|
|
pp_expr buffer ~pad:(mk_pad len rank pc)
|
2019-10-15 23:03:46 +04:00
|
|
|
in pp_ident buffer ~pad:(mk_pad (1+arity) 0 pc) name.value;
|
|
|
|
List.iteri (apply arity) args
|
2019-10-13 21:51:01 +04:00
|
|
|
|
|
|
|
and pp_record_patch buffer ~pad:(_,pc as pad) patch =
|
|
|
|
pp_path buffer ~pad:(mk_pad 2 0 pc) patch.path;
|
|
|
|
pp_injection pp_field_assign buffer
|
|
|
|
~pad patch.record_inj.value
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_field_assign buffer ~pad:(_,pc as pad) {value; _} =
|
|
|
|
pp_node buffer ~pad "<field assignment>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 2 0 pc) value.field_name.value;
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 1 pc) value.field_expr
|
|
|
|
|
|
|
|
and pp_map_patch buffer ~pad:(_,pc as pad) patch =
|
|
|
|
pp_path buffer ~pad:(mk_pad 2 0 pc) patch.path;
|
|
|
|
pp_injection pp_binding buffer
|
|
|
|
~pad patch.map_inj.value
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_binding buffer ~pad:(_,pc as pad) {value; _} =
|
2019-10-13 21:51:01 +04:00
|
|
|
let source, image = value.source, value.image in
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "<binding>";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 2 0 pc) source;
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 1 pc) image
|
|
|
|
|
|
|
|
and pp_set_patch buffer ~pad:(_,pc as pad) patch =
|
|
|
|
pp_path buffer ~pad:(mk_pad 2 0 pc) patch.path;
|
|
|
|
pp_injection pp_expr buffer ~pad patch.set_inj.value
|
|
|
|
|
|
|
|
and pp_map_remove buffer ~pad:(_,pc) rem =
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 0 pc) rem.key;
|
|
|
|
pp_path buffer ~pad:(mk_pad 2 1 pc) rem.map
|
|
|
|
|
|
|
|
and pp_set_remove buffer ~pad:(_,pc) rem =
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 0 pc) rem.element;
|
|
|
|
pp_path buffer ~pad:(mk_pad 2 1 pc) rem.set
|
2019-10-13 01:42:26 +04:00
|
|
|
|
|
|
|
and pp_local_decls buffer ~pad:(_,pc) decls =
|
|
|
|
let apply len rank =
|
|
|
|
pp_local_decl buffer ~pad:(mk_pad len rank pc)
|
|
|
|
in List.iteri (List.length decls |> apply) decls
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_local_decl buffer ~pad:(_,pc as pad) = function
|
2019-10-13 01:42:26 +04:00
|
|
|
LocalFun {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "LocalFun";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_fun_decl buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
| LocalProc {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "LocalProc";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_proc_decl buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
| LocalData data ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "LocalData";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_data_decl buffer ~pad:(mk_pad 1 0 pc) data
|
|
|
|
|
|
|
|
and pp_data_decl buffer ~pad = function
|
|
|
|
LocalConst {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "LocalConst";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_const_decl buffer ~pad value
|
|
|
|
| LocalVar {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "LocalVar";
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_var_decl buffer ~pad value
|
|
|
|
|
|
|
|
and pp_var_decl buffer ~pad:(_,pc) decl =
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 3 0 pc) decl.name.value;
|
2019-10-13 01:42:26 +04:00
|
|
|
pp_type_expr buffer ~pad:(mk_pad 3 1 pc) decl.var_type;
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 3 2 pc) decl.init
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_proc_decl buffer ~pad _decl =
|
|
|
|
pp_node buffer ~pad "PP_PROC_DECL"
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_expr buffer ~pad:(_,pc as pad) = function
|
2019-10-13 21:51:01 +04:00
|
|
|
ECase {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ECase";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_case pp_expr buffer ~pad value
|
2019-10-13 21:51:01 +04:00
|
|
|
| EAnnot {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EAnnot";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_annotated buffer ~pad value
|
2019-10-13 21:51:01 +04:00
|
|
|
| ELogic e_logic ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ELogic";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_e_logic buffer ~pad:(mk_pad 1 0 pc) e_logic
|
2019-10-13 21:51:01 +04:00
|
|
|
| EArith e_arith ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EArith";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_arith_expr buffer ~pad:(mk_pad 1 0 pc) e_arith
|
2019-10-13 21:51:01 +04:00
|
|
|
| EString e_string ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EString";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_string_expr buffer ~pad:(mk_pad 1 0 pc) e_string
|
2019-10-13 21:51:01 +04:00
|
|
|
| EList e_list ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EList";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_list_expr buffer ~pad:(mk_pad 1 0 pc) e_list
|
2019-10-13 21:51:01 +04:00
|
|
|
| ESet e_set ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ESet";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_set_expr buffer ~pad:(mk_pad 1 0 pc) e_set
|
2019-10-13 21:51:01 +04:00
|
|
|
| EConstr e_constr ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EConstr";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_constr_expr buffer ~pad:(mk_pad 1 0 pc) e_constr
|
|
|
|
| ERecord {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ERecord";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_injection pp_field_assign buffer ~pad value
|
2019-10-13 21:51:01 +04:00
|
|
|
| EProj {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EProj";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_projection buffer ~pad value
|
2019-10-13 21:51:01 +04:00
|
|
|
| EMap e_map ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EMap";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_map_expr buffer ~pad:(mk_pad 1 0 pc) e_map
|
2019-10-13 21:51:01 +04:00
|
|
|
| EVar {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EVar";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_ident buffer ~pad:(mk_pad 1 0 pc) value
|
2019-10-15 23:03:46 +04:00
|
|
|
| ECall {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ECall";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_fun_call buffer ~pad value
|
2019-10-13 21:51:01 +04:00
|
|
|
| EBytes {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EBytes";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_bytes buffer ~pad value
|
2019-10-13 21:51:01 +04:00
|
|
|
| EUnit _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EUnit"
|
2019-10-13 21:51:01 +04:00
|
|
|
| ETuple e_tuple ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ETuple";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_tuple_expr buffer ~pad e_tuple
|
2019-10-13 21:51:01 +04:00
|
|
|
| EPar {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "EPar";
|
2019-10-13 21:51:01 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 1 0 pc) value.inside
|
2019-10-13 01:42:26 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_list_expr buffer ~pad:(_,pc as pad) = function
|
2019-10-15 23:03:46 +04:00
|
|
|
Cons {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Cons";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 2 0 pc) value.arg1;
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 1 pc) value.arg2
|
|
|
|
| List {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "List";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_injection pp_expr buffer ~pad value
|
|
|
|
| Nil _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Nil"
|
2019-10-15 23:03:46 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_arith_expr buffer ~pad:(_,pc as pad) = function
|
2019-10-15 23:03:46 +04:00
|
|
|
Add {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Add" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Sub {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Sub" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Mult {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Mult" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Div {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Div" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Mod {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Mod" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Neg {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Neg";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 1 0 pc) value.arg;
|
|
|
|
| Int {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Int";
|
|
|
|
pp_int buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Nat {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Nat";
|
|
|
|
pp_int buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Mtz {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Mtz";
|
|
|
|
pp_int buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_set_expr buffer ~pad:(_,pc as pad) = function
|
2019-10-15 23:03:46 +04:00
|
|
|
SetInj {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "SetInj";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_injection pp_expr buffer ~pad value
|
|
|
|
| SetMem {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "SetMem";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 2 0 pc) value.set;
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 1 pc) value.element
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_e_logic buffer ~pad = function
|
2019-10-15 23:03:46 +04:00
|
|
|
BoolExpr e ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "BoolExpr";
|
|
|
|
pp_bool_expr buffer ~pad e
|
2019-10-15 23:03:46 +04:00
|
|
|
| CompExpr e ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "CompExpr";
|
|
|
|
pp_comp_expr buffer ~pad e
|
2019-10-15 23:03:46 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_bool_expr buffer ~pad:(_,pc as pad) = function
|
2019-10-15 23:03:46 +04:00
|
|
|
Or {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Or" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| And {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "And" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Not {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
let _, pc as pad = mk_pad 1 0 pc in
|
|
|
|
pp_node buffer ~pad "Not";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_expr buffer ~pad:(mk_pad 1 0 pc) value.arg
|
|
|
|
| False _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad:(mk_pad 1 0 pc) "False"
|
2019-10-15 23:03:46 +04:00
|
|
|
| True _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad:(mk_pad 1 0 pc) "True"
|
2019-10-15 23:03:46 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_comp_expr buffer ~pad = function
|
2019-10-15 23:03:46 +04:00
|
|
|
Lt {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Lt" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Leq {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Leq" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Gt {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Gt" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Geq {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Geq" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Equal {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Equal" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
| Neq {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_bin_op "Neq" buffer ~pad value
|
2019-10-15 23:03:46 +04:00
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_constr_expr buffer ~pad:(_, pc as pad) = function
|
2019-10-15 23:03:46 +04:00
|
|
|
SomeApp {value=some_region,args; _} ->
|
|
|
|
let constr = {value="Some"; region=some_region} in
|
|
|
|
let app = constr, Some args in
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "SomeApp";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_constr_app buffer ~pad app
|
|
|
|
| NoneExpr _ ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "NoneExpr"
|
2019-10-15 23:03:46 +04:00
|
|
|
| ConstrApp {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "ConstrApp";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_constr_app buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
|
|
|
|
and pp_constr_app buffer ~pad (constr, args_opt) =
|
|
|
|
pp_ident buffer ~pad constr.value;
|
|
|
|
match args_opt with
|
|
|
|
None -> ()
|
|
|
|
| Some args -> pp_tuple_expr buffer ~pad args
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_map_expr buffer ~pad = function
|
2019-10-15 23:03:46 +04:00
|
|
|
MapLookUp {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "MapLookUp";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_map_lookup buffer ~pad value
|
|
|
|
| MapInj {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "MapInj";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_injection pp_binding buffer ~pad value
|
|
|
|
|
|
|
|
and pp_tuple_expr buffer ~pad:(_,pc) {value; _} =
|
|
|
|
let exprs = Utils.nsepseq_to_list value.inside in
|
|
|
|
let length = List.length exprs in
|
|
|
|
let apply len rank =
|
|
|
|
pp_expr buffer ~pad:(mk_pad len rank pc)
|
|
|
|
in List.iteri (apply length) exprs
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_string_expr buffer ~pad:(_,pc as pad) = function
|
2019-10-15 23:03:46 +04:00
|
|
|
Cat {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "Cat";
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 0 pc) value.arg1;
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 1 pc) value.arg2;
|
2019-10-15 23:03:46 +04:00
|
|
|
| String {value; _} ->
|
2019-10-16 03:11:54 +04:00
|
|
|
pp_node buffer ~pad "String";
|
2019-10-15 23:03:46 +04:00
|
|
|
pp_string buffer ~pad:(mk_pad 1 0 pc) value
|
|
|
|
|
|
|
|
and pp_annotated buffer ~pad:(_,pc) (expr, t_expr) =
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 0 pc) expr;
|
|
|
|
pp_type_expr buffer ~pad:(mk_pad 2 1 pc) t_expr
|
|
|
|
|
2019-10-16 03:11:54 +04:00
|
|
|
and pp_bin_op node buffer ~pad:(_,pc) op =
|
|
|
|
pp_node buffer ~pad:(mk_pad 1 0 pc) node;
|
|
|
|
let _, pc = mk_pad 1 0 pc in
|
|
|
|
(pp_expr buffer ~pad:(mk_pad 2 0 pc) op.arg1;
|
|
|
|
pp_expr buffer ~pad:(mk_pad 2 1 pc) op.arg2)
|
2019-10-15 23:03:46 +04:00
|
|
|
|
2019-10-13 01:42:26 +04:00
|
|
|
let pp_ast buffer = pp_ast buffer ~pad:("","")
|