I relaxed the extension to the grammar that enabled non-annotated
empty lists and None values as initial values in declarations. Now, these values are accepted irrespective of the declared type. It is up to the typechecker to validate them.
This commit is contained in:
parent
d994592a1b
commit
c3b304db4a
58
Parser.mly
58
Parser.mly
@ -368,42 +368,21 @@ const_decl:
|
|||||||
}
|
}
|
||||||
|
|
||||||
var_decl:
|
var_decl:
|
||||||
Var var COLON var_decl_type_expr ASS expr option(SEMI) {
|
Var var COLON type_expr ASS extended_expr option(SEMI) {
|
||||||
let stop =
|
let stop = match $7 with
|
||||||
match $7 with
|
Some region -> region
|
||||||
Some region -> region
|
| None -> $6.region in
|
||||||
| None -> expr_to_region $6 in
|
|
||||||
let region = cover $1 stop in
|
let region = cover $1 stop in
|
||||||
let value = {
|
|
||||||
kwd_var = $1;
|
|
||||||
name = $2;
|
|
||||||
colon = $3;
|
|
||||||
var_type = $4;
|
|
||||||
assign = $5;
|
|
||||||
init = $6;
|
|
||||||
terminator = $7}
|
|
||||||
in {region; value}
|
|
||||||
}
|
|
||||||
| Var var COLON type_name type_tuple
|
|
||||||
ASS extended_expr option(SEMI) {
|
|
||||||
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 -> $7.region in
|
|
||||||
let region = cover $1 stop in
|
|
||||||
let init =
|
let init =
|
||||||
match $7.value with
|
match $6.value with
|
||||||
`Expr e -> e
|
`Expr e -> e
|
||||||
| `EList (lbracket, rbracket) ->
|
| `EList (lbracket, rbracket) ->
|
||||||
let region = $7.region
|
let region = $6.region
|
||||||
and value = {
|
and value = {
|
||||||
lbracket;
|
lbracket;
|
||||||
rbracket;
|
rbracket;
|
||||||
colon = Region.ghost;
|
colon = Region.ghost;
|
||||||
list_type = var_type} in
|
list_type = $4} in
|
||||||
let value = {
|
let value = {
|
||||||
lpar = Region.ghost;
|
lpar = Region.ghost;
|
||||||
inside = value;
|
inside = value;
|
||||||
@ -415,17 +394,17 @@ var_decl:
|
|||||||
inside = {
|
inside = {
|
||||||
c_None = region;
|
c_None = region;
|
||||||
colon = Region.ghost;
|
colon = Region.ghost;
|
||||||
opt_type = var_type};
|
opt_type = $4};
|
||||||
rpar = Region.ghost}
|
rpar = Region.ghost}
|
||||||
in ConstrExpr (NoneExpr {region; value}) in
|
in ConstrExpr (NoneExpr {region; value}) in
|
||||||
let value = {
|
let value = {
|
||||||
kwd_var = $1;
|
kwd_var = $1;
|
||||||
name = $2;
|
name = $2;
|
||||||
colon = $3;
|
colon = $3;
|
||||||
var_type;
|
var_type = $4;
|
||||||
assign = $6;
|
assign = $5;
|
||||||
init;
|
init;
|
||||||
terminator = $8}
|
terminator = $7}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,21 +415,6 @@ extended_expr:
|
|||||||
value = `EList ($1,$2)} }
|
value = `EList ($1,$2)} }
|
||||||
| C_None { {region = $1; value = `ENone $1} }
|
| 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:
|
instruction:
|
||||||
single_instr { Single $1 }
|
single_instr { Single $1 }
|
||||||
| block { Block $1 }
|
| block { Block $1 }
|
||||||
|
@ -15,7 +15,7 @@ entrypoint contribute (storage store : state;
|
|||||||
if now > store.deadline then
|
if now > store.deadline then
|
||||||
fail "Deadline passed"
|
fail "Deadline passed"
|
||||||
else
|
else
|
||||||
match store.backers[sender] with
|
case store.backers[sender] of
|
||||||
None ->
|
None ->
|
||||||
store :=
|
store :=
|
||||||
copy store with
|
copy store with
|
||||||
@ -50,7 +50,7 @@ entrypoint claim (storage store : state; const sender : address)
|
|||||||
if now <= store.deadline then
|
if now <= store.deadline then
|
||||||
fail "Too soon"
|
fail "Too soon"
|
||||||
else
|
else
|
||||||
match store.backers[sender] with
|
case store.backers[sender] of
|
||||||
None ->
|
None ->
|
||||||
fail "Not a backer"
|
fail "Not a backer"
|
||||||
| Some (amount) ->
|
| Some (amount) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user