Added alternate syntax for "case" constructs (both expression and instruction).
New syntax: case ... of [ ... ]
This commit is contained in:
parent
9a4ff35fc7
commit
99defca21a
@ -421,10 +421,10 @@ and set_membership = {
|
||||
and 'a case = {
|
||||
kwd_case : kwd_case;
|
||||
expr : expr;
|
||||
kwd_of : kwd_of;
|
||||
opening : opening;
|
||||
lead_vbar : vbar option;
|
||||
cases : ('a case_clause reg, vbar) nsepseq reg;
|
||||
kwd_end : kwd_end
|
||||
closing : closing
|
||||
}
|
||||
|
||||
and 'a case_clause = {
|
||||
@ -1111,14 +1111,14 @@ and print_if_clause = function
|
||||
print_token rbrace "}"
|
||||
|
||||
and print_case_instr (node : instruction case) =
|
||||
let {kwd_case; expr; kwd_of;
|
||||
lead_vbar; cases; kwd_end} = node in
|
||||
let {kwd_case; expr; opening;
|
||||
lead_vbar; cases; closing} = node in
|
||||
print_token kwd_case "case";
|
||||
print_expr expr;
|
||||
print_token kwd_of "of";
|
||||
print_opening "of" opening;
|
||||
print_token_opt lead_vbar "|";
|
||||
print_cases_instr cases;
|
||||
print_token kwd_end "end"
|
||||
print_closing closing
|
||||
|
||||
and print_token_opt = function
|
||||
None -> fun _ -> ()
|
||||
@ -1222,14 +1222,14 @@ and print_expr = function
|
||||
| EPar e -> print_par_expr e
|
||||
|
||||
and print_case_expr (node : expr case) =
|
||||
let {kwd_case; expr; kwd_of;
|
||||
lead_vbar; cases; kwd_end} = node in
|
||||
let {kwd_case; expr; opening;
|
||||
lead_vbar; cases; closing} = node in
|
||||
print_token kwd_case "case";
|
||||
print_expr expr;
|
||||
print_token kwd_of "of";
|
||||
print_opening "of" opening;
|
||||
print_token_opt lead_vbar "|";
|
||||
print_cases_expr cases;
|
||||
print_token kwd_end "end"
|
||||
print_closing closing
|
||||
|
||||
and print_cases_expr {value; _} =
|
||||
print_nsepseq "|" print_case_clause_expr value
|
||||
|
@ -405,10 +405,10 @@ and set_membership = {
|
||||
and 'a case = {
|
||||
kwd_case : kwd_case;
|
||||
expr : expr;
|
||||
kwd_of : kwd_of;
|
||||
opening : opening;
|
||||
lead_vbar : vbar option;
|
||||
cases : ('a case_clause reg, vbar) nsepseq reg;
|
||||
kwd_end : kwd_end
|
||||
closing : closing
|
||||
}
|
||||
|
||||
and 'a case_clause = {
|
||||
|
@ -686,18 +686,22 @@ case_instr:
|
||||
let value = {
|
||||
kwd_case = $1;
|
||||
expr = $2;
|
||||
kwd_of = $3;
|
||||
opening = Kwd $3;
|
||||
lead_vbar = $4;
|
||||
cases = $5;
|
||||
kwd_end = $6}
|
||||
in {region; value}}
|
||||
(*| Case expr LBRACKET option(VBAR) case_instr RBRACKET {
|
||||
let region = cover $1 $6 in
|
||||
closing = End $6}
|
||||
in {region; value}
|
||||
}
|
||||
| Case expr Of LBRACKET option(VBAR) cases_instr RBRACKET {
|
||||
let region = cover $1 $7 in
|
||||
let value = {
|
||||
k
|
||||
}
|
||||
}
|
||||
*)
|
||||
kwd_case = $1;
|
||||
expr = $2;
|
||||
opening = KwdBracket ($3,$4);
|
||||
lead_vbar = $5;
|
||||
cases = $6;
|
||||
closing = RBracket $7}
|
||||
in {region; value}}
|
||||
|
||||
cases_instr:
|
||||
nsepseq(case_clause_instr,VBAR) {
|
||||
@ -790,10 +794,20 @@ case_expr:
|
||||
let value : expr case = {
|
||||
kwd_case = $1;
|
||||
expr = $2;
|
||||
kwd_of = $3;
|
||||
opening = Kwd $3;
|
||||
lead_vbar = $4;
|
||||
cases = $5;
|
||||
kwd_end = $6}
|
||||
closing = End $6}
|
||||
in ECase {region; value}}
|
||||
| Case expr Of LBRACKET option(VBAR) cases_expr RBRACKET {
|
||||
let region = cover $1 $7 in
|
||||
let value = {
|
||||
kwd_case = $1;
|
||||
expr = $2;
|
||||
opening = KwdBracket ($3,$4);
|
||||
lead_vbar = $5;
|
||||
cases = $6;
|
||||
closing = RBracket $7}
|
||||
in ECase {region; value}}
|
||||
|
||||
cases_expr:
|
||||
|
@ -17,11 +17,11 @@ entrypoint contribute (storage store : store;
|
||||
if now > store.deadline then
|
||||
fail "Deadline passed";
|
||||
else
|
||||
case store.backers[sender] of
|
||||
case store.backers[sender] of [
|
||||
None -> store.backers[sender] := Some (amount)
|
||||
// None -> patch store.backers with map sender -> amount end
|
||||
| _ -> skip
|
||||
end
|
||||
]
|
||||
} with (store, operations)
|
||||
|
||||
entrypoint withdraw (storage store : store; const sender : address)
|
||||
|
Loading…
Reference in New Issue
Block a user