Added alternate syntax for "case" constructs (both expression and instruction).

New syntax: case ... of [ ... ]
This commit is contained in:
Christian Rinderknecht 2019-04-01 20:59:37 +02:00
parent 9a4ff35fc7
commit 99defca21a
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
4 changed files with 43 additions and 29 deletions

View File

@ -419,12 +419,12 @@ and set_membership = {
} }
and 'a case = { and 'a case = {
kwd_case : kwd_case; kwd_case : kwd_case;
expr : expr; expr : expr;
kwd_of : kwd_of; opening : opening;
lead_vbar : vbar option; lead_vbar : vbar option;
cases : ('a case_clause reg, vbar) nsepseq reg; cases : ('a case_clause reg, vbar) nsepseq reg;
kwd_end : kwd_end closing : closing
} }
and 'a case_clause = { and 'a case_clause = {
@ -1111,14 +1111,14 @@ and print_if_clause = function
print_token rbrace "}" print_token rbrace "}"
and print_case_instr (node : instruction case) = and print_case_instr (node : instruction case) =
let {kwd_case; expr; kwd_of; let {kwd_case; expr; opening;
lead_vbar; cases; kwd_end} = node in lead_vbar; cases; closing} = node in
print_token kwd_case "case"; print_token kwd_case "case";
print_expr expr; print_expr expr;
print_token kwd_of "of"; print_opening "of" opening;
print_token_opt lead_vbar "|"; print_token_opt lead_vbar "|";
print_cases_instr cases; print_cases_instr cases;
print_token kwd_end "end" print_closing closing
and print_token_opt = function and print_token_opt = function
None -> fun _ -> () None -> fun _ -> ()
@ -1222,14 +1222,14 @@ and print_expr = function
| EPar e -> print_par_expr e | EPar e -> print_par_expr e
and print_case_expr (node : expr case) = and print_case_expr (node : expr case) =
let {kwd_case; expr; kwd_of; let {kwd_case; expr; opening;
lead_vbar; cases; kwd_end} = node in lead_vbar; cases; closing} = node in
print_token kwd_case "case"; print_token kwd_case "case";
print_expr expr; print_expr expr;
print_token kwd_of "of"; print_opening "of" opening;
print_token_opt lead_vbar "|"; print_token_opt lead_vbar "|";
print_cases_expr cases; print_cases_expr cases;
print_token kwd_end "end" print_closing closing
and print_cases_expr {value; _} = and print_cases_expr {value; _} =
print_nsepseq "|" print_case_clause_expr value print_nsepseq "|" print_case_clause_expr value

View File

@ -405,10 +405,10 @@ and set_membership = {
and 'a case = { and 'a case = {
kwd_case : kwd_case; kwd_case : kwd_case;
expr : expr; expr : expr;
kwd_of : kwd_of; opening : opening;
lead_vbar : vbar option; lead_vbar : vbar option;
cases : ('a case_clause reg, vbar) nsepseq reg; cases : ('a case_clause reg, vbar) nsepseq reg;
kwd_end : kwd_end closing : closing
} }
and 'a case_clause = { and 'a case_clause = {

View File

@ -686,18 +686,22 @@ case_instr:
let value = { let value = {
kwd_case = $1; kwd_case = $1;
expr = $2; expr = $2;
kwd_of = $3; opening = Kwd $3;
lead_vbar = $4; lead_vbar = $4;
cases = $5; cases = $5;
kwd_end = $6} closing = End $6}
in {region; value}} in {region; value}
(*| Case expr LBRACKET option(VBAR) case_instr RBRACKET {
let region = cover $1 $6 in
let value = {
k
}
} }
*) | Case expr Of LBRACKET option(VBAR) cases_instr 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 {region; value}}
cases_instr: cases_instr:
nsepseq(case_clause_instr,VBAR) { nsepseq(case_clause_instr,VBAR) {
@ -790,10 +794,20 @@ case_expr:
let value : expr case = { let value : expr case = {
kwd_case = $1; kwd_case = $1;
expr = $2; expr = $2;
kwd_of = $3; opening = Kwd $3;
lead_vbar = $4; lead_vbar = $4;
cases = $5; 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}} in ECase {region; value}}
cases_expr: cases_expr:

View File

@ -17,11 +17,11 @@ entrypoint contribute (storage store : store;
if now > store.deadline then if now > store.deadline then
fail "Deadline passed"; fail "Deadline passed";
else else
case store.backers[sender] of case store.backers[sender] of [
None -> store.backers[sender] := Some (amount) None -> store.backers[sender] := Some (amount)
// None -> patch store.backers with map sender -> amount end // None -> patch store.backers with map sender -> amount end
| _ -> skip | _ -> skip
end ]
} with (store, operations) } with (store, operations)
entrypoint withdraw (storage store : store; const sender : address) entrypoint withdraw (storage store : store; const sender : address)