From 2ca9f718978b20e8cffb669dc61b63ad7d5e82cd Mon Sep 17 00:00:00 2001 From: csmoe Date: Tue, 11 Jun 2019 21:24:14 +0800 Subject: fix: support existential type --- crates/ra_parser/src/grammar/items.rs | 16 +++++++++++++--- crates/ra_parser/src/syntax_kind/generated.rs | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'crates/ra_parser/src') diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 7718fbe6a..e85147e9e 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -107,6 +107,10 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul p.bump_remap(T![default]); has_mods = true; } + if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] { + p.bump_remap(T![existential]); + has_mods = true; + } // items match p.current() { @@ -165,12 +169,17 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul traits::impl_block(p); m.complete(p, IMPL_BLOCK); } + // test existential_type + // existential type Foo: Fn() -> usize; + T![type] => { + type_def(p, m); + } _ => { if !has_visibility && !has_mods { return Err(m); } else { if has_mods { - p.error("expected fn, trait or impl"); + p.error("expected existential, fn, trait or impl"); } else { p.error("expected an item"); } @@ -187,7 +196,9 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { // test extern_crate // extern crate foo; T![extern] if la == T![crate] => extern_crate_item(p, m), - T![type] => type_def(p, m), + T![type] => { + type_def(p, m); + } T![mod] => mod_item(p, m), T![struct] => { // test struct_items @@ -308,7 +319,6 @@ fn type_def(p: &mut Parser, m: Marker) { // test type_item_where_clause // type Foo where Foo: Copy = (); type_params::opt_where_clause(p); - if p.eat(T![=]) { types::type_(p); } diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 2c021f3e9..036415eac 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -106,6 +106,7 @@ pub enum SyntaxKind { TRY_KW, AUTO_KW, DEFAULT_KW, + EXISTENTIAL_KW, UNION_KW, INT_NUMBER, FLOAT_NUMBER, @@ -336,6 +337,7 @@ macro_rules! T { (try) => { $crate::SyntaxKind::TRY_KW }; (auto) => { $crate::SyntaxKind::AUTO_KW }; (default) => { $crate::SyntaxKind::DEFAULT_KW }; + (existential) => { $crate::SyntaxKind::EXISTENTIAL_KW }; (union) => { $crate::SyntaxKind::UNION_KW }; } @@ -394,6 +396,7 @@ impl SyntaxKind { | TRY_KW | AUTO_KW | DEFAULT_KW + | EXISTENTIAL_KW | UNION_KW => true, _ => false @@ -566,6 +569,7 @@ impl SyntaxKind { TRY_KW => &SyntaxInfo { name: "TRY_KW" }, AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, + EXISTENTIAL_KW => &SyntaxInfo { name: "EXISTENTIAL_KW" }, UNION_KW => &SyntaxInfo { name: "UNION_KW" }, INT_NUMBER => &SyntaxInfo { name: "INT_NUMBER" }, FLOAT_NUMBER => &SyntaxInfo { name: "FLOAT_NUMBER" }, -- cgit v1.2.3