From 8f21afacfc981e93f2ad78cd340e9b6c0e821d92 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 8 Aug 2018 18:34:26 +0300 Subject: Optional patterns in fn types --- src/grammar/params.rs | 32 +++++++++++++++++++++++--------- src/grammar/paths.rs | 2 +- src/grammar/types.rs | 2 +- 3 files changed, 25 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/grammar/params.rs b/src/grammar/params.rs index c7f17168b..32e905cb2 100644 --- a/src/grammar/params.rs +++ b/src/grammar/params.rs @@ -33,12 +33,6 @@ impl Flavor { _ => true, } } - fn pattern_required(self) -> bool { - match self { - Flavor::OptionalPattern => false, - _ => true, - } - } } fn list_(p: &mut Parser, flavor: Flavor) { @@ -65,9 +59,29 @@ fn list_(p: &mut Parser, flavor: Flavor) { fn value_parameter(p: &mut Parser, flavor: Flavor) { let m = p.start(); - patterns::pattern(p); - if p.at(COLON) || flavor.type_required() { - types::ascription(p) + match flavor { + Flavor::OptionalType | Flavor::Normal => { + patterns::pattern(p); + if p.at(COLON) || flavor.type_required() { + types::ascription(p) + } + }, + // test value_parameters_no_patterns + // type F = Box; + Flavor::OptionalPattern => { + let la0 = p.current(); + let la1 = p.nth(1); + let la2 = p.nth(2); + let la3 = p.nth(3); + if la0 == IDENT && la1 == COLON + || la0 == AMP && la1 == IDENT && la2 == COLON + || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON { + patterns::pattern(p); + types::ascription(p); + } else { + types::type_(p); + } + }, } m.complete(p, PARAM); } diff --git a/src/grammar/paths.rs b/src/grammar/paths.rs index 6d406645f..c277e2a6b 100644 --- a/src/grammar/paths.rs +++ b/src/grammar/paths.rs @@ -75,7 +75,7 @@ fn path_generic_args(p: &mut Parser, mode: Mode) { // test path_fn_trait_args // type F = Box ()>; if p.at(L_PAREN) { - params::param_list(p); + params::param_list_opt_patterns(p); fn_ret_type(p); } else { type_args::type_arg_list(p, false) diff --git a/src/grammar/types.rs b/src/grammar/types.rs index 03a087acd..c8ced3d28 100644 --- a/src/grammar/types.rs +++ b/src/grammar/types.rs @@ -166,7 +166,7 @@ fn fn_pointer_type(p: &mut Parser) { return; } - params::param_list(p); + params::param_list_opt_patterns(p); // test fn_pointer_type_with_ret // type F = fn() -> (); fn_ret_type(p); -- cgit v1.2.3