2019-02-26 01:29:29 +04:00
|
|
|
%{
|
|
|
|
(* START HEADER *)
|
|
|
|
|
2019-03-07 15:24:57 +04:00
|
|
|
[@@@warning "-42"]
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
open Region
|
|
|
|
open AST
|
|
|
|
|
|
|
|
(* END HEADER *)
|
|
|
|
%}
|
|
|
|
|
2019-02-28 18:46:34 +04:00
|
|
|
(* See [ParToken.mly] for the definition of tokens. *)
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
(* Entry points *)
|
|
|
|
|
2019-03-20 13:06:33 +04:00
|
|
|
%start contract interactive_expr
|
|
|
|
%type <AST.t> contract
|
2019-03-11 15:51:50 +04:00
|
|
|
%type <AST.expr> interactive_expr
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
(* RULES *)
|
|
|
|
|
2019-03-20 12:11:19 +04:00
|
|
|
(* The rule [series(Item)] parses a list of [Item] separated by
|
|
|
|
semi-colons and optionally terminated by a semi-colon, then the
|
|
|
|
keyword [End]. *)
|
|
|
|
|
|
|
|
series(Item):
|
|
|
|
Item after_item(Item) { $1,$2 }
|
|
|
|
|
|
|
|
after_item(Item):
|
|
|
|
SEMI item_or_end(Item) {
|
|
|
|
match $2 with
|
|
|
|
`Some (item, items, term, close) ->
|
|
|
|
($1, item)::items, term, close
|
|
|
|
| `End close ->
|
|
|
|
[], Some $1, close
|
|
|
|
}
|
|
|
|
| End {
|
|
|
|
[], None, $1
|
|
|
|
}
|
|
|
|
|
|
|
|
item_or_end(Item):
|
|
|
|
End {
|
|
|
|
`End $1
|
|
|
|
}
|
|
|
|
| series(Item) {
|
|
|
|
let item, (items, term, close) = $1
|
|
|
|
in `Some (item, items, term, close)
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
(* Compound constructs *)
|
|
|
|
|
|
|
|
par(X):
|
|
|
|
LPAR X RPAR {
|
|
|
|
let region = cover $1 $3
|
2019-03-13 19:29:25 +04:00
|
|
|
and value = {
|
|
|
|
lpar = $1;
|
|
|
|
inside = $2;
|
|
|
|
rpar = $3}
|
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
braces(X):
|
|
|
|
LBRACE X RBRACE {
|
|
|
|
let region = cover $1 $3
|
2019-03-13 19:29:25 +04:00
|
|
|
and value = {
|
|
|
|
lbrace = $1;
|
|
|
|
inside = $2;
|
|
|
|
rbrace = $3}
|
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
brackets(X):
|
|
|
|
LBRACKET X RBRACKET {
|
|
|
|
let region = cover $1 $3
|
2019-03-13 19:29:25 +04:00
|
|
|
and value = {
|
|
|
|
lbracket = $1;
|
|
|
|
inside = $2;
|
|
|
|
rbracket = $3}
|
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
(* Sequences
|
|
|
|
|
|
|
|
Series of instances of the same syntactical category have often to
|
|
|
|
be parsed, like lists of expressions, patterns etc. The simplest of
|
|
|
|
all is the possibly empty sequence (series), parsed below by
|
|
|
|
[seq]. The non-empty sequence is parsed by [nseq]. Note that the
|
|
|
|
latter returns a pair made of the first parsed item (the parameter
|
|
|
|
[X]) and the rest of the sequence (possibly empty). This way, the
|
|
|
|
OCaml typechecker can keep track of this information along the
|
|
|
|
static control-flow graph. The rule [sepseq] parses possibly empty
|
|
|
|
sequences of items separated by some token (e.g., a comma), and
|
|
|
|
rule [nsepseq] is for non-empty such sequences. See module [Utils]
|
|
|
|
for the types corresponding to the semantic actions of those rules.
|
|
|
|
*)
|
|
|
|
|
|
|
|
(* Possibly empty sequence of items *)
|
|
|
|
|
|
|
|
seq(X):
|
|
|
|
(**) { [] }
|
|
|
|
| X seq(X) { $1::$2 }
|
|
|
|
|
|
|
|
(* Non-empty sequence of items *)
|
|
|
|
|
|
|
|
nseq(X):
|
|
|
|
X seq(X) { $1,$2 }
|
|
|
|
|
|
|
|
(* Non-empty separated sequence of items *)
|
|
|
|
|
|
|
|
nsepseq(X,Sep):
|
|
|
|
X { $1, [] }
|
|
|
|
| X Sep nsepseq(X,Sep) { let h,t = $3 in $1, ($2,h)::t }
|
|
|
|
|
|
|
|
(* Possibly empy separated sequence of items *)
|
|
|
|
|
|
|
|
sepseq(X,Sep):
|
|
|
|
(**) { None }
|
|
|
|
| nsepseq(X,Sep) { Some $1 }
|
|
|
|
|
|
|
|
(* Inlines *)
|
|
|
|
|
2019-03-14 12:59:26 +04:00
|
|
|
%inline var : Ident { $1 }
|
|
|
|
%inline type_name : Ident { $1 }
|
|
|
|
%inline fun_name : Ident { $1 }
|
|
|
|
%inline field_name : Ident { $1 }
|
|
|
|
%inline record_name : Ident { $1 }
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
(* Main *)
|
|
|
|
|
2019-03-20 13:06:33 +04:00
|
|
|
contract:
|
2019-03-11 15:51:50 +04:00
|
|
|
nseq(declaration) EOF {
|
|
|
|
{decl = $1; eof = $2}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2019-03-11 15:51:50 +04:00
|
|
|
declaration:
|
|
|
|
type_decl { TypeDecl $1 }
|
|
|
|
| const_decl { ConstDecl $1 }
|
|
|
|
| lambda_decl { LambdaDecl $1 }
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
(* Type declarations *)
|
|
|
|
|
|
|
|
type_decl:
|
2019-03-07 20:06:02 +04:00
|
|
|
Type type_name Is type_expr option(SEMI) {
|
|
|
|
let stop =
|
|
|
|
match $5 with
|
2019-03-14 12:59:26 +04:00
|
|
|
Some region -> region
|
|
|
|
| None -> type_expr_to_region $4 in
|
2019-03-07 20:06:02 +04:00
|
|
|
let region = cover $1 stop in
|
|
|
|
let value = {
|
|
|
|
kwd_type = $1;
|
|
|
|
name = $2;
|
|
|
|
kwd_is = $3;
|
|
|
|
type_expr = $4;
|
|
|
|
terminator = $5}
|
|
|
|
in {region; value}}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
type_expr:
|
2019-03-21 00:36:12 +04:00
|
|
|
cartesian { TProd $1 }
|
|
|
|
| sum_type { TSum $1 }
|
|
|
|
| record_type { TRecord $1 }
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
cartesian:
|
|
|
|
nsepseq(core_type,TIMES) {
|
|
|
|
let region = nsepseq_to_region type_expr_to_region $1
|
|
|
|
in {region; value=$1}
|
|
|
|
}
|
|
|
|
|
|
|
|
core_type:
|
|
|
|
type_name {
|
|
|
|
TAlias $1
|
|
|
|
}
|
|
|
|
| type_name type_tuple {
|
|
|
|
let region = cover $1.region $2.region
|
2019-03-21 00:36:12 +04:00
|
|
|
in TApp {region; value = $1,$2}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
2019-03-20 12:11:19 +04:00
|
|
|
| Map type_tuple {
|
|
|
|
let region = cover $1 $2.region in
|
2019-03-22 01:55:08 +04:00
|
|
|
let type_constr = {value="map"; region=$1}
|
|
|
|
in TApp {region; value = type_constr, $2}
|
|
|
|
}
|
|
|
|
| Set par(type_expr) {
|
|
|
|
let total = cover $1 $2.region in
|
|
|
|
let type_constr = {value="set"; region=$1} in
|
|
|
|
let {region; value = {lpar; inside; rpar}} = $2 in
|
|
|
|
let tuple = {region; value={lpar; inside=inside,[]; rpar}}
|
|
|
|
in TApp {region=total; value = type_constr, tuple}
|
2019-03-20 12:11:19 +04:00
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
| par(type_expr) {
|
2019-03-21 00:36:12 +04:00
|
|
|
TPar $1
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type_tuple:
|
2019-03-18 20:47:11 +04:00
|
|
|
par(nsepseq(type_expr,COMMA)) { $1 }
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
sum_type:
|
|
|
|
nsepseq(variant,VBAR) {
|
|
|
|
let region = nsepseq_to_region (fun x -> x.region) $1
|
2019-03-14 12:59:26 +04:00
|
|
|
in {region; value = $1}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
variant:
|
|
|
|
Constr Of cartesian {
|
|
|
|
let region = cover $1.region $3.region
|
2019-03-14 12:59:26 +04:00
|
|
|
and value = {constr = $1; kwd_of = $2; product = $3}
|
2019-03-13 19:29:25 +04:00
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
record_type:
|
2019-03-22 00:34:22 +04:00
|
|
|
Record series(field_decl) {
|
|
|
|
let first, (others, terminator, close) = $2 in
|
|
|
|
let region = cover $1 close
|
|
|
|
and value = {
|
|
|
|
opening = $1;
|
|
|
|
field_decls = first, others;
|
|
|
|
terminator;
|
|
|
|
close}
|
2019-03-13 19:29:25 +04:00
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
field_decl:
|
|
|
|
field_name COLON type_expr {
|
2019-02-28 18:46:34 +04:00
|
|
|
let stop = type_expr_to_region $3 in
|
2019-02-26 01:29:29 +04:00
|
|
|
let region = cover $1.region stop
|
2019-03-14 12:59:26 +04:00
|
|
|
and value = {field_name = $1; colon = $2; field_type = $3}
|
2019-03-13 19:29:25 +04:00
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
(* Function and procedure declarations *)
|
|
|
|
|
|
|
|
lambda_decl:
|
2019-03-10 16:55:24 +04:00
|
|
|
fun_decl { FunDecl $1 }
|
|
|
|
| proc_decl { ProcDecl $1 }
|
|
|
|
| entry_decl { EntryDecl $1 }
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
fun_decl:
|
|
|
|
Function fun_name parameters COLON type_expr Is
|
2019-02-28 18:46:34 +04:00
|
|
|
seq(local_decl)
|
2019-02-26 01:29:29 +04:00
|
|
|
block
|
2019-03-07 20:06:02 +04:00
|
|
|
With expr option(SEMI) {
|
|
|
|
let stop =
|
|
|
|
match $11 with
|
2019-03-14 12:59:26 +04:00
|
|
|
Some region -> region
|
|
|
|
| None -> expr_to_region $10 in
|
2019-03-07 20:06:02 +04:00
|
|
|
let region = cover $1 stop in
|
|
|
|
let value = {
|
|
|
|
kwd_function = $1;
|
|
|
|
name = $2;
|
|
|
|
param = $3;
|
|
|
|
colon = $4;
|
|
|
|
ret_type = $5;
|
|
|
|
kwd_is = $6;
|
|
|
|
local_decls = $7;
|
|
|
|
block = $8;
|
|
|
|
kwd_with = $9;
|
|
|
|
return = $10;
|
|
|
|
terminator = $11}
|
2019-02-26 01:29:29 +04:00
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-14 17:04:20 +04:00
|
|
|
entry_decl:
|
2019-03-14 21:17:19 +04:00
|
|
|
Entrypoint fun_name entry_params COLON type_expr Is
|
2019-03-14 17:04:20 +04:00
|
|
|
seq(local_decl)
|
|
|
|
block
|
|
|
|
With expr option(SEMI) {
|
|
|
|
let stop =
|
|
|
|
match $11 with
|
|
|
|
Some region -> region
|
|
|
|
| None -> expr_to_region $10 in
|
|
|
|
let region = cover $1 stop in
|
|
|
|
let value = {
|
|
|
|
kwd_entrypoint = $1;
|
|
|
|
name = $2;
|
|
|
|
param = $3;
|
|
|
|
colon = $4;
|
|
|
|
ret_type = $5;
|
|
|
|
kwd_is = $6;
|
|
|
|
local_decls = $7;
|
|
|
|
block = $8;
|
|
|
|
kwd_with = $9;
|
|
|
|
return = $10;
|
|
|
|
terminator = $11}
|
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-14 21:17:19 +04:00
|
|
|
entry_params:
|
|
|
|
par(nsepseq(entry_param_decl,SEMI)) { $1 }
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
proc_decl:
|
|
|
|
Procedure fun_name parameters Is
|
2019-02-28 18:46:34 +04:00
|
|
|
seq(local_decl)
|
2019-03-07 20:06:02 +04:00
|
|
|
block option(SEMI)
|
2019-03-05 14:15:02 +04:00
|
|
|
{
|
2019-03-07 20:06:02 +04:00
|
|
|
let stop =
|
|
|
|
match $7 with
|
2019-03-14 12:59:26 +04:00
|
|
|
Some region -> region
|
|
|
|
| None -> $6.region in
|
2019-03-07 20:06:02 +04:00
|
|
|
let region = cover $1 stop in
|
|
|
|
let value = {
|
|
|
|
kwd_procedure = $1;
|
|
|
|
name = $2;
|
|
|
|
param = $3;
|
|
|
|
kwd_is = $4;
|
|
|
|
local_decls = $5;
|
|
|
|
block = $6;
|
|
|
|
terminator = $7}
|
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
parameters:
|
|
|
|
par(nsepseq(param_decl,SEMI)) { $1 }
|
|
|
|
|
|
|
|
param_decl:
|
2019-03-21 18:09:35 +04:00
|
|
|
Var var COLON param_type {
|
2019-02-26 01:29:29 +04:00
|
|
|
let stop = type_expr_to_region $4 in
|
2019-02-28 18:46:34 +04:00
|
|
|
let region = cover $1 stop
|
2019-03-13 19:29:25 +04:00
|
|
|
and value = {
|
|
|
|
kwd_var = $1;
|
|
|
|
var = $2;
|
|
|
|
colon = $3;
|
|
|
|
param_type = $4}
|
|
|
|
in ParamVar {region; value}
|
2019-02-28 18:46:34 +04:00
|
|
|
}
|
2019-03-21 18:09:35 +04:00
|
|
|
| Const var COLON param_type {
|
2019-02-28 18:46:34 +04:00
|
|
|
let stop = type_expr_to_region $4 in
|
|
|
|
let region = cover $1 stop
|
2019-03-13 19:29:25 +04:00
|
|
|
and value = {
|
|
|
|
kwd_const = $1;
|
|
|
|
var = $2;
|
|
|
|
colon = $3;
|
|
|
|
param_type = $4}
|
|
|
|
in ParamConst {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2019-03-14 21:17:19 +04:00
|
|
|
entry_param_decl:
|
|
|
|
param_decl {
|
|
|
|
match $1 with
|
|
|
|
ParamConst const -> EntryConst const
|
|
|
|
| ParamVar var -> EntryVar var
|
|
|
|
}
|
2019-03-21 18:09:35 +04:00
|
|
|
| Storage var COLON param_type {
|
2019-03-14 21:17:19 +04:00
|
|
|
let stop = type_expr_to_region $4 in
|
|
|
|
let region = cover $1 stop
|
|
|
|
and value = {
|
|
|
|
kwd_storage = $1;
|
|
|
|
var = $2;
|
|
|
|
colon = $3;
|
|
|
|
storage_type = $4}
|
|
|
|
in EntryStore {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-21 18:09:35 +04:00
|
|
|
param_type:
|
|
|
|
nsepseq(core_param_type,TIMES) {
|
|
|
|
let region = nsepseq_to_region type_expr_to_region $1
|
|
|
|
in TProd {region; value=$1}
|
|
|
|
}
|
|
|
|
|
|
|
|
core_param_type:
|
|
|
|
type_name {
|
|
|
|
TAlias $1
|
|
|
|
}
|
|
|
|
| type_name type_tuple {
|
|
|
|
let region = cover $1.region $2.region
|
|
|
|
in TApp {region; value = $1,$2}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
block:
|
2019-03-20 12:11:19 +04:00
|
|
|
Begin series(instruction) {
|
|
|
|
let first, (others, terminator, close) = $2 in
|
2019-03-14 12:59:26 +04:00
|
|
|
let region = cover $1 close
|
|
|
|
and value = {
|
|
|
|
opening = $1;
|
2019-03-20 12:11:19 +04:00
|
|
|
instr = first, others;
|
2019-03-07 20:06:02 +04:00
|
|
|
terminator;
|
|
|
|
close}
|
2019-02-28 18:46:34 +04:00
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2019-02-28 18:46:34 +04:00
|
|
|
local_decl:
|
|
|
|
lambda_decl { LocalLam $1 }
|
|
|
|
| const_decl { LocalConst $1 }
|
|
|
|
| var_decl { LocalVar $1 }
|
2019-02-26 01:29:29 +04:00
|
|
|
|
2019-03-20 14:24:27 +04:00
|
|
|
unqualified_decl(OP):
|
|
|
|
var COLON type_expr OP extended_expr option(SEMI) {
|
2019-03-20 13:06:33 +04:00
|
|
|
let stop = match $6 with
|
|
|
|
Some region -> region
|
|
|
|
| None -> $5.region in
|
2019-03-19 13:52:47 +04:00
|
|
|
let init =
|
2019-03-20 13:06:33 +04:00
|
|
|
match $5.value with
|
2019-03-19 13:52:47 +04:00
|
|
|
`Expr e -> e
|
|
|
|
| `EList (lbracket, rbracket) ->
|
2019-03-20 13:06:33 +04:00
|
|
|
let region = $5.region
|
2019-03-19 13:52:47 +04:00
|
|
|
and value = {
|
|
|
|
lbracket;
|
|
|
|
rbracket;
|
|
|
|
colon = Region.ghost;
|
2019-03-20 13:06:33 +04:00
|
|
|
list_type = $3} in
|
2019-03-19 13:52:47 +04:00
|
|
|
let value = {
|
|
|
|
lpar = Region.ghost;
|
|
|
|
inside = value;
|
|
|
|
rpar = Region.ghost} in
|
2019-03-21 00:36:12 +04:00
|
|
|
EList (EmptyList {region; value})
|
2019-03-19 13:52:47 +04:00
|
|
|
| `ENone region ->
|
|
|
|
let value = {
|
|
|
|
lpar = Region.ghost;
|
|
|
|
inside = {
|
|
|
|
c_None = region;
|
|
|
|
colon = Region.ghost;
|
2019-03-20 13:06:33 +04:00
|
|
|
opt_type = $3};
|
2019-03-19 13:52:47 +04:00
|
|
|
rpar = Region.ghost}
|
2019-03-21 00:36:12 +04:00
|
|
|
in EConstr (NoneExpr {region; value})
|
2019-03-20 14:24:27 +04:00
|
|
|
| `EMap inj ->
|
2019-03-22 01:55:08 +04:00
|
|
|
EMap (MapInj inj)
|
|
|
|
| `ESet inj ->
|
|
|
|
ESet (SetInj inj)
|
2019-03-20 13:06:33 +04:00
|
|
|
in $1, $2, $3, $4, init, $6, stop
|
|
|
|
}
|
2019-03-20 12:11:19 +04:00
|
|
|
|
2019-03-20 13:06:33 +04:00
|
|
|
const_decl:
|
2019-03-20 14:24:27 +04:00
|
|
|
Const unqualified_decl(EQUAL) {
|
2019-03-20 13:06:33 +04:00
|
|
|
let name, colon, const_type, equal,
|
|
|
|
init, terminator, stop = $2 in
|
|
|
|
let region = cover $1 stop in
|
2019-03-07 15:24:57 +04:00
|
|
|
let value = {
|
2019-03-20 13:06:33 +04:00
|
|
|
kwd_const = $1;
|
|
|
|
name;
|
|
|
|
colon;
|
|
|
|
const_type;
|
|
|
|
equal;
|
|
|
|
init;
|
|
|
|
terminator}
|
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
|
|
|
var_decl:
|
2019-03-20 14:24:27 +04:00
|
|
|
Var unqualified_decl(ASS) {
|
2019-03-20 13:06:33 +04:00
|
|
|
let name, colon, var_type, assign,
|
|
|
|
init, terminator, stop = $2 in
|
|
|
|
let region = cover $1 stop in
|
|
|
|
let value = {
|
|
|
|
kwd_var = $1;
|
|
|
|
name;
|
|
|
|
colon;
|
|
|
|
var_type;
|
|
|
|
assign;
|
2019-03-19 13:52:47 +04:00
|
|
|
init;
|
2019-03-20 13:06:33 +04:00
|
|
|
terminator}
|
2019-02-26 01:29:29 +04:00
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-18 20:47:11 +04:00
|
|
|
extended_expr:
|
2019-03-19 13:52:47 +04:00
|
|
|
expr { {region = expr_to_region $1;
|
|
|
|
value = `Expr $1} }
|
|
|
|
| LBRACKET RBRACKET { {region = cover $1 $2;
|
|
|
|
value = `EList ($1,$2)} }
|
|
|
|
| C_None { {region = $1; value = `ENone $1} }
|
2019-03-20 12:11:19 +04:00
|
|
|
| map_injection { {region = $1.region; value = `EMap $1} }
|
2019-03-22 01:55:08 +04:00
|
|
|
| set_injection { {region = $1.region; value = `ESet $1} }
|
2019-03-20 14:24:27 +04:00
|
|
|
|
2019-03-19 13:52:47 +04:00
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
instruction:
|
|
|
|
single_instr { Single $1 }
|
|
|
|
| block { Block $1 }
|
|
|
|
|
|
|
|
single_instr:
|
2019-03-20 12:11:19 +04:00
|
|
|
conditional { Cond $1 }
|
|
|
|
| case_instr { Case $1 }
|
|
|
|
| assignment { Assign $1 }
|
|
|
|
| loop { Loop $1 }
|
|
|
|
| proc_call { ProcCall $1 }
|
|
|
|
| fail_instr { Fail $1 }
|
|
|
|
| Skip { Skip $1 }
|
|
|
|
| record_patch { RecordPatch $1 }
|
|
|
|
| map_patch { MapPatch $1 }
|
2019-03-22 02:12:46 +04:00
|
|
|
| set_patch { SetPatch $1 }
|
2019-03-22 00:55:59 +04:00
|
|
|
| map_remove { MapRemove $1 }
|
2019-03-22 02:01:21 +04:00
|
|
|
| set_remove { SetRemove $1 }
|
|
|
|
|
|
|
|
set_remove:
|
|
|
|
Remove expr From Set path {
|
|
|
|
let region = cover $1 (path_to_region $5) in
|
|
|
|
let value = {
|
|
|
|
kwd_remove = $1;
|
|
|
|
element = $2;
|
|
|
|
kwd_from = $3;
|
|
|
|
kwd_set = $4;
|
|
|
|
set = $5}
|
|
|
|
in {region; value}
|
|
|
|
}
|
2019-03-22 00:55:59 +04:00
|
|
|
|
|
|
|
map_remove:
|
|
|
|
Remove expr From Map path {
|
|
|
|
let region = cover $1 (path_to_region $5) in
|
|
|
|
let value = {
|
|
|
|
kwd_remove = $1;
|
|
|
|
key = $2;
|
|
|
|
kwd_from = $3;
|
|
|
|
kwd_map = $4;
|
|
|
|
map = $5}
|
|
|
|
in {region; value}
|
|
|
|
}
|
2019-03-20 12:11:19 +04:00
|
|
|
|
2019-03-22 02:12:46 +04:00
|
|
|
set_patch:
|
|
|
|
Patch path With set_injection {
|
|
|
|
let region = cover $1 $4.region in
|
|
|
|
let value = {
|
|
|
|
kwd_patch = $1;
|
|
|
|
path = $2;
|
|
|
|
kwd_with = $3;
|
|
|
|
set_inj = $4}
|
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-20 12:11:19 +04:00
|
|
|
map_patch:
|
2019-03-20 12:45:32 +04:00
|
|
|
Patch path With map_injection {
|
2019-03-20 12:11:19 +04:00
|
|
|
let region = cover $1 $4.region in
|
|
|
|
let value = {
|
2019-03-20 12:45:32 +04:00
|
|
|
kwd_patch = $1;
|
|
|
|
path = $2;
|
|
|
|
kwd_with = $3;
|
|
|
|
map_inj = $4}
|
2019-03-20 12:11:19 +04:00
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-22 01:55:08 +04:00
|
|
|
set_injection:
|
|
|
|
Set series(expr) {
|
|
|
|
let first, (others, terminator, close) = $2 in
|
|
|
|
let region = cover $1 close
|
|
|
|
and value = {
|
|
|
|
opening = $1;
|
|
|
|
elements = first, others;
|
|
|
|
terminator;
|
|
|
|
close}
|
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-20 12:11:19 +04:00
|
|
|
map_injection:
|
|
|
|
Map series(binding) {
|
|
|
|
let first, (others, terminator, close) = $2 in
|
|
|
|
let region = cover $1 close
|
|
|
|
and value = {
|
|
|
|
opening = $1;
|
|
|
|
bindings = first, others;
|
|
|
|
terminator;
|
|
|
|
close}
|
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
|
|
|
binding:
|
|
|
|
expr ARROW expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
|
|
|
let region = cover start stop
|
|
|
|
and value = {
|
|
|
|
source = $1;
|
|
|
|
arrow = $2;
|
|
|
|
image = $3}
|
|
|
|
in {region; value}
|
|
|
|
}
|
2019-03-19 17:32:43 +04:00
|
|
|
|
|
|
|
record_patch:
|
2019-03-20 12:45:32 +04:00
|
|
|
Patch path With record_injection {
|
2019-03-19 17:32:43 +04:00
|
|
|
let region = cover $1 $4.region in
|
|
|
|
let value = {
|
2019-03-20 12:45:32 +04:00
|
|
|
kwd_patch = $1;
|
|
|
|
path = $2;
|
|
|
|
kwd_with = $3;
|
|
|
|
record_inj = $4}
|
2019-03-19 17:32:43 +04:00
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-13 19:29:25 +04:00
|
|
|
fail_instr:
|
|
|
|
Fail expr {
|
|
|
|
let region = cover $1 (expr_to_region $2)
|
2019-03-14 12:59:26 +04:00
|
|
|
and value = {kwd_fail = $1; fail_expr = $2}
|
2019-03-13 19:29:25 +04:00
|
|
|
in {region; value}}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
proc_call:
|
|
|
|
fun_call { $1 }
|
|
|
|
|
|
|
|
conditional:
|
2019-03-22 02:45:19 +04:00
|
|
|
If test_expr Then instruction option(SEMI) Else instruction {
|
2019-03-22 02:18:09 +04:00
|
|
|
let region = cover $1 (instr_to_region $7) in
|
2019-03-07 20:06:02 +04:00
|
|
|
let value = {
|
2019-03-22 02:18:09 +04:00
|
|
|
kwd_if = $1;
|
|
|
|
test = $2;
|
|
|
|
kwd_then = $3;
|
|
|
|
ifso = $4;
|
|
|
|
terminator = $5;
|
|
|
|
kwd_else = $6;
|
|
|
|
ifnot = $7}
|
2019-02-26 01:29:29 +04:00
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-22 02:45:19 +04:00
|
|
|
test_expr:
|
|
|
|
expr { GenExpr $1 }
|
|
|
|
| set_membership { SetMem $1 }
|
|
|
|
|
|
|
|
set_membership:
|
|
|
|
expr Contains expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
|
|
|
let region = cover start stop in
|
|
|
|
let value = {
|
|
|
|
set = $1;
|
|
|
|
kwd_contains = $2;
|
|
|
|
element = $3}
|
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-03-19 14:46:30 +04:00
|
|
|
case_instr:
|
|
|
|
Case expr Of option(VBAR) cases End {
|
2019-03-07 20:06:02 +04:00
|
|
|
let region = cover $1 $6 in
|
|
|
|
let value = {
|
2019-03-19 14:46:30 +04:00
|
|
|
kwd_case = $1;
|
2019-03-07 20:06:02 +04:00
|
|
|
expr = $2;
|
2019-03-19 14:46:30 +04:00
|
|
|
kwd_of = $3;
|
2019-03-07 20:06:02 +04:00
|
|
|
lead_vbar = $4;
|
|
|
|
cases = $5;
|
|
|
|
kwd_end = $6}
|
2019-02-26 01:29:29 +04:00
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
|
|
|
cases:
|
|
|
|
nsepseq(case,VBAR) {
|
|
|
|
let region = nsepseq_to_region (fun x -> x.region) $1
|
2019-03-14 12:59:26 +04:00
|
|
|
in {region; value = $1}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case:
|
|
|
|
pattern ARROW instruction {
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover (pattern_to_region $1) (instr_to_region $3)
|
2019-03-14 12:59:26 +04:00
|
|
|
and value = {pattern = $1; arrow = $2; instr = $3}
|
2019-03-13 19:29:25 +04:00
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2019-03-18 20:47:11 +04:00
|
|
|
assignment:
|
2019-03-20 19:16:30 +04:00
|
|
|
lhs ASS rhs {
|
|
|
|
let stop = rhs_to_region $3 in
|
|
|
|
let region = cover (lhs_to_region $1) stop
|
|
|
|
and value = {lhs = $1; assign = $2; rhs = $3}
|
2019-03-13 19:29:25 +04:00
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2019-03-20 19:16:30 +04:00
|
|
|
rhs:
|
|
|
|
expr { Expr $1 }
|
|
|
|
| C_None { NoneExpr $1 : rhs }
|
|
|
|
|
2019-03-20 17:57:55 +04:00
|
|
|
lhs:
|
|
|
|
path { Path $1 }
|
|
|
|
| map_lookup { MapPath $1 }
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
loop:
|
|
|
|
while_loop { $1 }
|
|
|
|
| for_loop { $1 }
|
|
|
|
|
|
|
|
while_loop:
|
|
|
|
While expr block {
|
|
|
|
let region = cover $1 $3.region
|
2019-03-13 19:29:25 +04:00
|
|
|
and value = {
|
|
|
|
kwd_while = $1;
|
|
|
|
cond = $2;
|
|
|
|
block = $3}
|
|
|
|
in While {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for_loop:
|
2019-03-20 17:57:55 +04:00
|
|
|
For var_assign Down? To expr option(step_clause) block {
|
2019-02-26 01:29:29 +04:00
|
|
|
let region = cover $1 $7.region in
|
2019-03-20 16:27:55 +04:00
|
|
|
let value = {
|
|
|
|
kwd_for = $1;
|
|
|
|
assign = $2;
|
|
|
|
down = $3;
|
|
|
|
kwd_to = $4;
|
|
|
|
bound = $5;
|
|
|
|
step = $6;
|
|
|
|
block = $7}
|
2019-02-26 01:29:29 +04:00
|
|
|
in For (ForInt {region; value})
|
|
|
|
}
|
|
|
|
| For var option(arrow_clause) In expr block {
|
|
|
|
let region = cover $1 $6.region in
|
2019-03-14 12:59:26 +04:00
|
|
|
let value = {
|
|
|
|
kwd_for = $1;
|
|
|
|
var = $2;
|
|
|
|
bind_to = $3;
|
|
|
|
kwd_in = $4;
|
|
|
|
expr = $5;
|
|
|
|
block = $6}
|
2019-02-26 01:29:29 +04:00
|
|
|
in For (ForCollect {region; value})
|
|
|
|
}
|
|
|
|
|
2019-03-20 17:57:55 +04:00
|
|
|
var_assign:
|
|
|
|
var ASS expr {
|
|
|
|
let region = cover $1.region (expr_to_region $3)
|
|
|
|
and value = {name = $1; assign = $2; expr = $3}
|
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
step_clause:
|
|
|
|
Step expr { $1,$2 }
|
|
|
|
|
|
|
|
arrow_clause:
|
|
|
|
ARROW var { $1,$2 }
|
|
|
|
|
|
|
|
(* Expressions *)
|
|
|
|
|
2019-03-11 15:51:50 +04:00
|
|
|
interactive_expr:
|
|
|
|
expr EOF { $1 }
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
expr:
|
2019-03-20 15:28:25 +04:00
|
|
|
expr Or conj_expr {
|
2019-02-26 01:29:29 +04:00
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3} in
|
2019-03-21 00:36:12 +04:00
|
|
|
ELogic (BoolExpr (Or {region; value}))
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| conj_expr { $1 }
|
|
|
|
|
|
|
|
conj_expr:
|
2019-03-20 15:28:25 +04:00
|
|
|
conj_expr And comp_expr {
|
2019-02-26 01:29:29 +04:00
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-21 00:36:12 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
|
|
|
in ELogic (BoolExpr (And {region; value}))
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| comp_expr { $1 }
|
|
|
|
|
|
|
|
comp_expr:
|
|
|
|
comp_expr LT cat_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-21 00:36:12 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
|
|
|
in ELogic (CompExpr (Lt {region; value}))
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| comp_expr LEQ cat_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in ELogic (CompExpr (Leq {region; value}))
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| comp_expr GT cat_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in ELogic (CompExpr (Gt {region; value}))
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| comp_expr GEQ cat_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in ELogic (CompExpr (Geq {region; value}))
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| comp_expr EQUAL cat_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in ELogic (CompExpr (Equal {region; value}))
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| comp_expr NEQ cat_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in ELogic (CompExpr (Neq {region; value}))
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| cat_expr { $1 }
|
|
|
|
|
|
|
|
cat_expr:
|
|
|
|
cons_expr CAT cat_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in EString (Cat {region; value})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| cons_expr { $1 }
|
|
|
|
|
|
|
|
cons_expr:
|
|
|
|
add_expr CONS cons_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in EList (Cons {region; value})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| add_expr { $1 }
|
|
|
|
|
|
|
|
add_expr:
|
|
|
|
add_expr PLUS mult_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in EArith (Add {region; value})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| add_expr MINUS mult_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in EArith (Sub {region; value})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| mult_expr { $1 }
|
|
|
|
|
|
|
|
mult_expr:
|
|
|
|
mult_expr TIMES unary_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in EArith (Mult {region; value})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| mult_expr SLASH unary_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in EArith (Div {region; value})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| mult_expr Mod unary_expr {
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region $3 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover start stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
2019-03-21 00:36:12 +04:00
|
|
|
in EArith (Mod {region; value})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| unary_expr { $1 }
|
|
|
|
|
|
|
|
unary_expr:
|
|
|
|
MINUS core_expr {
|
|
|
|
let stop = expr_to_region $2 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover $1 stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {op = $1; arg = $2}
|
2019-03-21 00:36:12 +04:00
|
|
|
in EArith (Neg {region; value})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| Not core_expr {
|
|
|
|
let stop = expr_to_region $2 in
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = cover $1 stop
|
2019-03-18 20:47:11 +04:00
|
|
|
and value = {op = $1; arg = $2} in
|
2019-03-21 00:36:12 +04:00
|
|
|
ELogic (BoolExpr (Not {region; value}))
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| core_expr { $1 }
|
|
|
|
|
|
|
|
core_expr:
|
2019-03-21 00:36:12 +04:00
|
|
|
Int { EArith (Int $1) }
|
|
|
|
| var { EVar $1 }
|
|
|
|
| String { EString (String $1) }
|
|
|
|
| Bytes { EBytes $1 }
|
|
|
|
| C_False { ELogic (BoolExpr (False $1)) }
|
|
|
|
| C_True { ELogic (BoolExpr (True $1)) }
|
|
|
|
| C_Unit { EUnit $1 }
|
|
|
|
| tuple { ETuple $1 }
|
|
|
|
| list_expr { EList (List $1) }
|
|
|
|
| empty_list { EList (EmptyList $1) }
|
|
|
|
| none_expr { EConstr (NoneExpr $1) }
|
|
|
|
| fun_call { ECall $1 }
|
|
|
|
| map_expr { EMap $1 }
|
|
|
|
| record_expr { ERecord $1 }
|
2019-02-26 01:29:29 +04:00
|
|
|
| Constr arguments {
|
|
|
|
let region = cover $1.region $2.region in
|
2019-03-21 00:36:12 +04:00
|
|
|
EConstr (ConstrApp {region; value = $1,$2})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
| C_Some arguments {
|
|
|
|
let region = cover $1 $2.region in
|
2019-03-21 00:36:12 +04:00
|
|
|
EConstr (SomeApp {region; value = $1,$2})
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
2019-03-14 16:19:52 +04:00
|
|
|
|
2019-03-20 12:11:19 +04:00
|
|
|
map_expr:
|
2019-03-20 17:57:55 +04:00
|
|
|
map_lookup { MapLookUp $1 }
|
2019-03-20 12:11:19 +04:00
|
|
|
|
2019-03-20 12:45:32 +04:00
|
|
|
path:
|
|
|
|
var { Name $1 }
|
|
|
|
| record_projection { RecordPath $1 }
|
|
|
|
|
2019-03-20 17:57:55 +04:00
|
|
|
map_lookup:
|
2019-03-20 12:45:32 +04:00
|
|
|
path brackets(expr) {
|
|
|
|
let region = cover (path_to_region $1) $2.region in
|
2019-03-14 12:59:26 +04:00
|
|
|
let value = {
|
2019-03-20 12:45:32 +04:00
|
|
|
path = $1;
|
2019-03-20 12:26:24 +04:00
|
|
|
index = $2}
|
2019-03-14 16:19:52 +04:00
|
|
|
in {region; value}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
2019-03-14 12:59:26 +04:00
|
|
|
|
|
|
|
record_expr:
|
|
|
|
record_injection { RecordInj $1 }
|
|
|
|
| record_projection { RecordProj $1 }
|
|
|
|
|
|
|
|
record_injection:
|
2019-03-20 12:11:19 +04:00
|
|
|
Record series(field_assignment) {
|
|
|
|
let first, (others, terminator, close) = $2 in
|
|
|
|
let region = cover $1 close
|
|
|
|
and value = {
|
|
|
|
opening = $1;
|
|
|
|
fields = first, others;
|
|
|
|
terminator;
|
|
|
|
close}
|
|
|
|
in {region; value}
|
2019-03-14 12:59:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
field_assignment:
|
|
|
|
field_name EQUAL expr {
|
|
|
|
let region = cover $1.region (expr_to_region $3)
|
|
|
|
and value = {
|
|
|
|
field_name = $1;
|
|
|
|
equal = $2;
|
|
|
|
field_expr = $3}
|
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
|
|
|
record_projection:
|
2019-03-18 20:47:11 +04:00
|
|
|
record_name DOT nsepseq(field_name,DOT) {
|
|
|
|
let stop = nsepseq_to_region (fun x -> x.region) $3 in
|
|
|
|
let region = cover $1.region stop
|
|
|
|
and value = {
|
2019-03-14 12:59:26 +04:00
|
|
|
record_name = $1;
|
|
|
|
selector = $2;
|
2019-03-18 20:47:11 +04:00
|
|
|
field_path = $3}
|
2019-03-14 12:59:26 +04:00
|
|
|
in {region; value}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
fun_call:
|
|
|
|
fun_name arguments {
|
|
|
|
let region = cover $1.region $2.region
|
|
|
|
in {region; value = $1,$2}
|
|
|
|
}
|
|
|
|
|
|
|
|
tuple:
|
|
|
|
par(nsepseq(expr,COMMA)) { $1 }
|
|
|
|
|
|
|
|
arguments:
|
|
|
|
tuple { $1 }
|
|
|
|
|
|
|
|
list_expr:
|
|
|
|
brackets(nsepseq(expr,COMMA)) { $1 }
|
|
|
|
|
|
|
|
empty_list:
|
2019-03-13 19:29:25 +04:00
|
|
|
par(typed_empty_list) { $1 }
|
|
|
|
|
|
|
|
typed_empty_list:
|
|
|
|
LBRACKET RBRACKET COLON type_expr {
|
|
|
|
{lbracket = $1;
|
|
|
|
rbracket = $2;
|
|
|
|
colon = $3;
|
|
|
|
list_type = $4}
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
none_expr:
|
2019-03-13 19:29:25 +04:00
|
|
|
par(typed_none_expr) { $1 }
|
|
|
|
|
|
|
|
typed_none_expr:
|
|
|
|
C_None COLON type_expr {
|
|
|
|
{c_None = $1;
|
|
|
|
colon = $2;
|
|
|
|
opt_type = $3}
|
|
|
|
}
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
(* Patterns *)
|
|
|
|
|
|
|
|
pattern:
|
|
|
|
nsepseq(core_pattern,CONS) {
|
2019-03-13 19:29:25 +04:00
|
|
|
let region = nsepseq_to_region pattern_to_region $1
|
|
|
|
in PCons {region; value=$1}
|
2019-02-26 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
core_pattern:
|
|
|
|
var { PVar $1 }
|
|
|
|
| WILD { PWild $1 }
|
|
|
|
| Int { PInt $1 }
|
|
|
|
| String { PString $1 }
|
|
|
|
| C_Unit { PUnit $1 }
|
|
|
|
| C_False { PFalse $1 }
|
|
|
|
| C_True { PTrue $1 }
|
|
|
|
| C_None { PNone $1 }
|
|
|
|
| list_patt { PList $1 }
|
|
|
|
| tuple_patt { PTuple $1 }
|
|
|
|
| C_Some par(core_pattern) {
|
|
|
|
let region = cover $1 $2.region
|
|
|
|
in PSome {region; value = $1,$2}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_patt:
|
|
|
|
brackets(sepseq(core_pattern,COMMA)) { Sugar $1 }
|
|
|
|
| par(cons_pattern) { Raw $1 }
|
|
|
|
|
|
|
|
cons_pattern:
|
|
|
|
core_pattern CONS pattern { $1,$2,$3 }
|
|
|
|
|
|
|
|
tuple_patt:
|
|
|
|
par(nsepseq(core_pattern,COMMA)) { $1 }
|