Changed "match ... with ..." to "case ... of ..."

This commit is contained in:
Christian Rinderknecht 2019-03-19 11:46:30 +01:00
parent 6c5ae52db6
commit d994592a1b
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
6 changed files with 34 additions and 34 deletions

22
AST.ml
View File

@ -40,6 +40,7 @@ let sepseq_to_region to_region = function
(* Keywords of LIGO *)
type kwd_begin = Region.t
type kwd_case = Region.t
type kwd_const = Region.t
type kwd_copy = Region.t
type kwd_down = Region.t
@ -52,7 +53,6 @@ type kwd_function = Region.t
type kwd_if = Region.t
type kwd_in = Region.t
type kwd_is = Region.t
type kwd_match = Region.t
type kwd_mod = Region.t
type kwd_not = Region.t
type kwd_of = Region.t
@ -319,7 +319,7 @@ and instruction =
and single_instr =
Cond of conditional reg
| Match of match_instr reg
| Case of case_instr reg
| Assign of assignment reg
| Loop of loop
| ProcCall of fun_call
@ -340,10 +340,10 @@ and conditional = {
ifnot : instruction
}
and match_instr = {
kwd_match : kwd_match;
and case_instr = {
kwd_case : kwd_case;
expr : expr;
kwd_with : kwd_with;
kwd_of : kwd_of;
lead_vbar : vbar option;
cases : cases;
kwd_end : kwd_end
@ -645,7 +645,7 @@ and record_expr_to_region = function
let instr_to_region = function
Single Cond {region; _}
| Single Match {region; _}
| Single Case {region; _}
| Single Assign {region; _}
| Single Loop While {region; _}
| Single Loop For ForInt {region; _}
@ -932,7 +932,7 @@ and print_instruction = function
and print_single_instr = function
Cond {value; _} -> print_conditional value
| Match {value; _} -> print_match_instr value
| Case {value; _} -> print_case_instr value
| Assign assign -> print_assignment assign
| Loop loop -> print_loop loop
| ProcCall fun_call -> print_fun_call fun_call
@ -953,12 +953,12 @@ and print_conditional node =
print_token kwd_else "else";
print_instruction ifnot
and print_match_instr node =
let {kwd_match; expr; kwd_with;
and print_case_instr (node : case_instr) =
let {kwd_case; expr; kwd_of;
lead_vbar; cases; kwd_end} = node in
print_token kwd_match "match";
print_token kwd_case "case";
print_expr expr;
print_token kwd_with "with";
print_token kwd_of "of";
print_token_opt lead_vbar "|";
print_cases cases;
print_token kwd_end "end"

22
AST.mli
View File

@ -24,6 +24,7 @@ val sepseq_to_region : ('a -> Region.t) -> ('a,'sep) sepseq -> Region.t
(* Keywords of LIGO *)
type kwd_begin = Region.t
type kwd_case = Region.t
type kwd_const = Region.t
type kwd_copy = Region.t
type kwd_down = Region.t
@ -36,7 +37,6 @@ type kwd_function = Region.t
type kwd_if = Region.t
type kwd_in = Region.t
type kwd_is = Region.t
type kwd_match = Region.t
type kwd_mod = Region.t
type kwd_not = Region.t
type kwd_of = Region.t
@ -302,13 +302,13 @@ and instruction =
| Block of block reg
and single_instr =
Cond of conditional reg
| Match of match_instr reg
| Assign of assignment reg
| Loop of loop
| ProcCall of fun_call
| Fail of fail_instr reg
| Skip of kwd_skip
Cond of conditional reg
| Case of case_instr reg
| Assign of assignment reg
| Loop of loop
| ProcCall of fun_call
| Fail of fail_instr reg
| Skip of kwd_skip
and fail_instr = {
kwd_fail : kwd_fail;
@ -324,10 +324,10 @@ and conditional = {
ifnot : instruction
}
and match_instr = {
kwd_match : kwd_match;
and case_instr = {
kwd_case : kwd_case;
expr : expr;
kwd_with : kwd_with;
kwd_of : kwd_of;
lead_vbar : vbar option;
cases : cases;
kwd_end : kwd_end

View File

@ -68,6 +68,7 @@ type t =
(* Keywords *)
| Begin of Region.t (* "begin" *)
| Case of Region.t (* "case" *)
| Const of Region.t (* "const" *)
| Copy of Region.t (* "copy" *)
| Down of Region.t (* "down" *)
@ -84,7 +85,6 @@ type t =
| End of Region.t (* "end" *)
| Then of Region.t (* "then" *)
| Else of Region.t (* "else" *)
| Match of Region.t (* "match" *)
| Procedure of Region.t (* "procedure" *)
| Record of Region.t (* "record" *)
| Skip of Region.t (* "skip" *)

View File

@ -67,6 +67,7 @@ type t =
(* Keywords *)
| Begin of Region.t
| Case of Region.t
| Const of Region.t
| Copy of Region.t
| Down of Region.t
@ -83,7 +84,6 @@ type t =
| End of Region.t
| Then of Region.t
| Else of Region.t
| Match of Region.t
| Procedure of Region.t
| Record of Region.t
| Skip of Region.t
@ -186,6 +186,7 @@ let proj_token = function
(* Keywords *)
| Begin region -> region, "Begin"
| Case region -> region, "Case"
| Const region -> region, "Const"
| Copy region -> region, "Copy"
| Down region -> region, "Down"
@ -202,7 +203,6 @@ let proj_token = function
| End region -> region, "End"
| Then region -> region, "Then"
| Else region -> region, "Else"
| Match region -> region, "Match"
| Procedure region -> region, "Procedure"
| Record region -> region, "Record"
| Skip region -> region, "Skip"
@ -270,6 +270,7 @@ let to_lexeme = function
(* Keywords *)
| Begin _ -> "begin"
| Case _ -> "case"
| Const _ -> "const"
| Copy _ -> "copy"
| Down _ -> "down"
@ -286,7 +287,6 @@ let to_lexeme = function
| End _ -> "end"
| Then _ -> "then"
| Else _ -> "else"
| Match _ -> "match"
| Procedure _ -> "procedure"
| Record _ -> "record"
| Skip _ -> "skip"
@ -322,6 +322,7 @@ let to_region token = proj_token token |> fst
let keywords = [
(fun reg -> Begin reg);
(fun reg -> Case reg);
(fun reg -> Const reg);
(fun reg -> Copy reg);
(fun reg -> Down reg);
@ -338,7 +339,6 @@ let keywords = [
(fun reg -> End reg);
(fun reg -> Then reg);
(fun reg -> Else reg);
(fun reg -> Match reg);
(fun reg -> Procedure reg);
(fun reg -> Record reg);
(fun reg -> Skip reg);
@ -546,6 +546,7 @@ let is_ident = function
let is_kwd = function
Begin _
| Case _
| Const _
| Copy _
| Down _
@ -562,7 +563,6 @@ let is_kwd = function
| End _
| Then _
| Else _
| Match _
| Procedure _
| Record _
| Skip _

View File

@ -45,6 +45,7 @@
(* Keywords *)
%token <Region.t> Begin (* "begin" *)
%token <Region.t> Case (* "case" *)
%token <Region.t> Const (* "const" *)
%token <Region.t> Copy (* "copy" *)
%token <Region.t> Down (* "down" *)
@ -61,7 +62,6 @@
%token <Region.t> End (* "end" *)
%token <Region.t> Then (* "then" *)
%token <Region.t> Else (* "else" *)
%token <Region.t> Match (* "match" *)
%token <Region.t> Procedure (* "procedure" *)
%token <Region.t> Record (* "record" *)
%token <Region.t> Skip (* "skip" *)

View File

@ -457,7 +457,7 @@ instruction:
single_instr:
conditional { Cond $1 }
| match_instr { Match $1 }
| case_instr { Case $1 }
| assignment { Assign $1 }
| loop { Loop $1 }
| proc_call { ProcCall $1 }
@ -486,13 +486,13 @@ conditional:
in {region; value}
}
match_instr:
Match expr With option(VBAR) cases End {
case_instr:
Case expr Of option(VBAR) cases End {
let region = cover $1 $6 in
let value = {
kwd_match = $1;
kwd_case = $1;
expr = $2;
kwd_with = $3;
kwd_of = $3;
lead_vbar = $4;
cases = $5;
kwd_end = $6}