From 6502bd2c966d57bdb8fbba7f43da9ddd004d87d3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 5 Nov 2018 11:39:35 +0300 Subject: reduce code duplication --- crates/ra_syntax/src/grammar/type_params.rs | 27 ++++++++------------------- crates/ra_syntax/src/grammar/types.rs | 13 +++++++++++-- 2 files changed, 19 insertions(+), 21 deletions(-) (limited to 'crates/ra_syntax/src/grammar') diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/grammar/type_params.rs index 735c728e5..68eca0ce8 100644 --- a/crates/ra_syntax/src/grammar/type_params.rs +++ b/crates/ra_syntax/src/grammar/type_params.rs @@ -126,26 +126,15 @@ fn where_predicate(p: &mut Parser) { p.error("expected colon"); } } - // test where_pred_for - // fn test() - // where - // for<'a> F: Fn(&'a str) - // { } - FOR_KW => { - p.bump(); - if p.at(L_ANGLE) { - type_param_list(p); - types::path_type(p); - if p.at(COLON) { - bounds(p); - } else { - p.error("expected colon"); - } - } else { - p.error("expected `<`"); - } - } _ => { + // test where_pred_for + // fn test() + // where + // for<'a> F: Fn(&'a str) + // { } + if p.at(FOR_KW) { + types::for_binder(p); + } types::path_type(p); if p.at(COLON) { bounds(p); diff --git a/crates/ra_syntax/src/grammar/types.rs b/crates/ra_syntax/src/grammar/types.rs index f308aef89..ed2718e73 100644 --- a/crates/ra_syntax/src/grammar/types.rs +++ b/crates/ra_syntax/src/grammar/types.rs @@ -188,13 +188,22 @@ fn fn_pointer_type(p: &mut Parser) { m.complete(p, FN_POINTER_TYPE); } +pub(super) fn for_binder(p: &mut Parser) { + assert!(p.at(FOR_KW)); + p.bump(); + if p.at(L_ANGLE) { + type_params::opt_type_param_list(p); + } else { + p.error("expected `<`"); + } +} + // test for_type // type A = for<'a> fn() -> (); pub(super) fn for_type(p: &mut Parser) { assert!(p.at(FOR_KW)); let m = p.start(); - p.bump(); - type_params::opt_type_param_list(p); + for_binder(p); match p.current() { FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), _ if paths::is_path_start(p) => path_type_(p, false), -- cgit v1.2.3