Skip to content

Commit be72604

Browse files
committed
Update ungrammar for const block patterns
1 parent 4a2f60c commit be72604

File tree

7 files changed

+40
-7
lines changed

7 files changed

+40
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ debug = 0 # Set this to 1 or 2 to get more useful backtraces in debugger.
2626
# chalk-ir = { path = "../chalk/chalk-ir" }
2727
# chalk-recursive = { path = "../chalk/chalk-recursive" }
2828

29-
# ungrammar = { path = "../ungrammar" }
29+
ungrammar = { path = "../ungrammar" }

crates/hir_def/src/body/lower.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,9 @@ impl ExprCollector<'_> {
933933
Pat::Box { inner }
934934
}
935935
// FIXME: implement
936-
ast::Pat::RangePat(_) | ast::Pat::MacroPat(_) => Pat::Missing,
936+
ast::Pat::RangePat(_) | ast::Pat::MacroPat(_) | ast::Pat::ConstBlockPat(_) => {
937+
Pat::Missing
938+
}
937939
};
938940
let ptr = AstPtr::new(&pat);
939941
self.alloc_pat(pattern, Either::Left(ptr))

crates/parser/src/syntax_kind/generated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub enum SyntaxKind {
170170
RANGE_PAT,
171171
LITERAL_PAT,
172172
MACRO_PAT,
173+
CONST_BLOCK_PAT,
173174
TUPLE_EXPR,
174175
ARRAY_EXPR,
175176
PAREN_EXPR,

crates/syntax/src/ast/generated/nodes.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ impl EffectExpr {
763763
pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
764764
pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
765765
pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
766+
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
766767
pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
767768
}
768769
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1251,6 +1252,14 @@ impl TupleStructPat {
12511252
pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
12521253
}
12531254
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1255+
pub struct ConstBlockPat {
1256+
pub(crate) syntax: SyntaxNode,
1257+
}
1258+
impl ConstBlockPat {
1259+
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
1260+
pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
1261+
}
1262+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12541263
pub struct RecordPatFieldList {
12551264
pub(crate) syntax: SyntaxNode,
12561265
}
@@ -1369,6 +1378,7 @@ pub enum Pat {
13691378
SlicePat(SlicePat),
13701379
TuplePat(TuplePat),
13711380
TupleStructPat(TupleStructPat),
1381+
ConstBlockPat(ConstBlockPat),
13721382
}
13731383
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13741384
pub enum FieldList {
@@ -2772,6 +2782,17 @@ impl AstNode for TupleStructPat {
27722782
}
27732783
fn syntax(&self) -> &SyntaxNode { &self.syntax }
27742784
}
2785+
impl AstNode for ConstBlockPat {
2786+
fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_BLOCK_PAT }
2787+
fn cast(syntax: SyntaxNode) -> Option<Self> {
2788+
if Self::can_cast(syntax.kind()) {
2789+
Some(Self { syntax })
2790+
} else {
2791+
None
2792+
}
2793+
}
2794+
fn syntax(&self) -> &SyntaxNode { &self.syntax }
2795+
}
27752796
impl AstNode for RecordPatFieldList {
27762797
fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT_FIELD_LIST }
27772798
fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3242,12 +3263,15 @@ impl From<TuplePat> for Pat {
32423263
impl From<TupleStructPat> for Pat {
32433264
fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) }
32443265
}
3266+
impl From<ConstBlockPat> for Pat {
3267+
fn from(node: ConstBlockPat) -> Pat { Pat::ConstBlockPat(node) }
3268+
}
32453269
impl AstNode for Pat {
32463270
fn can_cast(kind: SyntaxKind) -> bool {
32473271
match kind {
32483272
IDENT_PAT | BOX_PAT | REST_PAT | LITERAL_PAT | MACRO_PAT | OR_PAT | PAREN_PAT
32493273
| PATH_PAT | WILDCARD_PAT | RANGE_PAT | RECORD_PAT | REF_PAT | SLICE_PAT
3250-
| TUPLE_PAT | TUPLE_STRUCT_PAT => true,
3274+
| TUPLE_PAT | TUPLE_STRUCT_PAT | CONST_BLOCK_PAT => true,
32513275
_ => false,
32523276
}
32533277
}
@@ -3268,6 +3292,7 @@ impl AstNode for Pat {
32683292
SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
32693293
TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
32703294
TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
3295+
CONST_BLOCK_PAT => Pat::ConstBlockPat(ConstBlockPat { syntax }),
32713296
_ => return None,
32723297
};
32733298
Some(res)
@@ -3289,6 +3314,7 @@ impl AstNode for Pat {
32893314
Pat::SlicePat(it) => &it.syntax,
32903315
Pat::TuplePat(it) => &it.syntax,
32913316
Pat::TupleStructPat(it) => &it.syntax,
3317+
Pat::ConstBlockPat(it) => &it.syntax,
32923318
}
32933319
}
32943320
}
@@ -4137,6 +4163,11 @@ impl std::fmt::Display for TupleStructPat {
41374163
std::fmt::Display::fmt(self.syntax(), f)
41384164
}
41394165
}
4166+
impl std::fmt::Display for ConstBlockPat {
4167+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4168+
std::fmt::Display::fmt(self.syntax(), f)
4169+
}
4170+
}
41404171
impl std::fmt::Display for RecordPatFieldList {
41414172
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41424173
std::fmt::Display::fmt(self.syntax(), f)

xtask/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ flate2 = "1.0"
1515
pico-args = "0.3.1"
1616
proc-macro2 = "1.0.8"
1717
quote = "1.0.2"
18-
ungrammar = "1.4"
18+
ungrammar = "1.5"
1919
walkdir = "2.3.1"
2020
write-json = "0.1.0"
2121
xshell = "0.1"

xtask/src/ast_src.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
132132
"RANGE_PAT",
133133
"LITERAL_PAT",
134134
"MACRO_PAT",
135+
"CONST_BLOCK_PAT",
135136
// atoms
136137
"TUPLE_EXPR",
137138
"ARRAY_EXPR",

0 commit comments

Comments
 (0)