From e2b378ef7e0ed82b0f0c874f98032a368fd5f30f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 10 Sep 2019 00:59:29 +0300 Subject: rename bump -> bump_any --- crates/ra_parser/src/grammar.rs | 40 ++++++++++++------------ crates/ra_parser/src/grammar/attributes.rs | 4 +-- crates/ra_parser/src/grammar/expressions.rs | 38 +++++++++++----------- crates/ra_parser/src/grammar/expressions/atom.rs | 36 ++++++++++----------- crates/ra_parser/src/grammar/items.rs | 20 ++++++------ crates/ra_parser/src/grammar/items/consts.rs | 2 +- crates/ra_parser/src/grammar/items/nominal.rs | 12 +++---- crates/ra_parser/src/grammar/items/traits.rs | 8 ++--- crates/ra_parser/src/grammar/items/use_item.rs | 16 +++++----- crates/ra_parser/src/grammar/params.rs | 4 +-- crates/ra_parser/src/grammar/paths.rs | 4 +-- crates/ra_parser/src/grammar/patterns.rs | 22 ++++++------- crates/ra_parser/src/grammar/type_args.rs | 10 +++--- crates/ra_parser/src/grammar/type_params.rs | 18 +++++------ crates/ra_parser/src/grammar/types.rs | 24 +++++++------- crates/ra_parser/src/parser.rs | 6 ++-- 16 files changed, 132 insertions(+), 132 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index a2ad580bc..89f4b63ec 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -93,12 +93,12 @@ pub(crate) mod fragments { // https://doc.rust-lang.org/reference/paths.html#simple-paths // The start of an meta must be a simple path match p.current() { - IDENT | T![::] | T![super] | T![self] | T![crate] => p.bump(), + IDENT | T![::] | T![super] | T![self] | T![crate] => p.bump_any(), T![=] => { - p.bump(); + p.bump_any(); match p.current() { - c if c.is_literal() => p.bump(), - T![true] | T![false] => p.bump(), + c if c.is_literal() => p.bump_any(), + T![true] | T![false] => p.bump_any(), _ => {} } break; @@ -126,7 +126,7 @@ pub(crate) mod fragments { while !p.at(EOF) { if p.at(T![;]) { - p.bump(); + p.bump_any(); continue; } @@ -179,7 +179,7 @@ fn opt_visibility(p: &mut Parser) -> bool { match p.current() { T![pub] => { let m = p.start(); - p.bump(); + p.bump_any(); if p.at(T!['(']) { match p.nth(1) { // test crate_visibility @@ -188,13 +188,13 @@ fn opt_visibility(p: &mut Parser) -> bool { // pub(self) struct S; // pub(self) struct S; T![crate] | T![self] | T![super] => { - p.bump(); - p.bump(); + p.bump_any(); + p.bump_any(); p.expect(T![')']); } T![in] => { - p.bump(); - p.bump(); + p.bump_any(); + p.bump_any(); paths::use_path(p); p.expect(T![')']); } @@ -212,7 +212,7 @@ fn opt_visibility(p: &mut Parser) -> bool { // fn foo() { crate::foo(); } T![crate] if p.nth(1) != T![::] => { let m = p.start(); - p.bump(); + p.bump_any(); m.complete(p, VISIBILITY); } _ => return false, @@ -223,7 +223,7 @@ fn opt_visibility(p: &mut Parser) -> bool { fn opt_alias(p: &mut Parser) { if p.at(T![as]) { let m = p.start(); - p.bump(); + p.bump_any(); if !p.eat(T![_]) { name(p); } @@ -234,9 +234,9 @@ fn opt_alias(p: &mut Parser) { fn abi(p: &mut Parser) { assert!(p.at(T![extern])); let abi = p.start(); - p.bump(); + p.bump_any(); match p.current() { - STRING | RAW_STRING => p.bump(), + STRING | RAW_STRING => p.bump_any(), _ => (), } abi.complete(p, ABI); @@ -245,7 +245,7 @@ fn abi(p: &mut Parser) { fn opt_fn_ret_type(p: &mut Parser) -> bool { if p.at(T![->]) { let m = p.start(); - p.bump(); + p.bump_any(); types::type_(p); m.complete(p, RET_TYPE); true @@ -257,7 +257,7 @@ fn opt_fn_ret_type(p: &mut Parser) -> bool { fn name_r(p: &mut Parser, recovery: TokenSet) { if p.at(IDENT) { let m = p.start(); - p.bump(); + p.bump_any(); m.complete(p, NAME); } else { p.err_recover("expected a name", recovery); @@ -271,11 +271,11 @@ fn name(p: &mut Parser) { fn name_ref(p: &mut Parser) { if p.at(IDENT) { let m = p.start(); - p.bump(); + p.bump_any(); m.complete(p, NAME_REF); } else if p.at(T![self]) { let m = p.start(); - p.bump(); + p.bump_any(); m.complete(p, T![self]); } else { p.err_and_bump("expected identifier"); @@ -285,7 +285,7 @@ fn name_ref(p: &mut Parser) { fn name_ref_or_index(p: &mut Parser) { if p.at(IDENT) || p.at(INT_NUMBER) { let m = p.start(); - p.bump(); + p.bump_any(); m.complete(p, NAME_REF); } else { p.err_and_bump("expected identifier"); @@ -296,7 +296,7 @@ fn error_block(p: &mut Parser, message: &str) { assert!(p.at(T!['{'])); let m = p.start(); p.error(message); - p.bump(); + p.bump_any(); expressions::expr_block_contents(p); p.eat(T!['}']); m.complete(p, ERROR); diff --git a/crates/ra_parser/src/grammar/attributes.rs b/crates/ra_parser/src/grammar/attributes.rs index e97170203..81a363a57 100644 --- a/crates/ra_parser/src/grammar/attributes.rs +++ b/crates/ra_parser/src/grammar/attributes.rs @@ -15,11 +15,11 @@ pub(super) fn outer_attributes(p: &mut Parser) { fn attribute(p: &mut Parser, inner: bool) { let attr = p.start(); assert!(p.at(T![#])); - p.bump(); + p.bump_any(); if inner { assert!(p.at(T![!])); - p.bump(); + p.bump_any(); } if p.at(T!['[']) { diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 855418f1c..30036eb46 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -46,7 +46,7 @@ pub(crate) fn block(p: &mut Parser) { pub(crate) fn naked_block(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); expr_block_contents(p); p.expect(T!['}']); m.complete(p, BLOCK); @@ -153,7 +153,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) { // } fn let_stmt(p: &mut Parser, m: Marker, with_semi: StmtWithSemi) { assert!(p.at(T![let])); - p.bump(); + p.bump_any(); patterns::pattern(p); if p.at(T![:]) { types::ascription(p); @@ -198,7 +198,7 @@ pub(crate) fn expr_block_contents(p: &mut Parser) { // } if p.at(T![;]) { - p.bump(); + p.bump_any(); continue; } @@ -309,7 +309,7 @@ fn expr_bp( } let m = lhs.precede(p); match op { - Op::Simple => p.bump(), + Op::Simple => p.bump_any(), Op::Composite(kind, n) => { p.bump_compound(kind, n); } @@ -338,7 +338,7 @@ fn lhs( // } T![&] => { m = p.start(); - p.bump(); + p.bump_any(); p.eat(T![mut]); REF_EXPR } @@ -350,14 +350,14 @@ fn lhs( // } T![*] | T![!] | T![-] => { m = p.start(); - p.bump(); + p.bump_any(); PREFIX_EXPR } // test full_range_expr // fn foo() { xs[..]; } T![..] | T![..=] => { m = p.start(); - p.bump(); + p.bump_any(); if p.at_ts(EXPR_FIRST) { expr_bp(p, r, 2, dollar_lvl); } @@ -410,8 +410,8 @@ fn postfix_expr( // x.0().await?.hello(); // } let m = lhs.precede(p); - p.bump(); - p.bump(); + p.bump_any(); + p.bump_any(); m.complete(p, AWAIT_EXPR) } T![.] => field_expr(p, lhs), @@ -419,7 +419,7 @@ fn postfix_expr( // fn foo() { let x = 1..; } T![..] | T![..=] if !EXPR_FIRST.contains(p.nth(1)) => { let m = lhs.precede(p); - p.bump(); + p.bump_any(); m.complete(p, RANGE_EXPR) } T![?] => try_expr(p, lhs), @@ -453,7 +453,7 @@ fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T!['['])); let m = lhs.precede(p); - p.bump(); + p.bump_any(); expr(p); p.expect(T![']']); m.complete(p, INDEX_EXPR) @@ -467,7 +467,7 @@ fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![.]) && p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth(2) == T![::])); let m = lhs.precede(p); - p.bump(); + p.bump_any(); name_ref(p); type_args::opt_type_arg_list(p, true); if p.at(T!['(']) { @@ -493,12 +493,12 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![.])); let m = lhs.precede(p); - p.bump(); + p.bump_any(); if p.at(IDENT) || p.at(INT_NUMBER) { name_ref_or_index(p) } else if p.at(FLOAT_NUMBER) { // FIXME: How to recover and instead parse INT + T![.]? - p.bump(); + p.bump_any(); } else { p.error("expected field name or number") } @@ -512,7 +512,7 @@ fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![?])); let m = lhs.precede(p); - p.bump(); + p.bump_any(); m.complete(p, TRY_EXPR) } @@ -526,7 +526,7 @@ fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![as])); let m = lhs.precede(p); - p.bump(); + p.bump_any(); // Use type_no_bounds(), because cast expressions are not // allowed to have bounds. types::type_no_bounds(p); @@ -536,7 +536,7 @@ fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn arg_list(p: &mut Parser) { assert!(p.at(T!['('])); let m = p.start(); - p.bump(); + p.bump_any(); while !p.at(T![')']) && !p.at(EOF) { if !p.at_ts(EXPR_FIRST) { p.error("expected expression"); @@ -585,7 +585,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) { pub(crate) fn record_field_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); while !p.at(EOF) && !p.at(T!['}']) { match p.current() { // test record_literal_field_with_attr @@ -602,7 +602,7 @@ pub(crate) fn record_field_list(p: &mut Parser) { m.complete(p, RECORD_FIELD); } T![..] => { - p.bump(); + p.bump_any(); expr(p); } T!['{'] => error_block(p, "expected a field"), diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index ec7f2441d..cea79cf6f 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -31,7 +31,7 @@ pub(crate) fn literal(p: &mut Parser) -> Option { return None; } let m = p.start(); - p.bump(); + p.bump_any(); Some(m.complete(p, LITERAL)) } @@ -100,14 +100,14 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar } T![async] if la == T!['{'] || (la == T![move] && p.nth(2) == T!['{']) => { let m = p.start(); - p.bump(); + p.bump_any(); p.eat(T![move]); block_expr(p, Some(m)) } T![match] => match_expr(p), T![unsafe] if la == T!['{'] => { let m = p.start(); - p.bump(); + p.bump_any(); block_expr(p, Some(m)) } T!['{'] => { @@ -179,7 +179,7 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker { fn array_expr(p: &mut Parser) -> CompletedMarker { assert!(p.at(T!['['])); let m = p.start(); - p.bump(); + p.bump_any(); if p.eat(T![']']) { return m.complete(p, ARRAY_EXPR); } @@ -261,11 +261,11 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { fn if_expr(p: &mut Parser) -> CompletedMarker { assert!(p.at(T![if])); let m = p.start(); - p.bump(); + p.bump_any(); cond(p); block(p); if p.at(T![else]) { - p.bump(); + p.bump_any(); if p.at(T![if]) { if_expr(p); } else { @@ -284,8 +284,8 @@ fn if_expr(p: &mut Parser) -> CompletedMarker { fn label(p: &mut Parser) { assert!(p.at(LIFETIME) && p.nth(1) == T![:]); let m = p.start(); - p.bump(); - p.bump(); + p.bump_any(); + p.bump_any(); m.complete(p, LABEL); } @@ -296,7 +296,7 @@ fn label(p: &mut Parser) { fn loop_expr(p: &mut Parser, m: Option) -> CompletedMarker { assert!(p.at(T![loop])); let m = m.unwrap_or_else(|| p.start()); - p.bump(); + p.bump_any(); block(p); m.complete(p, LOOP_EXPR) } @@ -309,7 +309,7 @@ fn loop_expr(p: &mut Parser, m: Option) -> CompletedMarker { fn while_expr(p: &mut Parser, m: Option) -> CompletedMarker { assert!(p.at(T![while])); let m = m.unwrap_or_else(|| p.start()); - p.bump(); + p.bump_any(); cond(p); block(p); m.complete(p, WHILE_EXPR) @@ -322,7 +322,7 @@ fn while_expr(p: &mut Parser, m: Option) -> CompletedMarker { fn for_expr(p: &mut Parser, m: Option) -> CompletedMarker { assert!(p.at(T![for])); let m = m.unwrap_or_else(|| p.start()); - p.bump(); + p.bump_any(); patterns::pattern(p); p.expect(T![in]); expr_no_struct(p); @@ -356,7 +356,7 @@ fn cond(p: &mut Parser) { fn match_expr(p: &mut Parser) -> CompletedMarker { assert!(p.at(T![match])); let m = p.start(); - p.bump(); + p.bump_any(); expr_no_struct(p); if p.at(T!['{']) { match_arm_list(p); @@ -452,7 +452,7 @@ fn match_arm(p: &mut Parser) -> BlockLike { fn match_guard(p: &mut Parser) -> CompletedMarker { assert!(p.at(T![if])); let m = p.start(); - p.bump(); + p.bump_any(); expr(p); m.complete(p, MATCH_GUARD) } @@ -478,7 +478,7 @@ pub(super) fn block_expr(p: &mut Parser, m: Option) -> CompletedMarker { fn return_expr(p: &mut Parser) -> CompletedMarker { assert!(p.at(T![return])); let m = p.start(); - p.bump(); + p.bump_any(); if p.at_ts(EXPR_FIRST) { expr(p); } @@ -495,7 +495,7 @@ fn return_expr(p: &mut Parser) -> CompletedMarker { fn continue_expr(p: &mut Parser) -> CompletedMarker { assert!(p.at(T![continue])); let m = p.start(); - p.bump(); + p.bump_any(); p.eat(LIFETIME); m.complete(p, CONTINUE_EXPR) } @@ -512,7 +512,7 @@ fn continue_expr(p: &mut Parser) -> CompletedMarker { fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { assert!(p.at(T![break])); let m = p.start(); - p.bump(); + p.bump_any(); p.eat(LIFETIME); // test break_ambiguity // fn foo(){ @@ -534,7 +534,7 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { fn try_block_expr(p: &mut Parser, m: Option) -> CompletedMarker { assert!(p.at(T![try])); let m = m.unwrap_or_else(|| p.start()); - p.bump(); + p.bump_any(); block(p); m.complete(p, TRY_EXPR) } @@ -548,7 +548,7 @@ fn try_block_expr(p: &mut Parser, m: Option) -> CompletedMarker { fn box_expr(p: &mut Parser, m: Option) -> CompletedMarker { assert!(p.at(T![box])); let m = m.unwrap_or_else(|| p.start()); - p.bump(); + p.bump_any(); if p.at_ts(EXPR_FIRST) { expr(p); } diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index b4327b78f..f27cc85ff 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -64,7 +64,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF } else if p.at(T!['}']) && !stop_on_r_curly { let e = p.start(); p.error("unmatched `}`"); - p.bump(); + p.bump_any(); e.complete(p, ERROR); } else if !p.at(EOF) && !p.at(T!['}']) { p.err_and_bump("expected an item"); @@ -276,9 +276,9 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { fn extern_crate_item(p: &mut Parser, m: Marker) { assert!(p.at(T![extern])); - p.bump(); + p.bump_any(); assert!(p.at(T![crate])); - p.bump(); + p.bump_any(); name_ref(p); opt_alias(p); p.expect(T![;]); @@ -288,7 +288,7 @@ fn extern_crate_item(p: &mut Parser, m: Marker) { pub(crate) fn extern_item_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); mod_contents(p, true); p.expect(T!['}']); m.complete(p, EXTERN_ITEM_LIST); @@ -296,7 +296,7 @@ pub(crate) fn extern_item_list(p: &mut Parser) { fn fn_def(p: &mut Parser, flavor: ItemFlavor) { assert!(p.at(T![fn])); - p.bump(); + p.bump_any(); name_r(p, ITEM_RECOVERY_SET); // test function_type_params @@ -323,7 +323,7 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) { // test fn_decl // trait T { fn foo(); } if p.at(T![;]) { - p.bump(); + p.bump_any(); } else { expressions::block(p) } @@ -333,7 +333,7 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) { // type Foo = Bar; fn type_def(p: &mut Parser, m: Marker) { assert!(p.at(T![type])); - p.bump(); + p.bump_any(); name(p); @@ -357,7 +357,7 @@ fn type_def(p: &mut Parser, m: Marker) { pub(crate) fn mod_item(p: &mut Parser, m: Marker) { assert!(p.at(T![mod])); - p.bump(); + p.bump_any(); name(p); if p.at(T!['{']) { @@ -371,7 +371,7 @@ pub(crate) fn mod_item(p: &mut Parser, m: Marker) { pub(crate) fn mod_item_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); mod_contents(p, true); p.expect(T!['}']); m.complete(p, ITEM_LIST); @@ -412,7 +412,7 @@ pub(crate) fn token_tree(p: &mut Parser) { _ => unreachable!(), }; let m = p.start(); - p.bump(); + p.bump_any(); while !p.at(EOF) && !p.at(closing_paren_kind) { match p.current() { T!['{'] | T!['('] | T!['['] => token_tree(p), diff --git a/crates/ra_parser/src/grammar/items/consts.rs b/crates/ra_parser/src/grammar/items/consts.rs index b4908ebba..e11546333 100644 --- a/crates/ra_parser/src/grammar/items/consts.rs +++ b/crates/ra_parser/src/grammar/items/consts.rs @@ -10,7 +10,7 @@ pub(super) fn const_def(p: &mut Parser, m: Marker) { fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { assert!(p.at(kw)); - p.bump(); + p.bump_any(); p.eat(T![mut]); // FIXME: validator to forbid const mut name(p); types::ascription(p); diff --git a/crates/ra_parser/src/grammar/items/nominal.rs b/crates/ra_parser/src/grammar/items/nominal.rs index 54f02c7c9..460acd65e 100644 --- a/crates/ra_parser/src/grammar/items/nominal.rs +++ b/crates/ra_parser/src/grammar/items/nominal.rs @@ -11,7 +11,7 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) { type_params::opt_where_clause(p); match p.current() { T![;] => { - p.bump(); + p.bump_any(); } T!['{'] => record_field_def_list(p), _ => { @@ -21,7 +21,7 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) { } } T![;] if kind == T![struct] => { - p.bump(); + p.bump_any(); } T!['{'] => record_field_def_list(p), T!['('] if kind == T![struct] => { @@ -44,7 +44,7 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) { pub(super) fn enum_def(p: &mut Parser, m: Marker) { assert!(p.at(T![enum])); - p.bump(); + p.bump_any(); name_r(p, ITEM_RECOVERY_SET); type_params::opt_type_param_list(p); type_params::opt_where_clause(p); @@ -59,7 +59,7 @@ pub(super) fn enum_def(p: &mut Parser, m: Marker) { pub(crate) fn enum_variant_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); while !p.at(EOF) && !p.at(T!['}']) { if p.at(T!['{']) { error_block(p, "expected enum variant"); @@ -73,7 +73,7 @@ pub(crate) fn enum_variant_list(p: &mut Parser) { T!['{'] => record_field_def_list(p), T!['('] => tuple_field_def_list(p), T![=] => { - p.bump(); + p.bump_any(); expressions::expr(p); } _ => (), @@ -94,7 +94,7 @@ pub(crate) fn enum_variant_list(p: &mut Parser) { pub(crate) fn record_field_def_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); while !p.at(T!['}']) && !p.at(EOF) { if p.at(T!['{']) { error_block(p, "expected field"); diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs index 5fcacfbff..b49221a4b 100644 --- a/crates/ra_parser/src/grammar/items/traits.rs +++ b/crates/ra_parser/src/grammar/items/traits.rs @@ -5,7 +5,7 @@ use super::*; // trait X: Hash + Clone where U: Copy {} pub(super) fn trait_def(p: &mut Parser) { assert!(p.at(T![trait])); - p.bump(); + p.bump_any(); name_r(p, ITEM_RECOVERY_SET); type_params::opt_type_param_list(p); if p.at(T![:]) { @@ -29,7 +29,7 @@ pub(super) fn trait_def(p: &mut Parser) { pub(crate) fn trait_item_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); while !p.at(EOF) && !p.at(T!['}']) { if p.at(T!['{']) { error_block(p, "expected an item"); @@ -45,7 +45,7 @@ pub(crate) fn trait_item_list(p: &mut Parser) { // impl Foo {} pub(super) fn impl_block(p: &mut Parser) { assert!(p.at(T![impl])); - p.bump(); + p.bump_any(); if choose_type_params_over_qpath(p) { type_params::opt_type_param_list(p); } @@ -78,7 +78,7 @@ pub(super) fn impl_block(p: &mut Parser) { pub(crate) fn impl_item_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); // test impl_inner_attributes // enum F{} // impl F { diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs index 83a65e226..7a1693a34 100644 --- a/crates/ra_parser/src/grammar/items/use_item.rs +++ b/crates/ra_parser/src/grammar/items/use_item.rs @@ -2,7 +2,7 @@ use super::*; pub(super) fn use_item(p: &mut Parser, m: Marker) { assert!(p.at(T![use])); - p.bump(); + p.bump_any(); use_tree(p); p.expect(T![;]); m.complete(p, USE_ITEM); @@ -28,15 +28,15 @@ fn use_tree(p: &mut Parser) { // use ::*; // use some::path::{*}; // use some::path::{::*}; - (T![*], _) => p.bump(), + (T![*], _) => p.bump_any(), (T![::], T![*]) => { // Parse `use ::*;`, which imports all from the crate root in Rust 2015 // This is invalid inside a use_tree_list, (e.g. `use some::path::{::*}`) // but still parses and errors later: ('crate root in paths can only be used in start position') // FIXME: Add this error (if not out of scope) // In Rust 2018, it is always invalid (see above) - p.bump(); - p.bump(); + p.bump_any(); + p.bump_any(); } // Open a use tree list // Handles cases such as `use {some::path};` or `{inner::path}` in @@ -49,7 +49,7 @@ fn use_tree(p: &mut Parser) { // use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig (T!['{'], _) | (T![::], T!['{']) => { if p.at(T![::]) { - p.bump(); + p.bump_any(); } use_tree_list(p); } @@ -81,10 +81,10 @@ fn use_tree(p: &mut Parser) { opt_alias(p); } T![::] => { - p.bump(); + p.bump_any(); match p.current() { T![*] => { - p.bump(); + p.bump_any(); } // test use_tree_list_after_path // use crate::{Item}; @@ -114,7 +114,7 @@ fn use_tree(p: &mut Parser) { pub(crate) fn use_tree_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); while !p.at(EOF) && !p.at(T!['}']) { use_tree(p); if !p.at(T!['}']) { diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs index 0b09f1874..56e457325 100644 --- a/crates/ra_parser/src/grammar/params.rs +++ b/crates/ra_parser/src/grammar/params.rs @@ -39,7 +39,7 @@ fn list_(p: &mut Parser, flavor: Flavor) { let (bra, ket) = if flavor.type_required() { (T!['('], T![')']) } else { (T![|], T![|]) }; assert!(p.at(bra)); let m = p.start(); - p.bump(); + p.bump_any(); if flavor.type_required() { // test self_param_outer_attr // fn f(#[must_use] self) {} @@ -146,7 +146,7 @@ fn opt_self_param(p: &mut Parser) { }; m = p.start(); for _ in 0..n_toks { - p.bump(); + p.bump_any(); } } m.complete(p, SELF_PARAM); diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index 28c35a67d..345c93f55 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs @@ -44,7 +44,7 @@ fn path(p: &mut Parser, mode: Mode) { }; if p.at(T![::]) && !use_tree { let path = qual.precede(p); - p.bump(); + p.bump_any(); path_segment(p, mode, false); let path = path.complete(p, PATH); qual = path; @@ -80,7 +80,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { } // test crate_path // use crate::foo; - T![self] | T![super] | T![crate] => p.bump(), + T![self] | T![super] | T![crate] => p.bump_any(), _ => { p.err_recover("expected identifier", items::ITEM_RECOVERY_SET); } diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index 32cde7de6..d2f4296f8 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs @@ -36,7 +36,7 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { // } if p.at(T![...]) || p.at(T![..=]) || p.at(T![..]) { let m = lhs.precede(p); - p.bump(); + p.bump_any(); atom_pat(p, recovery_set); m.complete(p, RANGE_PAT); } @@ -100,7 +100,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker { assert!(is_literal_pat_start(p)); let m = p.start(); if p.at(T![-]) { - p.bump(); + p.bump_any(); } expressions::literal(p); m.complete(p, LITERAL_PAT) @@ -140,7 +140,7 @@ fn path_pat(p: &mut Parser) -> CompletedMarker { // } fn tuple_pat_fields(p: &mut Parser) { assert!(p.at(T!['('])); - p.bump(); + p.bump_any(); pat_list(p, T![')']); p.expect(T![')']); } @@ -155,10 +155,10 @@ fn tuple_pat_fields(p: &mut Parser) { fn record_field_pat_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); - p.bump(); + p.bump_any(); while !p.at(EOF) && !p.at(T!['}']) { match p.current() { - T![..] => p.bump(), + T![..] => p.bump_any(), IDENT if p.nth(1) == T![:] => record_field_pat(p), T!['{'] => error_block(p, "expected ident"), T![box] => { @@ -182,7 +182,7 @@ fn record_field_pat(p: &mut Parser) { let m = p.start(); name(p); - p.bump(); + p.bump_any(); pattern(p); m.complete(p, RECORD_FIELD_PAT); } @@ -192,7 +192,7 @@ fn record_field_pat(p: &mut Parser) { fn placeholder_pat(p: &mut Parser) -> CompletedMarker { assert!(p.at(T![_])); let m = p.start(); - p.bump(); + p.bump_any(); m.complete(p, PLACEHOLDER_PAT) } @@ -204,7 +204,7 @@ fn placeholder_pat(p: &mut Parser) -> CompletedMarker { fn ref_pat(p: &mut Parser) -> CompletedMarker { assert!(p.at(T![&])); let m = p.start(); - p.bump(); + p.bump_any(); p.eat(T![mut]); pattern(p); m.complete(p, REF_PAT) @@ -228,7 +228,7 @@ fn tuple_pat(p: &mut Parser) -> CompletedMarker { fn slice_pat(p: &mut Parser) -> CompletedMarker { assert!(p.at(T!['['])); let m = p.start(); - p.bump(); + p.bump_any(); pat_list(p, T![']']); p.expect(T![']']); m.complete(p, SLICE_PAT) @@ -237,7 +237,7 @@ fn slice_pat(p: &mut Parser) -> CompletedMarker { fn pat_list(p: &mut Parser, ket: SyntaxKind) { while !p.at(EOF) && !p.at(ket) { match p.current() { - T![..] => p.bump(), + T![..] => p.bump_any(), _ => { if !p.at_ts(PATTERN_FIRST) { p.error("expected a pattern"); @@ -281,7 +281,7 @@ fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { fn box_pat(p: &mut Parser) -> CompletedMarker { assert!(p.at(T![box])); let m = p.start(); - p.bump(); + p.bump_any(); pattern(p); m.complete(p, BOX_PAT) } diff --git a/crates/ra_parser/src/grammar/type_args.rs b/crates/ra_parser/src/grammar/type_args.rs index 3db08b280..e100af531 100644 --- a/crates/ra_parser/src/grammar/type_args.rs +++ b/crates/ra_parser/src/grammar/type_args.rs @@ -5,13 +5,13 @@ pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) { match (colon_colon_required, p.nth(0), p.nth(1)) { (_, T![::], T![<]) => { m = p.start(); - p.bump(); - p.bump(); + p.bump_any(); + p.bump_any(); } (false, T![<], T![=]) => return, (false, T![<], _) => { m = p.start(); - p.bump(); + p.bump_any(); } _ => return, }; @@ -32,7 +32,7 @@ fn type_arg(p: &mut Parser) { let m = p.start(); match p.current() { LIFETIME => { - p.bump(); + p.bump_any(); m.complete(p, LIFETIME_ARG); } // test associated_type_bounds @@ -44,7 +44,7 @@ fn type_arg(p: &mut Parser) { } IDENT if p.nth(1) == T![=] => { name_ref(p); - p.bump(); + p.bump_any(); types::type_(p); m.complete(p, ASSOC_TYPE_ARG); } diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs index cf54344c6..31d709d81 100644 --- a/crates/ra_parser/src/grammar/type_params.rs +++ b/crates/ra_parser/src/grammar/type_params.rs @@ -10,7 +10,7 @@ pub(super) fn opt_type_param_list(p: &mut Parser) { fn type_param_list(p: &mut Parser) { assert!(p.at(T![<])); let m = p.start(); - p.bump(); + p.bump_any(); while !p.at(EOF) && !p.at(T![>]) { let m = p.start(); @@ -38,7 +38,7 @@ fn type_param_list(p: &mut Parser) { fn lifetime_param(p: &mut Parser, m: Marker) { assert!(p.at(LIFETIME)); - p.bump(); + p.bump_any(); if p.at(T![:]) { lifetime_bounds(p); } @@ -54,7 +54,7 @@ fn type_param(p: &mut Parser, m: Marker) { // test type_param_default // struct S; if p.at(T![=]) { - p.bump(); + p.bump_any(); types::type_(p) } m.complete(p, TYPE_PARAM); @@ -64,15 +64,15 @@ fn type_param(p: &mut Parser, m: Marker) { // struct S; pub(super) fn bounds(p: &mut Parser) { assert!(p.at(T![:])); - p.bump(); + p.bump_any(); bounds_without_colon(p); } fn lifetime_bounds(p: &mut Parser) { assert!(p.at(T![:])); - p.bump(); + p.bump_any(); while p.at(LIFETIME) { - p.bump(); + p.bump_any(); if !p.eat(T![+]) { break; } @@ -99,7 +99,7 @@ fn type_bound(p: &mut Parser) -> bool { let has_paren = p.eat(T!['(']); p.eat(T![?]); match p.current() { - LIFETIME => p.bump(), + LIFETIME => p.bump_any(), T![for] => types::for_type(p), _ if paths::is_use_path_start(p) => types::path_type_(p, false), _ => { @@ -128,7 +128,7 @@ pub(super) fn opt_where_clause(p: &mut Parser) { return; } let m = p.start(); - p.bump(); + p.bump_any(); while is_where_predicate(p) { where_predicate(p); @@ -166,7 +166,7 @@ fn where_predicate(p: &mut Parser) { let m = p.start(); match p.current() { LIFETIME => { - p.bump(); + p.bump_any(); if p.at(T![:]) { bounds(p); } else { diff --git a/crates/ra_parser/src/grammar/types.rs b/crates/ra_parser/src/grammar/types.rs index 9e321b2a6..0eb28ef09 100644 --- a/crates/ra_parser/src/grammar/types.rs +++ b/crates/ra_parser/src/grammar/types.rs @@ -44,7 +44,7 @@ pub(super) fn ascription(p: &mut Parser) { fn paren_or_tuple_type(p: &mut Parser) { assert!(p.at(T!['('])); let m = p.start(); - p.bump(); + p.bump_any(); let mut n_types: u32 = 0; let mut trailing_comma: bool = false; while !p.at(EOF) && !p.at(T![')']) { @@ -79,20 +79,20 @@ fn paren_or_tuple_type(p: &mut Parser) { fn never_type(p: &mut Parser) { assert!(p.at(T![!])); let m = p.start(); - p.bump(); + p.bump_any(); m.complete(p, NEVER_TYPE); } fn pointer_type(p: &mut Parser) { assert!(p.at(T![*])); let m = p.start(); - p.bump(); + p.bump_any(); match p.current() { // test pointer_type_mut // type M = *mut (); // type C = *mut (); - T![mut] | T![const] => p.bump(), + T![mut] | T![const] => p.bump_any(), _ => { // test_err pointer_type_no_mutability // type T = *(); @@ -110,21 +110,21 @@ fn pointer_type(p: &mut Parser) { fn array_or_slice_type(p: &mut Parser) { assert!(p.at(T!['['])); let m = p.start(); - p.bump(); + p.bump_any(); type_(p); let kind = match p.current() { // test slice_type // type T = [()]; T![']'] => { - p.bump(); + p.bump_any(); SLICE_TYPE } // test array_type // type T = [(); 92]; T![;] => { - p.bump(); + p.bump_any(); expressions::expr(p); p.expect(T![']']); ARRAY_TYPE @@ -146,7 +146,7 @@ fn array_or_slice_type(p: &mut Parser) { fn reference_type(p: &mut Parser) { assert!(p.at(T![&])); let m = p.start(); - p.bump(); + p.bump_any(); p.eat(LIFETIME); p.eat(T![mut]); type_no_bounds(p); @@ -158,7 +158,7 @@ fn reference_type(p: &mut Parser) { fn placeholder_type(p: &mut Parser) { assert!(p.at(T![_])); let m = p.start(); - p.bump(); + p.bump_any(); m.complete(p, PLACEHOLDER_TYPE); } @@ -193,7 +193,7 @@ fn fn_pointer_type(p: &mut Parser) { pub(super) fn for_binder(p: &mut Parser) { assert!(p.at(T![for])); - p.bump(); + p.bump_any(); if p.at(T![<]) { type_params::opt_type_param_list(p); } else { @@ -224,7 +224,7 @@ pub(super) fn for_type(p: &mut Parser) { fn impl_trait_type(p: &mut Parser) { assert!(p.at(T![impl])); let m = p.start(); - p.bump(); + p.bump_any(); type_params::bounds_without_colon(p); m.complete(p, IMPL_TRAIT_TYPE); } @@ -234,7 +234,7 @@ fn impl_trait_type(p: &mut Parser) { fn dyn_trait_type(p: &mut Parser) { assert!(p.at(T![dyn ])); let m = p.start(); - p.bump(); + p.bump_any(); type_params::bounds_without_colon(p); m.complete(p, DYN_TRAIT_TYPE); } diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index 393586561..ccacaacad 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs @@ -148,7 +148,7 @@ impl<'t> Parser<'t> { } /// Advances the parser by one token with composite puncts handled - pub(crate) fn bump(&mut self) { + pub(crate) fn bump_any(&mut self) { let kind = self.nth(0); if kind == EOF { return; @@ -205,7 +205,7 @@ impl<'t> Parser<'t> { if !self.at(kind) { return false; } - self.bump(); + self.bump_any(); true } @@ -231,7 +231,7 @@ impl<'t> Parser<'t> { } else { let m = self.start(); self.error(message); - self.bump(); + self.bump_any(); m.complete(self, ERROR); }; } -- cgit v1.2.3 From d8aa9a1d81529cdc39e8353f2915c3c4d04ac263 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 10 Sep 2019 01:03:00 +0300 Subject: introduce bump as a better-checked alternative to bump_any --- crates/ra_parser/src/grammar.rs | 4 ++-- crates/ra_parser/src/parser.rs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 89f4b63ec..4e6f2f558 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -126,7 +126,7 @@ pub(crate) mod fragments { while !p.at(EOF) { if p.at(T![;]) { - p.bump_any(); + p.bump(T![;]); continue; } @@ -179,7 +179,7 @@ fn opt_visibility(p: &mut Parser) -> bool { match p.current() { T![pub] => { let m = p.start(); - p.bump_any(); + p.bump(T![pub]); if p.at(T!['(']) { match p.nth(1) { // test crate_visibility diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index ccacaacad..d8567e84b 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs @@ -170,6 +170,12 @@ impl<'t> Parser<'t> { } } + /// Advances the parser by one token, asserting that it is exactly the expected token + pub(crate) fn bump(&mut self, expected: SyntaxKind) { + debug_assert!(self.nth(0) == expected); + self.bump_any() + } + /// Advances the parser by one token, remapping its kind. /// This is useful to create contextual keywords from /// identifiers. For example, the lexer creates an `union` -- cgit v1.2.3