From d994592a1b591ad465af7dfb2a46cb3e93c25bb3 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Tue, 19 Mar 2019 11:46:30 +0100 Subject: [PATCH] Changed "match ... with ..." to "case ... of ..." --- AST.ml | 22 +++++++++++----------- AST.mli | 22 +++++++++++----------- LexToken.mli | 2 +- LexToken.mll | 10 +++++----- ParToken.mly | 2 +- Parser.mly | 10 +++++----- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/AST.ml b/AST.ml index b8a3172b6..74fed1d19 100644 --- a/AST.ml +++ b/AST.ml @@ -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" diff --git a/AST.mli b/AST.mli index 5cd0e9587..6bf269599 100644 --- a/AST.mli +++ b/AST.mli @@ -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 diff --git a/LexToken.mli b/LexToken.mli index f72c0e41e..a868bf0c9 100644 --- a/LexToken.mli +++ b/LexToken.mli @@ -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" *) diff --git a/LexToken.mll b/LexToken.mll index 741426209..1c433ed83 100644 --- a/LexToken.mll +++ b/LexToken.mll @@ -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 _ diff --git a/ParToken.mly b/ParToken.mly index 2611aae22..86bfdc388 100644 --- a/ParToken.mly +++ b/ParToken.mly @@ -45,6 +45,7 @@ (* Keywords *) %token Begin (* "begin" *) +%token Case (* "case" *) %token Const (* "const" *) %token Copy (* "copy" *) %token Down (* "down" *) @@ -61,7 +62,6 @@ %token End (* "end" *) %token Then (* "then" *) %token Else (* "else" *) -%token Match (* "match" *) %token Procedure (* "procedure" *) %token Record (* "record" *) %token Skip (* "skip" *) diff --git a/Parser.mly b/Parser.mly index dd847ab72..62404c87a 100644 --- a/Parser.mly +++ b/Parser.mly @@ -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}