From d6533994e461dac502672c77ff27c6ca08fdc092 Mon Sep 17 00:00:00 2001 From: csmoe Date: Tue, 18 Jun 2019 23:50:57 +0800 Subject: fix: box_pattern Change-Id: I45a856d74fb616d3bce33050f9e69d327186bd59 --- crates/ra_parser/src/grammar/expressions.rs | 5 ----- crates/ra_parser/src/grammar/expressions/atom.rs | 15 +++++++++++++++ crates/ra_parser/src/grammar/patterns.rs | 3 +++ crates/ra_parser/src/syntax_kind/generated.rs | 7 +++++++ 4 files changed, 25 insertions(+), 5 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 2ae05521c..795dccea1 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -583,8 +583,3 @@ pub(crate) fn named_field_list(p: &mut Parser) { p.expect(T!['}']); m.complete(p, NAMED_FIELD_LIST); } - -// test box_syntax -// fn foo() { -// let x = box 1i32; -// } diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 725fb99f6..41be283d0 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -74,6 +74,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar T![if] => if_expr(p), T![loop] => loop_expr(p, None), + T![box] => box_expr(p, None), T![for] => for_expr(p, None), T![while] => while_expr(p, None), T![try] => try_block_expr(p, None), @@ -507,3 +508,17 @@ fn try_block_expr(p: &mut Parser, m: Option) -> CompletedMarker { block(p); m.complete(p, TRY_EXPR) } + +// test box_expr +// fn foo() { +// let x = box 1i32; +// } +fn box_expr(p: &mut Parser, m: Option) -> CompletedMarker { + assert!(p.at(T![box])); + let m = m.unwrap_or_else(|| p.start()); + p.bump(); + if p.at_ts(EXPR_FIRST) { + expr(p); + } + m.complete(p, BOX_EXPR) +} diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index 16ae9da63..46034942a 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs @@ -60,6 +60,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { let la1 = p.nth(1); if la0 == T![ref] || la0 == T![mut] + || la0 == T![box] || (la0 == IDENT && !(la1 == T![::] || la1 == T!['('] || la1 == T!['{'] || la1 == T![!])) { return Some(bind_pat(p, true)); @@ -260,9 +261,11 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) { // let ref mut d = (); // let e @ _ = (); // let ref mut f @ g @ _ = (); +// let box i = Box::new(1i32); // } fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { let m = p.start(); + p.eat(T![box]); p.eat(T![ref]); p.eat(T![mut]); name(p); diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 036415eac..374fd5aec 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -104,6 +104,7 @@ pub enum SyntaxKind { MOVE_KW, RETURN_KW, TRY_KW, + BOX_KW, AUTO_KW, DEFAULT_KW, EXISTENTIAL_KW, @@ -187,6 +188,7 @@ pub enum SyntaxKind { NAMED_FIELD_LIST, NAMED_FIELD, TRY_BLOCK_EXPR, + BOX_EXPR, CALL_EXPR, INDEX_EXPR, METHOD_CALL_EXPR, @@ -335,6 +337,7 @@ macro_rules! T { (move) => { $crate::SyntaxKind::MOVE_KW }; (return) => { $crate::SyntaxKind::RETURN_KW }; (try) => { $crate::SyntaxKind::TRY_KW }; + (box) => { $crate::SyntaxKind::BOX_KW }; (auto) => { $crate::SyntaxKind::AUTO_KW }; (default) => { $crate::SyntaxKind::DEFAULT_KW }; (existential) => { $crate::SyntaxKind::EXISTENTIAL_KW }; @@ -394,6 +397,7 @@ impl SyntaxKind { | MOVE_KW | RETURN_KW | TRY_KW + | BOX_KW | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW @@ -567,6 +571,7 @@ impl SyntaxKind { MOVE_KW => &SyntaxInfo { name: "MOVE_KW" }, RETURN_KW => &SyntaxInfo { name: "RETURN_KW" }, TRY_KW => &SyntaxInfo { name: "TRY_KW" }, + BOX_KW => &SyntaxInfo { name: "BOX_KW" }, AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, EXISTENTIAL_KW => &SyntaxInfo { name: "EXISTENTIAL_KW" }, @@ -650,6 +655,7 @@ impl SyntaxKind { NAMED_FIELD_LIST => &SyntaxInfo { name: "NAMED_FIELD_LIST" }, NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, TRY_BLOCK_EXPR => &SyntaxInfo { name: "TRY_BLOCK_EXPR" }, + BOX_EXPR => &SyntaxInfo { name: "BOX_EXPR" }, CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" }, METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, @@ -745,6 +751,7 @@ impl SyntaxKind { "move" => MOVE_KW, "return" => RETURN_KW, "try" => TRY_KW, + "box" => BOX_KW, _ => return None, }; Some(kw) -- cgit v1.2.3