Changed "match ... with ..." to "case ... of ..."
This commit is contained in:
parent
6c5ae52db6
commit
d994592a1b
22
AST.ml
22
AST.ml
@ -40,6 +40,7 @@ let sepseq_to_region to_region = function
|
|||||||
(* Keywords of LIGO *)
|
(* Keywords of LIGO *)
|
||||||
|
|
||||||
type kwd_begin = Region.t
|
type kwd_begin = Region.t
|
||||||
|
type kwd_case = Region.t
|
||||||
type kwd_const = Region.t
|
type kwd_const = Region.t
|
||||||
type kwd_copy = Region.t
|
type kwd_copy = Region.t
|
||||||
type kwd_down = Region.t
|
type kwd_down = Region.t
|
||||||
@ -52,7 +53,6 @@ type kwd_function = Region.t
|
|||||||
type kwd_if = Region.t
|
type kwd_if = Region.t
|
||||||
type kwd_in = Region.t
|
type kwd_in = Region.t
|
||||||
type kwd_is = Region.t
|
type kwd_is = Region.t
|
||||||
type kwd_match = Region.t
|
|
||||||
type kwd_mod = Region.t
|
type kwd_mod = Region.t
|
||||||
type kwd_not = Region.t
|
type kwd_not = Region.t
|
||||||
type kwd_of = Region.t
|
type kwd_of = Region.t
|
||||||
@ -319,7 +319,7 @@ and instruction =
|
|||||||
|
|
||||||
and single_instr =
|
and single_instr =
|
||||||
Cond of conditional reg
|
Cond of conditional reg
|
||||||
| Match of match_instr reg
|
| Case of case_instr reg
|
||||||
| Assign of assignment reg
|
| Assign of assignment reg
|
||||||
| Loop of loop
|
| Loop of loop
|
||||||
| ProcCall of fun_call
|
| ProcCall of fun_call
|
||||||
@ -340,10 +340,10 @@ and conditional = {
|
|||||||
ifnot : instruction
|
ifnot : instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
and match_instr = {
|
and case_instr = {
|
||||||
kwd_match : kwd_match;
|
kwd_case : kwd_case;
|
||||||
expr : expr;
|
expr : expr;
|
||||||
kwd_with : kwd_with;
|
kwd_of : kwd_of;
|
||||||
lead_vbar : vbar option;
|
lead_vbar : vbar option;
|
||||||
cases : cases;
|
cases : cases;
|
||||||
kwd_end : kwd_end
|
kwd_end : kwd_end
|
||||||
@ -645,7 +645,7 @@ and record_expr_to_region = function
|
|||||||
|
|
||||||
let instr_to_region = function
|
let instr_to_region = function
|
||||||
Single Cond {region; _}
|
Single Cond {region; _}
|
||||||
| Single Match {region; _}
|
| Single Case {region; _}
|
||||||
| Single Assign {region; _}
|
| Single Assign {region; _}
|
||||||
| Single Loop While {region; _}
|
| Single Loop While {region; _}
|
||||||
| Single Loop For ForInt {region; _}
|
| Single Loop For ForInt {region; _}
|
||||||
@ -932,7 +932,7 @@ and print_instruction = function
|
|||||||
|
|
||||||
and print_single_instr = function
|
and print_single_instr = function
|
||||||
Cond {value; _} -> print_conditional value
|
Cond {value; _} -> print_conditional value
|
||||||
| Match {value; _} -> print_match_instr value
|
| Case {value; _} -> print_case_instr value
|
||||||
| Assign assign -> print_assignment assign
|
| Assign assign -> print_assignment assign
|
||||||
| Loop loop -> print_loop loop
|
| Loop loop -> print_loop loop
|
||||||
| ProcCall fun_call -> print_fun_call fun_call
|
| ProcCall fun_call -> print_fun_call fun_call
|
||||||
@ -953,12 +953,12 @@ and print_conditional node =
|
|||||||
print_token kwd_else "else";
|
print_token kwd_else "else";
|
||||||
print_instruction ifnot
|
print_instruction ifnot
|
||||||
|
|
||||||
and print_match_instr node =
|
and print_case_instr (node : case_instr) =
|
||||||
let {kwd_match; expr; kwd_with;
|
let {kwd_case; expr; kwd_of;
|
||||||
lead_vbar; cases; kwd_end} = node in
|
lead_vbar; cases; kwd_end} = node in
|
||||||
print_token kwd_match "match";
|
print_token kwd_case "case";
|
||||||
print_expr expr;
|
print_expr expr;
|
||||||
print_token kwd_with "with";
|
print_token kwd_of "of";
|
||||||
print_token_opt lead_vbar "|";
|
print_token_opt lead_vbar "|";
|
||||||
print_cases cases;
|
print_cases cases;
|
||||||
print_token kwd_end "end"
|
print_token kwd_end "end"
|
||||||
|
22
AST.mli
22
AST.mli
@ -24,6 +24,7 @@ val sepseq_to_region : ('a -> Region.t) -> ('a,'sep) sepseq -> Region.t
|
|||||||
(* Keywords of LIGO *)
|
(* Keywords of LIGO *)
|
||||||
|
|
||||||
type kwd_begin = Region.t
|
type kwd_begin = Region.t
|
||||||
|
type kwd_case = Region.t
|
||||||
type kwd_const = Region.t
|
type kwd_const = Region.t
|
||||||
type kwd_copy = Region.t
|
type kwd_copy = Region.t
|
||||||
type kwd_down = Region.t
|
type kwd_down = Region.t
|
||||||
@ -36,7 +37,6 @@ type kwd_function = Region.t
|
|||||||
type kwd_if = Region.t
|
type kwd_if = Region.t
|
||||||
type kwd_in = Region.t
|
type kwd_in = Region.t
|
||||||
type kwd_is = Region.t
|
type kwd_is = Region.t
|
||||||
type kwd_match = Region.t
|
|
||||||
type kwd_mod = Region.t
|
type kwd_mod = Region.t
|
||||||
type kwd_not = Region.t
|
type kwd_not = Region.t
|
||||||
type kwd_of = Region.t
|
type kwd_of = Region.t
|
||||||
@ -302,13 +302,13 @@ and instruction =
|
|||||||
| Block of block reg
|
| Block of block reg
|
||||||
|
|
||||||
and single_instr =
|
and single_instr =
|
||||||
Cond of conditional reg
|
Cond of conditional reg
|
||||||
| Match of match_instr reg
|
| Case of case_instr reg
|
||||||
| Assign of assignment reg
|
| Assign of assignment reg
|
||||||
| Loop of loop
|
| Loop of loop
|
||||||
| ProcCall of fun_call
|
| ProcCall of fun_call
|
||||||
| Fail of fail_instr reg
|
| Fail of fail_instr reg
|
||||||
| Skip of kwd_skip
|
| Skip of kwd_skip
|
||||||
|
|
||||||
and fail_instr = {
|
and fail_instr = {
|
||||||
kwd_fail : kwd_fail;
|
kwd_fail : kwd_fail;
|
||||||
@ -324,10 +324,10 @@ and conditional = {
|
|||||||
ifnot : instruction
|
ifnot : instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
and match_instr = {
|
and case_instr = {
|
||||||
kwd_match : kwd_match;
|
kwd_case : kwd_case;
|
||||||
expr : expr;
|
expr : expr;
|
||||||
kwd_with : kwd_with;
|
kwd_of : kwd_of;
|
||||||
lead_vbar : vbar option;
|
lead_vbar : vbar option;
|
||||||
cases : cases;
|
cases : cases;
|
||||||
kwd_end : kwd_end
|
kwd_end : kwd_end
|
||||||
|
@ -68,6 +68,7 @@ type t =
|
|||||||
(* Keywords *)
|
(* Keywords *)
|
||||||
|
|
||||||
| Begin of Region.t (* "begin" *)
|
| Begin of Region.t (* "begin" *)
|
||||||
|
| Case of Region.t (* "case" *)
|
||||||
| Const of Region.t (* "const" *)
|
| Const of Region.t (* "const" *)
|
||||||
| Copy of Region.t (* "copy" *)
|
| Copy of Region.t (* "copy" *)
|
||||||
| Down of Region.t (* "down" *)
|
| Down of Region.t (* "down" *)
|
||||||
@ -84,7 +85,6 @@ type t =
|
|||||||
| End of Region.t (* "end" *)
|
| End of Region.t (* "end" *)
|
||||||
| Then of Region.t (* "then" *)
|
| Then of Region.t (* "then" *)
|
||||||
| Else of Region.t (* "else" *)
|
| Else of Region.t (* "else" *)
|
||||||
| Match of Region.t (* "match" *)
|
|
||||||
| Procedure of Region.t (* "procedure" *)
|
| Procedure of Region.t (* "procedure" *)
|
||||||
| Record of Region.t (* "record" *)
|
| Record of Region.t (* "record" *)
|
||||||
| Skip of Region.t (* "skip" *)
|
| Skip of Region.t (* "skip" *)
|
||||||
|
10
LexToken.mll
10
LexToken.mll
@ -67,6 +67,7 @@ type t =
|
|||||||
(* Keywords *)
|
(* Keywords *)
|
||||||
|
|
||||||
| Begin of Region.t
|
| Begin of Region.t
|
||||||
|
| Case of Region.t
|
||||||
| Const of Region.t
|
| Const of Region.t
|
||||||
| Copy of Region.t
|
| Copy of Region.t
|
||||||
| Down of Region.t
|
| Down of Region.t
|
||||||
@ -83,7 +84,6 @@ type t =
|
|||||||
| End of Region.t
|
| End of Region.t
|
||||||
| Then of Region.t
|
| Then of Region.t
|
||||||
| Else of Region.t
|
| Else of Region.t
|
||||||
| Match of Region.t
|
|
||||||
| Procedure of Region.t
|
| Procedure of Region.t
|
||||||
| Record of Region.t
|
| Record of Region.t
|
||||||
| Skip of Region.t
|
| Skip of Region.t
|
||||||
@ -186,6 +186,7 @@ let proj_token = function
|
|||||||
(* Keywords *)
|
(* Keywords *)
|
||||||
|
|
||||||
| Begin region -> region, "Begin"
|
| Begin region -> region, "Begin"
|
||||||
|
| Case region -> region, "Case"
|
||||||
| Const region -> region, "Const"
|
| Const region -> region, "Const"
|
||||||
| Copy region -> region, "Copy"
|
| Copy region -> region, "Copy"
|
||||||
| Down region -> region, "Down"
|
| Down region -> region, "Down"
|
||||||
@ -202,7 +203,6 @@ let proj_token = function
|
|||||||
| End region -> region, "End"
|
| End region -> region, "End"
|
||||||
| Then region -> region, "Then"
|
| Then region -> region, "Then"
|
||||||
| Else region -> region, "Else"
|
| Else region -> region, "Else"
|
||||||
| Match region -> region, "Match"
|
|
||||||
| Procedure region -> region, "Procedure"
|
| Procedure region -> region, "Procedure"
|
||||||
| Record region -> region, "Record"
|
| Record region -> region, "Record"
|
||||||
| Skip region -> region, "Skip"
|
| Skip region -> region, "Skip"
|
||||||
@ -270,6 +270,7 @@ let to_lexeme = function
|
|||||||
(* Keywords *)
|
(* Keywords *)
|
||||||
|
|
||||||
| Begin _ -> "begin"
|
| Begin _ -> "begin"
|
||||||
|
| Case _ -> "case"
|
||||||
| Const _ -> "const"
|
| Const _ -> "const"
|
||||||
| Copy _ -> "copy"
|
| Copy _ -> "copy"
|
||||||
| Down _ -> "down"
|
| Down _ -> "down"
|
||||||
@ -286,7 +287,6 @@ let to_lexeme = function
|
|||||||
| End _ -> "end"
|
| End _ -> "end"
|
||||||
| Then _ -> "then"
|
| Then _ -> "then"
|
||||||
| Else _ -> "else"
|
| Else _ -> "else"
|
||||||
| Match _ -> "match"
|
|
||||||
| Procedure _ -> "procedure"
|
| Procedure _ -> "procedure"
|
||||||
| Record _ -> "record"
|
| Record _ -> "record"
|
||||||
| Skip _ -> "skip"
|
| Skip _ -> "skip"
|
||||||
@ -322,6 +322,7 @@ let to_region token = proj_token token |> fst
|
|||||||
|
|
||||||
let keywords = [
|
let keywords = [
|
||||||
(fun reg -> Begin reg);
|
(fun reg -> Begin reg);
|
||||||
|
(fun reg -> Case reg);
|
||||||
(fun reg -> Const reg);
|
(fun reg -> Const reg);
|
||||||
(fun reg -> Copy reg);
|
(fun reg -> Copy reg);
|
||||||
(fun reg -> Down reg);
|
(fun reg -> Down reg);
|
||||||
@ -338,7 +339,6 @@ let keywords = [
|
|||||||
(fun reg -> End reg);
|
(fun reg -> End reg);
|
||||||
(fun reg -> Then reg);
|
(fun reg -> Then reg);
|
||||||
(fun reg -> Else reg);
|
(fun reg -> Else reg);
|
||||||
(fun reg -> Match reg);
|
|
||||||
(fun reg -> Procedure reg);
|
(fun reg -> Procedure reg);
|
||||||
(fun reg -> Record reg);
|
(fun reg -> Record reg);
|
||||||
(fun reg -> Skip reg);
|
(fun reg -> Skip reg);
|
||||||
@ -546,6 +546,7 @@ let is_ident = function
|
|||||||
|
|
||||||
let is_kwd = function
|
let is_kwd = function
|
||||||
Begin _
|
Begin _
|
||||||
|
| Case _
|
||||||
| Const _
|
| Const _
|
||||||
| Copy _
|
| Copy _
|
||||||
| Down _
|
| Down _
|
||||||
@ -562,7 +563,6 @@ let is_kwd = function
|
|||||||
| End _
|
| End _
|
||||||
| Then _
|
| Then _
|
||||||
| Else _
|
| Else _
|
||||||
| Match _
|
|
||||||
| Procedure _
|
| Procedure _
|
||||||
| Record _
|
| Record _
|
||||||
| Skip _
|
| Skip _
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
(* Keywords *)
|
(* Keywords *)
|
||||||
|
|
||||||
%token <Region.t> Begin (* "begin" *)
|
%token <Region.t> Begin (* "begin" *)
|
||||||
|
%token <Region.t> Case (* "case" *)
|
||||||
%token <Region.t> Const (* "const" *)
|
%token <Region.t> Const (* "const" *)
|
||||||
%token <Region.t> Copy (* "copy" *)
|
%token <Region.t> Copy (* "copy" *)
|
||||||
%token <Region.t> Down (* "down" *)
|
%token <Region.t> Down (* "down" *)
|
||||||
@ -61,7 +62,6 @@
|
|||||||
%token <Region.t> End (* "end" *)
|
%token <Region.t> End (* "end" *)
|
||||||
%token <Region.t> Then (* "then" *)
|
%token <Region.t> Then (* "then" *)
|
||||||
%token <Region.t> Else (* "else" *)
|
%token <Region.t> Else (* "else" *)
|
||||||
%token <Region.t> Match (* "match" *)
|
|
||||||
%token <Region.t> Procedure (* "procedure" *)
|
%token <Region.t> Procedure (* "procedure" *)
|
||||||
%token <Region.t> Record (* "record" *)
|
%token <Region.t> Record (* "record" *)
|
||||||
%token <Region.t> Skip (* "skip" *)
|
%token <Region.t> Skip (* "skip" *)
|
||||||
|
10
Parser.mly
10
Parser.mly
@ -457,7 +457,7 @@ instruction:
|
|||||||
|
|
||||||
single_instr:
|
single_instr:
|
||||||
conditional { Cond $1 }
|
conditional { Cond $1 }
|
||||||
| match_instr { Match $1 }
|
| case_instr { Case $1 }
|
||||||
| assignment { Assign $1 }
|
| assignment { Assign $1 }
|
||||||
| loop { Loop $1 }
|
| loop { Loop $1 }
|
||||||
| proc_call { ProcCall $1 }
|
| proc_call { ProcCall $1 }
|
||||||
@ -486,13 +486,13 @@ conditional:
|
|||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
|
|
||||||
match_instr:
|
case_instr:
|
||||||
Match expr With option(VBAR) cases End {
|
Case expr Of option(VBAR) cases End {
|
||||||
let region = cover $1 $6 in
|
let region = cover $1 $6 in
|
||||||
let value = {
|
let value = {
|
||||||
kwd_match = $1;
|
kwd_case = $1;
|
||||||
expr = $2;
|
expr = $2;
|
||||||
kwd_with = $3;
|
kwd_of = $3;
|
||||||
lead_vbar = $4;
|
lead_vbar = $4;
|
||||||
cases = $5;
|
cases = $5;
|
||||||
kwd_end = $6}
|
kwd_end = $6}
|
||||||
|
Loading…
Reference in New Issue
Block a user