From a688a1afe470458a12cbaccc09a5e22666316b99 Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Mon, 8 Jun 2020 15:24:36 +0200 Subject: [PATCH] ReasonLIGO improvements. --- src/passes/01-parser/reasonligo/Pretty.ml | 22 +++++++++---------- .../contracts/expected/amount.religo.expected | 2 +- .../condition-shadowing.religo.expected | 2 +- .../expected/condition.religo.expected | 2 +- .../expected/eq_bool.religo.expected | 2 +- .../expected/failwith.religo.expected | 2 +- .../contracts/expected/loop.religo.expected | 6 ++--- .../expected/multisig.religo.expected | 10 ++++----- .../expected/no_semicolon.religo.expected | 2 +- .../contracts/expected/pledge.religo.expected | 4 ++-- .../expected/recursion.religo.expected | 4 ++-- ...tuples_sequences_functions.religo.expected | 2 +- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/passes/01-parser/reasonligo/Pretty.ml b/src/passes/01-parser/reasonligo/Pretty.ml index e925388e1..f1e1c834a 100644 --- a/src/passes/01-parser/reasonligo/Pretty.ml +++ b/src/passes/01-parser/reasonligo/Pretty.ml @@ -120,8 +120,8 @@ and pp_ptuple {value; _} = | p::items -> group (break 1 ^^ pp_pattern p ^^ string ",") ^^ app items in if tail = [] - then string "(" ^^ pp_pattern head ^^ string ")" - else string "(" ^^ pp_pattern head ^^ string "," ^^ app (List.map snd tail) ^^ string ")" + then string "(" ^^ nest 1 (pp_pattern head) ^^ string ")" + else string "(" ^^ nest 1 (pp_pattern head ^^ string "," ^^ app (List.map snd tail)) ^^ string ")" and pp_precord fields = pp_ne_injection pp_field_pattern fields @@ -162,7 +162,7 @@ and pp_expr = function and pp_case_expr {value; _} = let {expr; cases; _} = value in - group (string "switch" ^^ string "(" ^^ pp_expr expr ^^ (string ") " ^^ string "{") + group (string "switch" ^^ string "(" ^^ nest 1 (pp_expr expr) ^^ (string ") " ^^ string "{") ^^ (pp_cases cases) ^^ hardline ^^ string "}" ) and pp_cases {value; _} = @@ -178,7 +178,7 @@ and pp_clause {value; _} = and pp_cond_expr {value; _} = let {test; ifso; kwd_else; ifnot; _} = value in let if_then = - string "if" ^^ string "(" ^^ pp_expr test ^^ string ")" ^^ string " {" ^^ break 0 + string "if" ^^ string " (" ^^ pp_expr test ^^ string ")" ^^ string " {" ^^ break 0 ^^ group (nest 2 (break 2 ^^ pp_expr ifso)) ^^ hardline ^^ string "}" in if kwd_else#is_ghost then if_then @@ -350,8 +350,8 @@ and pp_tuple_expr {value; _} = | e::items -> group (break 1 ^^ pp_expr e ^^ string ",") ^^ app items in if tail = [] - then string "(" ^^ pp_expr head ^^ string ")" - else string "(" ^^ pp_expr head ^^ string "," ^^ app (List.map snd tail) ^^ string ")" + then string "(" ^^ nest 1 (pp_expr head) ^^ string ")" + else string "(" ^^ nest 1 (pp_expr head ^^ string "," ^^ app (List.map snd tail)) ^^ string ")" and pp_par_expr {value; _} = string "(" ^^ nest 1 (pp_expr value.inside ^^ string ")") @@ -378,8 +378,8 @@ and pp_fun {value; _} = group (break 0 ^^ string ": " ^^ nest 2 (pp_type_expr e)) in match body with - | ESeq _ -> string "(" ^^ binders ^^ string ")" ^^ annot ^^ string " => " ^^ pp_expr body - | _ -> (prefix 2 0 (string "(" ^^ binders ^^ string ")" ^^ annot + | ESeq _ -> string "(" ^^ nest 1 binders ^^ string ")" ^^ annot ^^ string " => " ^^ pp_expr body + | _ -> (prefix 2 0 (string "(" ^^ nest 1 binders ^^ string ")" ^^ annot ^^ string " => ") (pp_expr body)) and pp_seq {value; _} = @@ -412,7 +412,7 @@ and pp_cartesian {value; _} = | e::items -> group (break 1 ^^ pp_type_expr e ^^ string ",") ^^ app items in - string "(" ^^ pp_type_expr head ^^ (if tail <> [] then string "," else empty) ^^ app (List.map snd tail) ^^ string ")" + string "(" ^^ nest 1 (pp_type_expr head ^^ (if tail <> [] then string "," else empty) ^^ app (List.map snd tail)) ^^ string ")" and pp_variants {value; _} = let head, tail = value in @@ -445,7 +445,7 @@ and pp_field_decl {value; _} = and pp_type_app {value; _} = let ctor, tuple = value in - prefix 2 0 (pp_type_constr ctor) (string "(" ^^ pp_type_tuple tuple ^^ string ")") + prefix 2 0 (pp_type_constr ctor) (string "(" ^^ nest 1 (pp_type_tuple tuple) ^^ string ")") and pp_type_tuple {value; _} = let head, tail = value.inside in @@ -474,7 +474,7 @@ and pp_fun_type {value; _} = match lhs, rhs with | _, TFun tf -> string "(" ^^ pp_type_expr lhs ^^ string ", " ^^ pp_fun_args tf | TVar _ , _ -> group (pp_type_expr lhs ^^ string " =>" ^/^ pp_type_expr rhs) - | _ -> group (string "(" ^^ pp_type_expr lhs ^^ string ")" ^^ string " =>" ^/^ pp_type_expr rhs) + | _ -> group (string "(" ^^ nest 1 (pp_type_expr lhs) ^^ string ")" ^^ string " =>" ^/^ pp_type_expr rhs) and pp_type_par {value; _} = string "(" ^^ nest 1 (pp_type_expr value.inside ^^ string ")") diff --git a/src/test/contracts/expected/amount.religo.expected b/src/test/contracts/expected/amount.religo.expected index 7f4dac3d6..f1082701d 100644 --- a/src/test/contracts/expected/amount.religo.expected +++ b/src/test/contracts/expected/amount.religo.expected @@ -1,5 +1,5 @@ let check_ = (p: unit): int => - if(Tezos.amount == 100000000mutez) { + if (Tezos.amount == 100000000mutez) { 42 } else { 0 diff --git a/src/test/contracts/expected/condition-shadowing.religo.expected b/src/test/contracts/expected/condition-shadowing.religo.expected index d77219f4b..9f66ae5f2 100644 --- a/src/test/contracts/expected/condition-shadowing.religo.expected +++ b/src/test/contracts/expected/condition-shadowing.religo.expected @@ -1,6 +1,6 @@ let main = (i: int) => { let result = 0; - if(i == 2) { + if (i == 2) { let result = 42; result diff --git a/src/test/contracts/expected/condition.religo.expected b/src/test/contracts/expected/condition.religo.expected index 8049192f8..9e4ec2c65 100644 --- a/src/test/contracts/expected/condition.religo.expected +++ b/src/test/contracts/expected/condition.religo.expected @@ -1,5 +1,5 @@ let main = (i: int) => - if(i == 2) { + if (i == 2) { 42 } else { 0 diff --git a/src/test/contracts/expected/eq_bool.religo.expected b/src/test/contracts/expected/eq_bool.religo.expected index 73671f764..35ac77780 100644 --- a/src/test/contracts/expected/eq_bool.religo.expected +++ b/src/test/contracts/expected/eq_bool.religo.expected @@ -1,5 +1,5 @@ let main = ((a, b): (bool, bool)) => - if(a == b) { + if (a == b) { 999 } else { 1 diff --git a/src/test/contracts/expected/failwith.religo.expected b/src/test/contracts/expected/failwith.religo.expected index 8f29675a1..1c0ca2203 100644 --- a/src/test/contracts/expected/failwith.religo.expected +++ b/src/test/contracts/expected/failwith.religo.expected @@ -1,6 +1,6 @@ type storage = unit; let main = (p: unit, storage) => - if(true) { + if (true) { failwith("This contract always fails") }; diff --git a/src/test/contracts/expected/loop.religo.expected b/src/test/contracts/expected/loop.religo.expected index 130c2cd06..18fa276e6 100644 --- a/src/test/contracts/expected/loop.religo.expected +++ b/src/test/contracts/expected/loop.religo.expected @@ -1,5 +1,5 @@ let rec aux_simple = (i: int): int => - if(i < 100) { + if (i < 100) { aux_simple(i + 1) } else { i @@ -15,7 +15,7 @@ let counter = (n: int): int => { sum: 0 }; let rec aggregate = (prev: sum_aggregator): int => - if(prev.counter <= n) { + if (prev.counter <= n) { aggregate({ @@ -29,7 +29,7 @@ let counter = (n: int): int => { }; let rec aux_nest = (prev: sum_aggregator): sum_aggregator => - if(prev.counter < 100) { + if (prev.counter < 100) { let sum: int = prev.sum + aux_simple(prev.counter); aux_nest({counter: prev.counter + 1, sum: sum }) diff --git a/src/test/contracts/expected/multisig.religo.expected b/src/test/contracts/expected/multisig.religo.expected index ddb7b981c..0161e9fe2 100644 --- a/src/test/contracts/expected/multisig.religo.expected +++ b/src/test/contracts/expected/multisig.religo.expected @@ -33,7 +33,7 @@ let check_message = ((param, s): (check_message_pt, storage)) : return => { let message: message = param.message; let s = - if(param.counter != s.counter) { + if (param.counter != s.counter) { (failwith("Counters does not match") : storage) } else { @@ -42,15 +42,15 @@ let check_message = ((param, s): (check_message_pt, storage)) let valid: nat = 0n; let keys: authorized_keys = s.auth; let aux = ((vk, pkh_sig): ((nat, authorized_keys), - (key_hash, signature))): (nat, authorized_keys) => { + (key_hash, signature))): (nat, authorized_keys) => { let (valid, keys) = vk; switch(keys) { | [] => vk | [key, ...keys] => - if(pkh_sig[0] == Crypto.hash_key(key)) { + if (pkh_sig[0] == Crypto.hash_key(key)) { let valid = - if( + if ( Crypto.check(key, pkh_sig[1], packed_payload)) { valid + 1n } else { @@ -64,7 +64,7 @@ let check_message = ((param, s): (check_message_pt, storage)) }; let (valid, keys) = List.fold(aux, param.signatures, (valid, keys)); - if(valid < s.threshold) { + if (valid < s.threshold) { (failwith("Not enough signatures passed the check") : storage) diff --git a/src/test/contracts/expected/no_semicolon.religo.expected b/src/test/contracts/expected/no_semicolon.religo.expected index ea3b13c2c..01c4b5a96 100644 --- a/src/test/contracts/expected/no_semicolon.religo.expected +++ b/src/test/contracts/expected/no_semicolon.religo.expected @@ -1,7 +1,7 @@ type f = int; let a = (b: f) => { - if(b == 2) { + if (b == 2) { 3 } else { 4 diff --git a/src/test/contracts/expected/pledge.religo.expected b/src/test/contracts/expected/pledge.religo.expected index 9c8044a9c..8df47dc01 100644 --- a/src/test/contracts/expected/pledge.religo.expected +++ b/src/test/contracts/expected/pledge.religo.expected @@ -10,8 +10,8 @@ let donate = ((p, s): (unit, storage)) }; let distribute = ((p, s): ((unit => list(operation)), - storage)): (list(operation), storage) => { - if(Tezos.sender == s) { + storage)): (list(operation), storage) => { + if (Tezos.sender == s) { (p(()), s) } else { diff --git a/src/test/contracts/expected/recursion.religo.expected b/src/test/contracts/expected/recursion.religo.expected index 70cf03318..9c598e4a3 100644 --- a/src/test/contracts/expected/recursion.religo.expected +++ b/src/test/contracts/expected/recursion.religo.expected @@ -1,12 +1,12 @@ let rec sum = ((n, acc): (int, int)): int => - if(n < 1) { + if (n < 1) { acc } else { sum((n - 1, acc + n)) }; let rec fibo = ((n, n_1, n_0): (int, int, int)): int => - if(n < 2) { + if (n < 2) { n_1 } else { fibo((n - 1, n_1 + n_0, n_1)) diff --git a/src/test/contracts/expected/tuples_sequences_functions.religo.expected b/src/test/contracts/expected/tuples_sequences_functions.religo.expected index ee569df68..e4277334e 100644 --- a/src/test/contracts/expected/tuples_sequences_functions.religo.expected +++ b/src/test/contracts/expected/tuples_sequences_functions.religo.expected @@ -54,7 +54,7 @@ let s = { let t = (((((((2))))))); let u = - if(true) { + if (true) { 1 } else { 2