Merge branch 'wild-args-reasonligo' into 'dev'
ReasonLIGO: Add support for _ as an argument See merge request ligolang/ligo!527
This commit is contained in:
commit
cbf2c7680e
@ -68,6 +68,18 @@ module Errors =
|
|||||||
("location",
|
("location",
|
||||||
fun () -> Format.asprintf "%a" Location.pp_lift @@ expression_loc)]
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ expression_loc)]
|
||||||
in error ~data title message
|
in error ~data title message
|
||||||
|
|
||||||
|
let invalid_wild (expr: AST.expr) =
|
||||||
|
let title () = "" in
|
||||||
|
let message () =
|
||||||
|
"It looks like you are using a wild pattern where it cannot be used."
|
||||||
|
in
|
||||||
|
let expression_loc = AST.expr_to_region expr in
|
||||||
|
let data = [
|
||||||
|
("location",
|
||||||
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ expression_loc)]
|
||||||
|
in error ~data title message
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let parse (module IO : IO) parser =
|
let parse (module IO : IO) parser =
|
||||||
@ -127,6 +139,8 @@ let parse (module IO : IO) parser =
|
|||||||
|
|
||||||
| exception SyntaxError.Error (SyntaxError.WrongFunctionArguments expr) ->
|
| exception SyntaxError.Error (SyntaxError.WrongFunctionArguments expr) ->
|
||||||
Trace.fail @@ Errors.wrong_function_arguments expr
|
Trace.fail @@ Errors.wrong_function_arguments expr
|
||||||
|
| exception SyntaxError.Error (SyntaxError.InvalidWild expr) ->
|
||||||
|
Trace.fail @@ Errors.wrong_function_arguments expr
|
||||||
|
|
||||||
let parse_file (source: string) =
|
let parse_file (source: string) =
|
||||||
let module IO =
|
let module IO =
|
||||||
|
@ -40,6 +40,13 @@ let rec curry hd = function
|
|||||||
in TFun {value; region}
|
in TFun {value; region}
|
||||||
| [] -> hd
|
| [] -> hd
|
||||||
|
|
||||||
|
let wild_error e =
|
||||||
|
match e with
|
||||||
|
| EVar { value = "_"; _} as e ->
|
||||||
|
let open! SyntaxError in
|
||||||
|
raise (Error (InvalidWild e))
|
||||||
|
| _ -> ()
|
||||||
|
|
||||||
(* END HEADER *)
|
(* END HEADER *)
|
||||||
%}
|
%}
|
||||||
|
|
||||||
@ -262,24 +269,30 @@ let_declaration:
|
|||||||
|
|
||||||
let_binding:
|
let_binding:
|
||||||
"<ident>" type_annotation? "=" expr {
|
"<ident>" type_annotation? "=" expr {
|
||||||
|
wild_error $4;
|
||||||
Scoping.check_reserved_name $1;
|
Scoping.check_reserved_name $1;
|
||||||
{binders = PVar $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
{binders = PVar $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
||||||
}
|
}
|
||||||
| "_" type_annotation? "=" expr {
|
| "_" type_annotation? "=" expr {
|
||||||
|
wild_error $4;
|
||||||
{binders = PWild $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
{binders = PWild $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
||||||
}
|
}
|
||||||
| unit type_annotation? "=" expr {
|
| unit type_annotation? "=" expr {
|
||||||
|
wild_error $4;
|
||||||
{binders = PUnit $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
{binders = PUnit $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
||||||
}
|
}
|
||||||
| record_pattern type_annotation? "=" expr {
|
| record_pattern type_annotation? "=" expr {
|
||||||
|
wild_error $4;
|
||||||
Scoping.check_pattern (PRecord $1);
|
Scoping.check_pattern (PRecord $1);
|
||||||
{binders = PRecord $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
{binders = PRecord $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
||||||
}
|
}
|
||||||
| par(closed_irrefutable) type_annotation? "=" expr {
|
| par(closed_irrefutable) type_annotation? "=" expr {
|
||||||
|
wild_error $4;
|
||||||
Scoping.check_pattern $1.value.inside;
|
Scoping.check_pattern $1.value.inside;
|
||||||
{binders = PPar $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
{binders = PPar $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
||||||
}
|
}
|
||||||
| tuple(sub_irrefutable) type_annotation? "=" expr {
|
| tuple(sub_irrefutable) type_annotation? "=" expr {
|
||||||
|
wild_error $4;
|
||||||
Utils.nsepseq_iter Scoping.check_pattern $1;
|
Utils.nsepseq_iter Scoping.check_pattern $1;
|
||||||
let hd, tl = $1 in
|
let hd, tl = $1 in
|
||||||
let start = pattern_to_region hd in
|
let start = pattern_to_region hd in
|
||||||
@ -408,7 +421,9 @@ expr:
|
|||||||
base_cond__open(expr) | switch_expr(base_cond) { $1 }
|
base_cond__open(expr) | switch_expr(base_cond) { $1 }
|
||||||
|
|
||||||
base_cond__open(x):
|
base_cond__open(x):
|
||||||
base_expr(x) | conditional(expr_with_let_expr) { $1 }
|
base_expr(x) | conditional(expr_with_let_expr) {
|
||||||
|
wild_error $1;
|
||||||
|
$1 }
|
||||||
|
|
||||||
base_cond:
|
base_cond:
|
||||||
base_cond__open(base_cond) { $1 }
|
base_cond__open(base_cond) { $1 }
|
||||||
@ -445,8 +460,12 @@ fun_expr:
|
|||||||
|
|
||||||
let rec arg_to_pattern = function
|
let rec arg_to_pattern = function
|
||||||
EVar v ->
|
EVar v ->
|
||||||
|
if v.value = "_" then
|
||||||
|
PWild v.region
|
||||||
|
else (
|
||||||
Scoping.check_reserved_name v;
|
Scoping.check_reserved_name v;
|
||||||
PVar v
|
PVar v
|
||||||
|
)
|
||||||
| EAnnot {region; value = {inside = EVar v, colon, typ; _}} ->
|
| EAnnot {region; value = {inside = EVar v, colon, typ; _}} ->
|
||||||
Scoping.check_reserved_name v;
|
Scoping.check_reserved_name v;
|
||||||
let value = {pattern = PVar v; colon; type_expr = typ}
|
let value = {pattern = PVar v; colon; type_expr = typ}
|
||||||
@ -779,6 +798,7 @@ common_expr:
|
|||||||
| "<bytes>" { EBytes $1 }
|
| "<bytes>" { EBytes $1 }
|
||||||
| "<ident>" | module_field { EVar $1 }
|
| "<ident>" | module_field { EVar $1 }
|
||||||
| projection { EProj $1 }
|
| projection { EProj $1 }
|
||||||
|
| "_" { EVar {value = "_"; region = $1} }
|
||||||
| update_record { EUpdate $1 }
|
| update_record { EUpdate $1 }
|
||||||
| "<string>" { EString (String $1) }
|
| "<string>" { EString (String $1) }
|
||||||
| unit { EUnit $1 }
|
| unit { EUnit $1 }
|
||||||
|
@ -48,7 +48,12 @@ let parse parser : ('a, string Region.reg) Stdlib.result =
|
|||||||
in Stdlib.Error Region.{value=error; region}
|
in Stdlib.Error Region.{value=error; region}
|
||||||
|
|
||||||
(* Scoping errors *)
|
(* Scoping errors *)
|
||||||
|
| SyntaxError.Error (SyntaxError.InvalidWild expr) ->
|
||||||
|
let msg = "It looks like you are using a wild pattern where it cannot be used.\n"
|
||||||
|
and region = AST.expr_to_region expr in
|
||||||
|
let error = Unit.short_error ~offsets:IO.options#offsets
|
||||||
|
IO.options#mode msg region
|
||||||
|
in Stdlib.Error Region.{value=error; region}
|
||||||
| Scoping.Error (Scoping.Reserved_name name) ->
|
| Scoping.Error (Scoping.Reserved_name name) ->
|
||||||
let token =
|
let token =
|
||||||
Lexer.Token.mk_ident name.Region.value name.Region.region in
|
Lexer.Token.mk_ident name.Region.value name.Region.region in
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
type error =
|
type error =
|
||||||
| WrongFunctionArguments of AST.expr
|
| WrongFunctionArguments of AST.expr
|
||||||
|
| InvalidWild of AST.expr
|
||||||
|
|
||||||
exception Error of error
|
exception Error of error
|
@ -1,4 +1,5 @@
|
|||||||
type error =
|
type error =
|
||||||
| WrongFunctionArguments of AST.expr
|
| WrongFunctionArguments of AST.expr
|
||||||
|
| InvalidWild of AST.expr
|
||||||
|
|
||||||
exception Error of error
|
exception Error of error
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,6 @@ type storage = big_map (int, bar);
|
|||||||
|
|
||||||
type return = (list (operation), storage);
|
type return = (list (operation), storage);
|
||||||
|
|
||||||
let main = ((ignore, store): (unit, storage)): return => {
|
let main = ((_, store): (unit, storage)): return => {
|
||||||
([]: list(operation), store)
|
([]: list(operation), store)
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@ type storage = big_map (nat, big_map (int, string));
|
|||||||
|
|
||||||
type return = (list (operation), storage);
|
type return = (list (operation), storage);
|
||||||
|
|
||||||
let main = ((ignore, store): (unit, storage)): return => {
|
let main = ((_, store): (unit, storage)): return => {
|
||||||
([]: list(operation), store)
|
([]: list(operation), store)
|
||||||
};
|
};
|
||||||
|
|
@ -10,6 +10,6 @@ type storage = big_map(nat, foo);
|
|||||||
|
|
||||||
type return = (list (operation), storage);
|
type return = (list (operation), storage);
|
||||||
|
|
||||||
let main = ((ignore, store): (unit, storage)): return => {
|
let main = ((_, store): (unit, storage)): return => {
|
||||||
([]: list(operation), store)
|
([]: list(operation), store)
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@ type storage = map (int, big_map (nat, big_map (int, string)));
|
|||||||
|
|
||||||
type return = (list (operation), storage);
|
type return = (list (operation), storage);
|
||||||
|
|
||||||
let main = ((ignore, store): (unit, storage)): return => {
|
let main = ((_, store): (unit, storage)): return => {
|
||||||
([]: list(operation), store)
|
([]: list(operation), store)
|
||||||
};
|
};
|
||||||
|
|
@ -15,7 +15,7 @@ let arguments = (b: int, c: int) => { b + c; };
|
|||||||
|
|
||||||
let arguments_type_def = (b: fun_type) => b (5, 3);
|
let arguments_type_def = (b: fun_type) => b (5, 3);
|
||||||
|
|
||||||
let arguments_test = (ignore: int) => arguments_type_def (arguments);
|
let arguments_test = (_: int) => arguments_type_def (arguments);
|
||||||
|
|
||||||
type tuple_type = ((int, int)) => int;
|
type tuple_type = ((int, int)) => int;
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ let tuple = ((a, b): (int, int)) => { a + b; };
|
|||||||
|
|
||||||
let tuple_type_def = (b: tuple_type) => b ((5, 3));
|
let tuple_type_def = (b: tuple_type) => b ((5, 3));
|
||||||
|
|
||||||
let tuple_test = (ignore: int) => tuple_type_def (tuple);
|
let tuple_test = (_: int) => tuple_type_def (tuple);
|
||||||
|
|
||||||
|
|
||||||
/* inline */
|
/* inline */
|
||||||
@ -32,12 +32,12 @@ let arguments_inline = (b: int, c: int) => { b + c; };
|
|||||||
|
|
||||||
let arguments_type_def_inline = (b: (int, int) => int) => b (5, 3);
|
let arguments_type_def_inline = (b: (int, int) => int) => b (5, 3);
|
||||||
|
|
||||||
let arguments_test_inline = (ignore: int) =>
|
let arguments_test_inline = (_: int) =>
|
||||||
arguments_type_def_inline (arguments_inline);
|
arguments_type_def_inline (arguments_inline);
|
||||||
|
|
||||||
let tuple_inline = ((a, b): (int, int)) => { a + b; };
|
let tuple_inline = ((a, b): (int, int)) => { a + b; };
|
||||||
|
|
||||||
let tuple_type_def_inline = (b: ((int, int)) => int) => b ((5, 3));
|
let tuple_type_def_inline = (b: ((int, int)) => int) => b ((5, 3));
|
||||||
|
|
||||||
let tuple_test_inline = (ignore: int) =>
|
let tuple_test_inline = (_: int) =>
|
||||||
tuple_type_def_inline(tuple_inline);
|
tuple_type_def_inline(tuple_inline);
|
||||||
|
Loading…
Reference in New Issue
Block a user