From 5222b8aba3b1c2c68706aacf6869423a8e4fe6d5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Feb 2019 15:47:32 +0300 Subject: move all parsing related bits to a separate module --- crates/ra_syntax/src/parsing/grammar/type_args.rs | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 crates/ra_syntax/src/parsing/grammar/type_args.rs (limited to 'crates/ra_syntax/src/parsing/grammar/type_args.rs') diff --git a/crates/ra_syntax/src/parsing/grammar/type_args.rs b/crates/ra_syntax/src/parsing/grammar/type_args.rs new file mode 100644 index 000000000..f889419c5 --- /dev/null +++ b/crates/ra_syntax/src/parsing/grammar/type_args.rs @@ -0,0 +1,48 @@ +use super::*; + +pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) { + let m; + match (colon_colon_required, p.nth(0), p.nth(1)) { + (_, COLONCOLON, L_ANGLE) => { + m = p.start(); + p.bump(); + p.bump(); + } + (false, L_ANGLE, _) => { + m = p.start(); + p.bump(); + } + _ => return, + }; + + while !p.at(EOF) && !p.at(R_ANGLE) { + type_arg(p); + if !p.at(R_ANGLE) && !p.expect(COMMA) { + break; + } + } + p.expect(R_ANGLE); + m.complete(p, TYPE_ARG_LIST); +} + +// test type_arg +// type A = B<'static, i32, Item=u64>; +fn type_arg(p: &mut Parser) { + let m = p.start(); + match p.current() { + LIFETIME => { + p.bump(); + m.complete(p, LIFETIME_ARG); + } + IDENT if p.nth(1) == EQ => { + name_ref(p); + p.bump(); + types::type_(p); + m.complete(p, ASSOC_TYPE_ARG); + } + _ => { + types::type_(p); + m.complete(p, TYPE_ARG); + } + } +} -- cgit v1.2.3