I relaxed the grammar to support in the parser for initial values of

variables to not require type annotation, like

var x : list (operation) := []
This commit is contained in:
Christian Rinderknecht 2019-03-19 10:52:47 +01:00
parent 46d6df2146
commit 6c5ae52db6
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
2 changed files with 62 additions and 19 deletions

View File

@ -368,7 +368,7 @@ const_decl:
}
var_decl:
Var var COLON type_expr ASS expr option(SEMI) {
Var var COLON var_decl_type_expr ASS expr option(SEMI) {
let stop =
match $7 with
Some region -> region
@ -384,30 +384,73 @@ var_decl:
terminator = $7}
in {region; value}
}
(*
| Var var COLON type_name type_tuple
ASS extended_expr option(SEMI) {
let stop =
match $7 with
let region = cover $4.region $5.region in
let type_app = TypeApp {region; value=$4,$5} in
let cartesian = {region; value = type_app, []} in
let var_type = Prod cartesian in
let stop = match $8 with
Some region -> region
| None -> expr_to_region $6 in
| None -> $7.region in
let region = cover $1 stop in
let init =
match $7.value with
`Expr e -> e
| `EList (lbracket, rbracket) ->
let region = $7.region
and value = {
lbracket;
rbracket;
colon = Region.ghost;
list_type = var_type} in
let value = {
lpar = Region.ghost;
inside = value;
rpar = Region.ghost} in
ListExpr (EmptyList {region; value})
| `ENone region ->
let value = {
lpar = Region.ghost;
inside = {
c_None = region;
colon = Region.ghost;
opt_type = var_type};
rpar = Region.ghost}
in ConstrExpr (NoneExpr {region; value}) in
let value = {
kwd_var = $1;
name = $2;
colon = $3;
var_type = $4;
ass = $5;
init = $6;
terminator = $7}
var_type;
assign = $6;
init;
terminator = $8}
in {region; value}
}
extended_expr:
expr { }
| LBRACKET RBRACKET { }
| C_None { }
*)
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} }
var_decl_type_expr:
var_decl_cartesian { Prod $1 }
| sum_type { Sum $1 }
| record_type { Record $1 }
var_decl_cartesian:
nsepseq(var_decl_core_type,TIMES) {
let region = nsepseq_to_region type_expr_to_region $1
in {region; value=$1}
}
var_decl_core_type:
type_name { TAlias $1 }
| par(type_expr) { ParType $1 }
instruction:
single_instr { Single $1 }
| block { Block $1 }

View File

@ -10,7 +10,7 @@ entrypoint contribute (storage store : state;
const sender : address;
const amount : mutez)
: state * list (operation) is
var operations : list (operation) := ([] : list (operation)) // TODO
var operations : list (operation) := []
begin
if now > store.deadline then
fail "Deadline passed"
@ -26,9 +26,9 @@ entrypoint contribute (storage store : state;
end
end with (store, operations)
entrypoint get_funds (storage store : state; const sender : address)
entrypoint withdraw (storage store : state; const sender : address)
: state * list (operation) is
var operations : list (operation) := ([] : list (operation)) // TODO
var operations : list (operation) := []
begin
if sender = owner then
if now >= store.deadline then
@ -44,7 +44,7 @@ entrypoint get_funds (storage store : state; const sender : address)
entrypoint claim (storage store : state; const sender : address)
: state * list (operation) is
var operations : list (operation) := ([] : list (operation)) // TODO
var operations : list (operation) := []
var amount : mutez := 0
begin
if now <= store.deadline then