2019-03-18 20:47:11 +04:00
|
|
|
(* Abstract Syntax Tree (AST) for LIGO *)
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
[@@@warning "-30"]
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
open Utils
|
|
|
|
|
|
|
|
(* Regions
|
|
|
|
|
|
|
|
The AST carries all the regions where tokens have been found by the
|
|
|
|
lexer, plus additional regions corresponding to whole subtrees
|
|
|
|
(like entire expressions, patterns etc.). These regions are needed
|
|
|
|
for error reporting and source-to-source transformations. To make
|
|
|
|
these pervasive regions more legible, we define singleton types for
|
|
|
|
the symbols, keywords etc. with suggestive names like "kwd_and"
|
|
|
|
denoting the _region_ of the occurrence of the keyword "and".
|
|
|
|
*)
|
|
|
|
|
|
|
|
type 'a reg = 'a Region.reg
|
|
|
|
|
|
|
|
val nseq_to_region : ('a -> Region.t) -> 'a nseq -> Region.t
|
|
|
|
val nsepseq_to_region : ('a -> Region.t) -> ('a,'sep) nsepseq -> Region.t
|
|
|
|
val sepseq_to_region : ('a -> Region.t) -> ('a,'sep) sepseq -> Region.t
|
|
|
|
|
2019-03-18 20:47:11 +04:00
|
|
|
(* Keywords of LIGO *)
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
type kwd_begin = Region.t
|
|
|
|
type kwd_const = Region.t
|
2019-03-14 12:59:26 +04:00
|
|
|
type kwd_copy = Region.t
|
2019-02-26 01:29:29 +04:00
|
|
|
type kwd_down = Region.t
|
2019-03-10 16:55:24 +04:00
|
|
|
type kwd_else = Region.t
|
|
|
|
type kwd_end = Region.t
|
|
|
|
type kwd_entrypoint = Region.t
|
2019-02-28 18:46:34 +04:00
|
|
|
type kwd_fail = Region.t
|
2019-03-10 16:55:24 +04:00
|
|
|
type kwd_for = Region.t
|
|
|
|
type kwd_function = Region.t
|
2019-02-26 01:29:29 +04:00
|
|
|
type kwd_if = Region.t
|
|
|
|
type kwd_in = Region.t
|
|
|
|
type kwd_is = Region.t
|
2019-03-10 16:55:24 +04:00
|
|
|
type kwd_match = Region.t
|
|
|
|
type kwd_mod = Region.t
|
|
|
|
type kwd_not = Region.t
|
2019-02-26 01:29:29 +04:00
|
|
|
type kwd_of = Region.t
|
|
|
|
type kwd_procedure = Region.t
|
|
|
|
type kwd_record = Region.t
|
2019-03-18 21:09:15 +04:00
|
|
|
type kwd_skip = Region.t
|
2019-02-26 01:29:29 +04:00
|
|
|
type kwd_step = Region.t
|
2019-03-14 21:17:19 +04:00
|
|
|
type kwd_storage = Region.t
|
2019-03-10 16:55:24 +04:00
|
|
|
type kwd_then = Region.t
|
2019-02-26 01:29:29 +04:00
|
|
|
type kwd_to = Region.t
|
2019-03-10 16:55:24 +04:00
|
|
|
type kwd_type = Region.t
|
|
|
|
type kwd_var = Region.t
|
2019-02-26 01:29:29 +04:00
|
|
|
type kwd_while = Region.t
|
|
|
|
type kwd_with = Region.t
|
|
|
|
|
|
|
|
(* Data constructors *)
|
|
|
|
|
|
|
|
type c_False = Region.t
|
|
|
|
type c_None = Region.t
|
|
|
|
type c_Some = Region.t
|
|
|
|
type c_True = Region.t
|
|
|
|
type c_Unit = Region.t
|
|
|
|
|
|
|
|
(* Symbols *)
|
|
|
|
|
2019-03-18 20:47:11 +04:00
|
|
|
type semi = Region.t (* ";" *)
|
|
|
|
type comma = Region.t (* "," *)
|
|
|
|
type lpar = Region.t (* "(" *)
|
|
|
|
type rpar = Region.t (* ")" *)
|
|
|
|
type lbrace = Region.t (* "{" *)
|
|
|
|
type rbrace = Region.t (* "}" *)
|
|
|
|
type lbracket = Region.t (* "[" *)
|
|
|
|
type rbracket = Region.t (* "]" *)
|
|
|
|
type cons = Region.t (* "#" *)
|
|
|
|
type vbar = Region.t (* "|" *)
|
|
|
|
type arrow = Region.t (* "->" *)
|
|
|
|
type assign = Region.t (* ":=" *)
|
|
|
|
type equal = Region.t (* "=" *)
|
|
|
|
type colon = Region.t (* ":" *)
|
|
|
|
type bool_or = Region.t (* "||" *)
|
|
|
|
type bool_and = Region.t (* "&&" *)
|
|
|
|
type lt = Region.t (* "<" *)
|
|
|
|
type leq = Region.t (* "<=" *)
|
|
|
|
type gt = Region.t (* ">" *)
|
|
|
|
type geq = Region.t (* ">=" *)
|
|
|
|
type neq = Region.t (* "=/=" *)
|
|
|
|
type plus = Region.t (* "+" *)
|
|
|
|
type minus = Region.t (* "-" *)
|
|
|
|
type slash = Region.t (* "/" *)
|
|
|
|
type times = Region.t (* "*" *)
|
|
|
|
type dot = Region.t (* "." *)
|
|
|
|
type wild = Region.t (* "_" *)
|
|
|
|
type cat = Region.t (* "^" *)
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
(* Virtual tokens *)
|
|
|
|
|
|
|
|
type eof = Region.t
|
|
|
|
|
|
|
|
(* Literals *)
|
|
|
|
|
|
|
|
type variable = string reg
|
|
|
|
type fun_name = string reg
|
|
|
|
type type_name = string reg
|
|
|
|
type field_name = string reg
|
|
|
|
type map_name = string reg
|
|
|
|
type constr = string reg
|
|
|
|
|
|
|
|
(* Parentheses *)
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
type 'a par = {
|
|
|
|
lpar : lpar;
|
|
|
|
inside : 'a;
|
|
|
|
rpar : rpar
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
(* Brackets compounds *)
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
type 'a brackets = {
|
|
|
|
lbracket : lbracket;
|
|
|
|
inside : 'a;
|
|
|
|
rbracket : rbracket
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
(* Braced compounds *)
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
type 'a braces = {
|
|
|
|
lbrace : lbrace;
|
|
|
|
inside : 'a;
|
|
|
|
rbrace : rbrace
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
(* The Abstract Syntax Tree *)
|
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
type t = {
|
2019-03-11 15:51:50 +04:00
|
|
|
decl : declaration nseq;
|
|
|
|
eof : eof
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
and ast = t
|
|
|
|
|
2019-03-11 15:51:50 +04:00
|
|
|
and declaration =
|
|
|
|
TypeDecl of type_decl reg
|
|
|
|
| ConstDecl of const_decl reg
|
|
|
|
| LambdaDecl of lambda_decl
|
|
|
|
|
2019-03-10 22:41:27 +04:00
|
|
|
and const_decl = {
|
|
|
|
kwd_const : kwd_const;
|
|
|
|
name : variable;
|
|
|
|
colon : colon;
|
|
|
|
const_type : type_expr;
|
|
|
|
equal : equal;
|
|
|
|
init : expr;
|
|
|
|
terminator : semi option
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
(* Type declarations *)
|
|
|
|
|
2019-03-07 20:06:02 +04:00
|
|
|
and type_decl = {
|
|
|
|
kwd_type : kwd_type;
|
|
|
|
name : type_name;
|
|
|
|
kwd_is : kwd_is;
|
|
|
|
type_expr : type_expr;
|
|
|
|
terminator : semi option
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
and type_expr =
|
|
|
|
Prod of cartesian
|
2019-03-13 19:29:25 +04:00
|
|
|
| Sum of (variant reg, vbar) nsepseq reg
|
|
|
|
| Record of record_type reg
|
2019-02-26 01:29:29 +04:00
|
|
|
| TypeApp of (type_name * type_tuple) reg
|
2019-03-13 19:29:25 +04:00
|
|
|
| ParType of type_expr par reg
|
2019-02-26 01:29:29 +04:00
|
|
|
| TAlias of variable
|
|
|
|
|
|
|
|
and cartesian = (type_expr, times) nsepseq reg
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and variant = {
|
|
|
|
constr : constr;
|
|
|
|
kwd_of : kwd_of;
|
|
|
|
product : cartesian
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and record_type = {
|
|
|
|
kwd_record : kwd_record;
|
|
|
|
fields : field_decls;
|
|
|
|
kwd_end : kwd_end
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and field_decls = (field_decl reg, semi) nsepseq
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and field_decl = {
|
2019-03-14 12:59:26 +04:00
|
|
|
field_name : field_name;
|
2019-03-13 19:29:25 +04:00
|
|
|
colon : colon;
|
|
|
|
field_type : type_expr
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-18 20:47:11 +04:00
|
|
|
and type_tuple = (type_expr, comma) nsepseq par reg
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
(* Function and procedure declarations *)
|
|
|
|
|
|
|
|
and lambda_decl =
|
2019-03-13 19:29:25 +04:00
|
|
|
FunDecl of fun_decl reg
|
|
|
|
| ProcDecl of proc_decl reg
|
2019-03-10 16:55:24 +04:00
|
|
|
| EntryDecl of entry_decl reg
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
and fun_decl = {
|
2019-02-26 01:29:29 +04:00
|
|
|
kwd_function : kwd_function;
|
2019-02-28 18:46:34 +04:00
|
|
|
name : variable;
|
2019-02-26 01:29:29 +04:00
|
|
|
param : parameters;
|
|
|
|
colon : colon;
|
|
|
|
ret_type : type_expr;
|
|
|
|
kwd_is : kwd_is;
|
2019-02-28 18:46:34 +04:00
|
|
|
local_decls : local_decl list;
|
|
|
|
block : block reg;
|
2019-02-26 01:29:29 +04:00
|
|
|
kwd_with : kwd_with;
|
2019-03-07 20:06:02 +04:00
|
|
|
return : expr;
|
|
|
|
terminator : semi option
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
and proc_decl = {
|
2019-02-26 01:29:29 +04:00
|
|
|
kwd_procedure : kwd_procedure;
|
2019-02-28 18:46:34 +04:00
|
|
|
name : variable;
|
2019-02-26 01:29:29 +04:00
|
|
|
param : parameters;
|
|
|
|
kwd_is : kwd_is;
|
2019-02-28 18:46:34 +04:00
|
|
|
local_decls : local_decl list;
|
2019-03-07 20:06:02 +04:00
|
|
|
block : block reg;
|
|
|
|
terminator : semi option
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-10 16:55:24 +04:00
|
|
|
and entry_decl = {
|
|
|
|
kwd_entrypoint : kwd_entrypoint;
|
|
|
|
name : variable;
|
2019-03-14 21:17:19 +04:00
|
|
|
param : entry_params;
|
2019-03-14 17:04:20 +04:00
|
|
|
colon : colon;
|
|
|
|
ret_type : type_expr;
|
2019-03-10 16:55:24 +04:00
|
|
|
kwd_is : kwd_is;
|
|
|
|
local_decls : local_decl list;
|
|
|
|
block : block reg;
|
2019-03-14 17:04:20 +04:00
|
|
|
kwd_with : kwd_with;
|
|
|
|
return : expr;
|
2019-03-10 16:55:24 +04:00
|
|
|
terminator : semi option
|
|
|
|
}
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and parameters = (param_decl, semi) nsepseq par reg
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-14 21:17:19 +04:00
|
|
|
and entry_params = (entry_param_decl, semi) nsepseq par reg
|
|
|
|
|
|
|
|
and entry_param_decl =
|
|
|
|
EntryConst of param_const reg
|
|
|
|
| EntryVar of param_var reg
|
|
|
|
| EntryStore of storage reg
|
|
|
|
|
|
|
|
and storage = {
|
|
|
|
kwd_storage : kwd_storage;
|
|
|
|
var : variable;
|
|
|
|
colon : colon;
|
|
|
|
storage_type : type_expr
|
|
|
|
}
|
|
|
|
|
2019-02-28 18:46:34 +04:00
|
|
|
and param_decl =
|
2019-03-13 19:29:25 +04:00
|
|
|
ParamConst of param_const reg
|
|
|
|
| ParamVar of param_var reg
|
2019-03-07 20:06:02 +04:00
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and param_const = {
|
|
|
|
kwd_const : kwd_const;
|
|
|
|
var : variable;
|
|
|
|
colon : colon;
|
|
|
|
param_type : type_expr
|
|
|
|
}
|
2019-03-07 20:06:02 +04:00
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and param_var = {
|
|
|
|
kwd_var : kwd_var;
|
|
|
|
var : variable;
|
|
|
|
colon : colon;
|
|
|
|
param_type : type_expr
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
and block = {
|
2019-03-07 20:06:02 +04:00
|
|
|
opening : kwd_begin;
|
|
|
|
instr : instructions;
|
|
|
|
terminator : semi option;
|
|
|
|
close : kwd_end
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-02-28 18:46:34 +04:00
|
|
|
and local_decl =
|
|
|
|
LocalLam of lambda_decl
|
|
|
|
| LocalConst of const_decl reg
|
|
|
|
| LocalVar of var_decl reg
|
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
and var_decl = {
|
2019-03-07 20:06:02 +04:00
|
|
|
kwd_var : kwd_var;
|
|
|
|
name : variable;
|
|
|
|
colon : colon;
|
2019-03-10 22:41:27 +04:00
|
|
|
var_type : type_expr;
|
2019-03-18 20:47:11 +04:00
|
|
|
assign : assign;
|
2019-03-07 20:06:02 +04:00
|
|
|
init : expr;
|
|
|
|
terminator : semi option
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-14 12:59:26 +04:00
|
|
|
and instructions = (instruction, semi) nsepseq
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
and instruction =
|
|
|
|
Single of single_instr
|
|
|
|
| Block of block reg
|
|
|
|
|
|
|
|
and single_instr =
|
2019-03-18 20:47:11 +04:00
|
|
|
Cond of conditional reg
|
|
|
|
| Match of match_instr reg
|
|
|
|
| Assign of assignment reg
|
|
|
|
| Loop of loop
|
|
|
|
| ProcCall of fun_call
|
|
|
|
| Fail of fail_instr reg
|
2019-03-18 21:09:15 +04:00
|
|
|
| Skip of kwd_skip
|
2019-03-13 19:29:25 +04:00
|
|
|
|
|
|
|
and fail_instr = {
|
|
|
|
kwd_fail : kwd_fail;
|
|
|
|
fail_expr : expr
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
and conditional = {
|
2019-02-26 01:29:29 +04:00
|
|
|
kwd_if : kwd_if;
|
|
|
|
test : expr;
|
|
|
|
kwd_then : kwd_then;
|
|
|
|
ifso : instruction;
|
|
|
|
kwd_else : kwd_else;
|
|
|
|
ifnot : instruction
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
and match_instr = {
|
2019-02-26 01:29:29 +04:00
|
|
|
kwd_match : kwd_match;
|
|
|
|
expr : expr;
|
|
|
|
kwd_with : kwd_with;
|
2019-03-07 20:06:02 +04:00
|
|
|
lead_vbar : vbar option;
|
2019-02-26 01:29:29 +04:00
|
|
|
cases : cases;
|
|
|
|
kwd_end : kwd_end
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and cases = (case reg, vbar) nsepseq reg
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and case = {
|
|
|
|
pattern : pattern;
|
|
|
|
arrow : arrow;
|
|
|
|
instr : instruction
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-18 20:47:11 +04:00
|
|
|
and assignment = {
|
|
|
|
var : variable;
|
|
|
|
assign : assign;
|
2019-03-14 16:19:52 +04:00
|
|
|
expr : expr
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
and loop =
|
2019-03-13 19:29:25 +04:00
|
|
|
While of while_loop reg
|
2019-02-26 01:29:29 +04:00
|
|
|
| For of for_loop
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and while_loop = {
|
|
|
|
kwd_while : kwd_while;
|
|
|
|
cond : expr;
|
|
|
|
block : block reg
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
and for_loop =
|
|
|
|
ForInt of for_int reg
|
|
|
|
| ForCollect of for_collect reg
|
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
and for_int = {
|
2019-02-26 01:29:29 +04:00
|
|
|
kwd_for : kwd_for;
|
2019-03-18 20:47:11 +04:00
|
|
|
assign : assignment reg;
|
2019-02-26 01:29:29 +04:00
|
|
|
down : kwd_down option;
|
|
|
|
kwd_to : kwd_to;
|
|
|
|
bound : expr;
|
|
|
|
step : (kwd_step * expr) option;
|
|
|
|
block : block reg
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
and for_collect = {
|
2019-02-26 01:29:29 +04:00
|
|
|
kwd_for : kwd_for;
|
|
|
|
var : variable;
|
|
|
|
bind_to : (arrow * variable) option;
|
|
|
|
kwd_in : kwd_in;
|
|
|
|
expr : expr;
|
|
|
|
block : block reg
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
(* Expressions *)
|
|
|
|
|
|
|
|
and expr =
|
2019-03-13 19:29:25 +04:00
|
|
|
LogicExpr of logic_expr
|
|
|
|
| ArithExpr of arith_expr
|
|
|
|
| StringExpr of string_expr
|
|
|
|
| ListExpr of list_expr
|
|
|
|
| SetExpr of set_expr
|
|
|
|
| ConstrExpr of constr_expr
|
2019-03-14 12:59:26 +04:00
|
|
|
| RecordExpr of record_expr
|
2019-03-13 19:29:25 +04:00
|
|
|
| Var of Lexer.lexeme reg
|
|
|
|
| FunCall of fun_call
|
|
|
|
| Bytes of (Lexer.lexeme * MBytes.t) reg
|
|
|
|
| Unit of c_Unit
|
|
|
|
| Tuple of tuple
|
|
|
|
| MapLookUp of map_lookup reg
|
|
|
|
| ParExpr of expr par reg
|
|
|
|
|
|
|
|
and logic_expr =
|
|
|
|
BoolExpr of bool_expr
|
|
|
|
| CompExpr of comp_expr
|
|
|
|
|
|
|
|
and bool_expr =
|
2019-03-18 20:47:11 +04:00
|
|
|
Or of bool_or bin_op reg
|
2019-03-13 19:29:25 +04:00
|
|
|
| And of bool_and bin_op reg
|
2019-03-18 20:47:11 +04:00
|
|
|
| Not of kwd_not un_op reg
|
2019-03-13 19:29:25 +04:00
|
|
|
| False of c_False
|
|
|
|
| True of c_True
|
|
|
|
|
|
|
|
and 'a bin_op = {
|
2019-03-18 20:47:11 +04:00
|
|
|
op : 'a;
|
|
|
|
arg1 : expr;
|
|
|
|
arg2 : expr
|
2019-03-13 19:29:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
and 'a un_op = {
|
|
|
|
op : 'a;
|
2019-03-18 20:47:11 +04:00
|
|
|
arg : expr
|
2019-03-13 19:29:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
and comp_expr =
|
|
|
|
Lt of lt bin_op reg
|
|
|
|
| Leq of leq bin_op reg
|
|
|
|
| Gt of gt bin_op reg
|
|
|
|
| Geq of geq bin_op reg
|
|
|
|
| Equal of equal bin_op reg
|
|
|
|
| Neq of neq bin_op reg
|
|
|
|
|
|
|
|
and arith_expr =
|
|
|
|
Add of plus bin_op reg
|
|
|
|
| Sub of minus bin_op reg
|
|
|
|
| Mult of times bin_op reg
|
|
|
|
| Div of slash bin_op reg
|
|
|
|
| Mod of kwd_mod bin_op reg
|
2019-03-18 20:47:11 +04:00
|
|
|
| Neg of minus un_op reg
|
2019-03-13 19:29:25 +04:00
|
|
|
| Int of (Lexer.lexeme * Z.t) reg
|
|
|
|
|
|
|
|
and string_expr =
|
|
|
|
Cat of cat bin_op reg
|
|
|
|
| String of Lexer.lexeme reg
|
|
|
|
|
|
|
|
and list_expr =
|
|
|
|
Cons of cons bin_op reg
|
|
|
|
| List of (expr, comma) nsepseq brackets reg
|
|
|
|
| EmptyList of empty_list reg
|
|
|
|
|
|
|
|
and set_expr =
|
|
|
|
Set of (expr, comma) nsepseq braces reg
|
|
|
|
| EmptySet of empty_set reg
|
|
|
|
|
|
|
|
and constr_expr =
|
|
|
|
SomeApp of (c_Some * arguments) reg
|
|
|
|
| NoneExpr of none_expr reg
|
|
|
|
| ConstrApp of (constr * arguments) reg
|
|
|
|
|
2019-03-14 12:59:26 +04:00
|
|
|
and record_expr =
|
|
|
|
RecordInj of record_injection reg
|
|
|
|
| RecordProj of record_projection reg
|
|
|
|
| RecordCopy of record_copy reg
|
|
|
|
|
|
|
|
and record_injection = {
|
|
|
|
opening : kwd_record;
|
2019-03-18 20:47:11 +04:00
|
|
|
fields : (field_assign reg, semi) nsepseq;
|
2019-03-14 12:59:26 +04:00
|
|
|
terminator : semi option;
|
|
|
|
close : kwd_end
|
|
|
|
}
|
|
|
|
|
2019-03-18 20:47:11 +04:00
|
|
|
and field_assign = {
|
2019-03-14 12:59:26 +04:00
|
|
|
field_name : field_name;
|
|
|
|
equal : equal;
|
|
|
|
field_expr : expr
|
|
|
|
}
|
|
|
|
|
|
|
|
and record_projection = {
|
|
|
|
record_name : variable;
|
|
|
|
selector : dot;
|
2019-03-18 20:47:11 +04:00
|
|
|
field_path : (field_name, dot) nsepseq
|
2019-03-14 12:59:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
and record_copy = {
|
|
|
|
kwd_copy : kwd_copy;
|
|
|
|
record_name : variable;
|
|
|
|
kwd_with : kwd_with;
|
|
|
|
delta : record_injection reg
|
|
|
|
}
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and tuple = (expr, comma) nsepseq par reg
|
|
|
|
|
|
|
|
and empty_list = typed_empty_list par
|
|
|
|
|
|
|
|
and typed_empty_list = {
|
|
|
|
lbracket : lbracket;
|
|
|
|
rbracket : rbracket;
|
|
|
|
colon : colon;
|
|
|
|
list_type : type_expr
|
|
|
|
}
|
|
|
|
|
|
|
|
and empty_set = typed_empty_set par
|
|
|
|
|
|
|
|
and typed_empty_set = {
|
|
|
|
lbrace : lbrace;
|
|
|
|
rbrace : rbrace;
|
|
|
|
colon : colon;
|
|
|
|
set_type : type_expr
|
|
|
|
}
|
|
|
|
|
|
|
|
and none_expr = typed_none_expr par
|
|
|
|
|
|
|
|
and typed_none_expr = {
|
|
|
|
c_None : c_None;
|
|
|
|
colon : colon;
|
|
|
|
opt_type : type_expr
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
and fun_call = (fun_name * arguments) reg
|
|
|
|
|
|
|
|
and arguments = tuple
|
|
|
|
|
2019-03-05 12:53:58 +04:00
|
|
|
and map_lookup = {
|
2019-03-18 20:47:11 +04:00
|
|
|
map_path : map_path;
|
2019-03-13 19:29:25 +04:00
|
|
|
index : expr brackets reg
|
2019-03-05 12:53:58 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-18 20:47:11 +04:00
|
|
|
and map_path =
|
|
|
|
Map of map_name
|
|
|
|
| MapPath of record_projection reg
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
(* Patterns *)
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
and pattern =
|
|
|
|
PCons of (pattern, cons) nsepseq reg
|
|
|
|
| PVar of Lexer.lexeme reg
|
2019-02-26 01:29:29 +04:00
|
|
|
| PWild of wild
|
|
|
|
| PInt of (Lexer.lexeme * Z.t) reg
|
|
|
|
| PBytes of (Lexer.lexeme * MBytes.t) reg
|
|
|
|
| PString of Lexer.lexeme reg
|
|
|
|
| PUnit of c_Unit
|
|
|
|
| PFalse of c_False
|
|
|
|
| PTrue of c_True
|
|
|
|
| PNone of c_None
|
2019-03-13 19:29:25 +04:00
|
|
|
| PSome of (c_Some * pattern par reg) reg
|
2019-02-26 01:29:29 +04:00
|
|
|
| PList of list_pattern
|
2019-03-13 19:29:25 +04:00
|
|
|
| PTuple of (pattern, comma) nsepseq par reg
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
and list_pattern =
|
2019-03-13 19:29:25 +04:00
|
|
|
Sugar of (pattern, comma) sepseq brackets reg
|
|
|
|
| Raw of (pattern * cons * pattern) par reg
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
(* Projecting regions *)
|
|
|
|
|
|
|
|
val type_expr_to_region : type_expr -> Region.t
|
|
|
|
|
|
|
|
val expr_to_region : expr -> Region.t
|
|
|
|
|
|
|
|
val instr_to_region : instruction -> Region.t
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
val pattern_to_region : pattern -> Region.t
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-02-28 18:46:34 +04:00
|
|
|
val local_decl_to_region : local_decl -> Region.t
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
(* Printing *)
|
|
|
|
|
|
|
|
val print_tokens : t -> unit
|