From be7260485e31eb24a9fa7bb3d6b587ab59bd6846 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 23 Dec 2020 01:26:31 +0100 Subject: Update ungrammar for const block patterns --- Cargo.lock | 4 +--- Cargo.toml | 2 +- crates/hir_def/src/body/lower.rs | 4 +++- crates/parser/src/syntax_kind/generated.rs | 1 + crates/syntax/src/ast/generated/nodes.rs | 33 +++++++++++++++++++++++++++++- xtask/Cargo.toml | 2 +- xtask/src/ast_src.rs | 1 + 7 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fbb79e01f..47381c08e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1827,9 +1827,7 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] name = "ungrammar" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68951379f3ced25754472ca5addbf74d7dab58c9818f49290a3d8caa3ab44fb7" +version = "1.5.0" [[package]] name = "unicase" diff --git a/Cargo.toml b/Cargo.toml index 59d36fbc1..fdf2a71a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,4 +26,4 @@ debug = 0 # Set this to 1 or 2 to get more useful backtraces in debugger. # chalk-ir = { path = "../chalk/chalk-ir" } # chalk-recursive = { path = "../chalk/chalk-recursive" } -# ungrammar = { path = "../ungrammar" } +ungrammar = { path = "../ungrammar" } diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 0f404be1b..978c3a324 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -933,7 +933,9 @@ impl ExprCollector<'_> { Pat::Box { inner } } // FIXME: implement - ast::Pat::RangePat(_) | ast::Pat::MacroPat(_) => Pat::Missing, + ast::Pat::RangePat(_) | ast::Pat::MacroPat(_) | ast::Pat::ConstBlockPat(_) => { + Pat::Missing + } }; let ptr = AstPtr::new(&pat); self.alloc_pat(pattern, Either::Left(ptr)) diff --git a/crates/parser/src/syntax_kind/generated.rs b/crates/parser/src/syntax_kind/generated.rs index 980aa5979..f69e71bdb 100644 --- a/crates/parser/src/syntax_kind/generated.rs +++ b/crates/parser/src/syntax_kind/generated.rs @@ -170,6 +170,7 @@ pub enum SyntaxKind { RANGE_PAT, LITERAL_PAT, MACRO_PAT, + CONST_BLOCK_PAT, TUPLE_EXPR, ARRAY_EXPR, PAREN_EXPR, diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 1588ba93e..c5b80bffe 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs @@ -763,6 +763,7 @@ impl EffectExpr { pub fn try_token(&self) -> Option { support::token(&self.syntax, T![try]) } pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } pub fn async_token(&self) -> Option { support::token(&self.syntax, T![async]) } + pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } pub fn block_expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1251,6 +1252,14 @@ impl TupleStructPat { pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ConstBlockPat { + pub(crate) syntax: SyntaxNode, +} +impl ConstBlockPat { + pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } + pub fn block_expr(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordPatFieldList { pub(crate) syntax: SyntaxNode, } @@ -1369,6 +1378,7 @@ pub enum Pat { SlicePat(SlicePat), TuplePat(TuplePat), TupleStructPat(TupleStructPat), + ConstBlockPat(ConstBlockPat), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum FieldList { @@ -2772,6 +2782,17 @@ impl AstNode for TupleStructPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for ConstBlockPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_BLOCK_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for RecordPatFieldList { fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT_FIELD_LIST } fn cast(syntax: SyntaxNode) -> Option { @@ -3242,12 +3263,15 @@ impl From for Pat { impl From for Pat { fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) } } +impl From for Pat { + fn from(node: ConstBlockPat) -> Pat { Pat::ConstBlockPat(node) } +} impl AstNode for Pat { fn can_cast(kind: SyntaxKind) -> bool { match kind { IDENT_PAT | BOX_PAT | REST_PAT | LITERAL_PAT | MACRO_PAT | OR_PAT | PAREN_PAT | PATH_PAT | WILDCARD_PAT | RANGE_PAT | RECORD_PAT | REF_PAT | SLICE_PAT - | TUPLE_PAT | TUPLE_STRUCT_PAT => true, + | TUPLE_PAT | TUPLE_STRUCT_PAT | CONST_BLOCK_PAT => true, _ => false, } } @@ -3268,6 +3292,7 @@ impl AstNode for Pat { SLICE_PAT => Pat::SlicePat(SlicePat { syntax }), TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }), TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }), + CONST_BLOCK_PAT => Pat::ConstBlockPat(ConstBlockPat { syntax }), _ => return None, }; Some(res) @@ -3289,6 +3314,7 @@ impl AstNode for Pat { Pat::SlicePat(it) => &it.syntax, Pat::TuplePat(it) => &it.syntax, Pat::TupleStructPat(it) => &it.syntax, + Pat::ConstBlockPat(it) => &it.syntax, } } } @@ -4137,6 +4163,11 @@ impl std::fmt::Display for TupleStructPat { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for ConstBlockPat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for RecordPatFieldList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 78a0b54ba..96b4ea448 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -15,7 +15,7 @@ flate2 = "1.0" pico-args = "0.3.1" proc-macro2 = "1.0.8" quote = "1.0.2" -ungrammar = "1.4" +ungrammar = "1.5" walkdir = "2.3.1" write-json = "0.1.0" xshell = "0.1" diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index a69ced5cc..2b8012bdd 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -132,6 +132,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { "RANGE_PAT", "LITERAL_PAT", "MACRO_PAT", + "CONST_BLOCK_PAT", // atoms "TUPLE_EXPR", "ARRAY_EXPR", -- cgit v1.2.3