mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
Align parser names with grammar
This commit is contained in:
parent
1b0c7701cc
commit
6bc2633c90
17 changed files with 124 additions and 223 deletions
|
@ -142,19 +142,19 @@ pub(crate) fn reparser(
|
|||
) -> Option<fn(&mut Parser)> {
|
||||
let res = match node {
|
||||
BLOCK_EXPR => expressions::block_expr,
|
||||
RECORD_FIELD_LIST => items::record_field_def_list,
|
||||
RECORD_EXPR_FIELD_LIST => items::record_field_list,
|
||||
VARIANT_LIST => items::enum_variant_list,
|
||||
RECORD_FIELD_LIST => items::record_field_list,
|
||||
RECORD_EXPR_FIELD_LIST => items::record_expr_field_list,
|
||||
VARIANT_LIST => items::variant_list,
|
||||
MATCH_ARM_LIST => items::match_arm_list,
|
||||
USE_TREE_LIST => items::use_tree_list,
|
||||
EXTERN_ITEM_LIST => items::extern_item_list,
|
||||
TOKEN_TREE if first_child? == T!['{'] => items::token_tree,
|
||||
ASSOC_ITEM_LIST => match parent? {
|
||||
IMPL => items::impl_item_list,
|
||||
TRAIT => items::trait_item_list,
|
||||
IMPL => items::assoc_item_list,
|
||||
TRAIT => items::assoc_item_list,
|
||||
_ => return None,
|
||||
},
|
||||
ITEM_LIST => items::mod_item_list,
|
||||
ITEM_LIST => items::item_list,
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
|
@ -217,7 +217,7 @@ fn opt_visibility(p: &mut Parser) -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
fn opt_alias(p: &mut Parser) {
|
||||
fn opt_rename(p: &mut Parser) {
|
||||
if p.at(T![as]) {
|
||||
let m = p.start();
|
||||
p.bump(T![as]);
|
||||
|
@ -239,7 +239,7 @@ fn abi(p: &mut Parser) {
|
|||
abi.complete(p, ABI);
|
||||
}
|
||||
|
||||
fn opt_fn_ret_type(p: &mut Parser) -> bool {
|
||||
fn opt_ret_type(p: &mut Parser) -> bool {
|
||||
if p.at(T![->]) {
|
||||
let m = p.start();
|
||||
p.bump(T![->]);
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn inner_attributes(p: &mut Parser) {
|
||||
pub(super) fn inner_attrs(p: &mut Parser) {
|
||||
while p.at(T![#]) && p.nth(1) == T![!] {
|
||||
attribute(p, true)
|
||||
attr(p, true)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn outer_attributes(p: &mut Parser) {
|
||||
pub(super) fn outer_attrs(p: &mut Parser) {
|
||||
while p.at(T![#]) {
|
||||
attribute(p, false)
|
||||
attr(p, false)
|
||||
}
|
||||
}
|
||||
|
||||
fn attribute(p: &mut Parser, inner: bool) {
|
||||
fn attr(p: &mut Parser, inner: bool) {
|
||||
let attr = p.start();
|
||||
assert!(p.at(T![#]));
|
||||
p.bump(T![#]);
|
||||
|
|
|
@ -22,7 +22,7 @@ pub(super) fn expr(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
|
|||
pub(super) fn expr_with_attrs(p: &mut Parser) -> bool {
|
||||
let m = p.start();
|
||||
let has_attrs = p.at(T![#]);
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
|
||||
let (cm, _block_like) = expr(p);
|
||||
let success = cm.is_some();
|
||||
|
@ -64,7 +64,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
|
|||
// #[D] return ();
|
||||
// }
|
||||
let has_attrs = p.at(T![#]);
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
|
||||
if p.at(T![let]) {
|
||||
let_stmt(p, m, with_semi);
|
||||
|
@ -175,7 +175,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
|
|||
|
||||
pub(super) fn expr_block_contents(p: &mut Parser) {
|
||||
// This is checked by a validator
|
||||
attributes::inner_attributes(p);
|
||||
attributes::inner_attrs(p);
|
||||
|
||||
while !p.at(EOF) && !p.at(T!['}']) {
|
||||
// test nocontentexpr
|
||||
|
@ -489,7 +489,7 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
|||
let m = lhs.precede(p);
|
||||
p.bump_any();
|
||||
name_ref(p);
|
||||
type_args::opt_type_arg_list(p, true);
|
||||
type_args::opt_generic_arg_list(p, true);
|
||||
if p.at(T!['(']) {
|
||||
arg_list(p);
|
||||
}
|
||||
|
@ -585,7 +585,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) {
|
|||
paths::expr_path(p);
|
||||
match p.current() {
|
||||
T!['{'] if !r.forbid_structs => {
|
||||
record_field_list(p);
|
||||
record_expr_field_list(p);
|
||||
(m.complete(p, RECORD_EXPR), BlockLike::NotBlock)
|
||||
}
|
||||
T![!] if !p.at(T![!=]) => {
|
||||
|
@ -603,7 +603,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) {
|
|||
// S { x, y: 32, ..Default::default() };
|
||||
// TupleStruct { 0: 1 };
|
||||
// }
|
||||
pub(crate) fn record_field_list(p: &mut Parser) {
|
||||
pub(crate) fn record_expr_field_list(p: &mut Parser) {
|
||||
assert!(p.at(T!['{']));
|
||||
let m = p.start();
|
||||
p.bump(T!['{']);
|
||||
|
@ -613,7 +613,7 @@ pub(crate) fn record_field_list(p: &mut Parser) {
|
|||
// fn main() {
|
||||
// S { #[cfg(test)] field: 1 }
|
||||
// }
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
|
||||
match p.current() {
|
||||
IDENT | INT_NUMBER => {
|
||||
|
|
|
@ -75,9 +75,9 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
|
|||
T!['('] => tuple_expr(p),
|
||||
T!['['] => array_expr(p),
|
||||
L_DOLLAR => meta_var_expr(p),
|
||||
T![|] => lambda_expr(p),
|
||||
T![move] if la == T![|] => lambda_expr(p),
|
||||
T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => lambda_expr(p),
|
||||
T![|] => closure_expr(p),
|
||||
T![move] if la == T![|] => closure_expr(p),
|
||||
T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p),
|
||||
T![if] => if_expr(p),
|
||||
|
||||
T![loop] => loop_expr(p, None),
|
||||
|
@ -228,7 +228,7 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
|
|||
// move || {};
|
||||
// async move || {};
|
||||
// }
|
||||
fn lambda_expr(p: &mut Parser) -> CompletedMarker {
|
||||
fn closure_expr(p: &mut Parser) -> CompletedMarker {
|
||||
assert!(
|
||||
p.at(T![|])
|
||||
|| (p.at(T![move]) && p.nth(1) == T![|])
|
||||
|
@ -239,7 +239,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
|
|||
p.eat(T![async]);
|
||||
p.eat(T![move]);
|
||||
params::param_list_closure(p);
|
||||
if opt_fn_ret_type(p) {
|
||||
if opt_ret_type(p) {
|
||||
// test lambda_ret_block
|
||||
// fn main() { || -> i32 { 92 }(); }
|
||||
block_expr(p);
|
||||
|
@ -265,7 +265,7 @@ fn if_expr(p: &mut Parser) -> CompletedMarker {
|
|||
assert!(p.at(T![if]));
|
||||
let m = p.start();
|
||||
p.bump(T![if]);
|
||||
cond(p);
|
||||
condition(p);
|
||||
block_expr(p);
|
||||
if p.at(T![else]) {
|
||||
p.bump(T![else]);
|
||||
|
@ -314,7 +314,7 @@ fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
|||
assert!(p.at(T![while]));
|
||||
let m = m.unwrap_or_else(|| p.start());
|
||||
p.bump(T![while]);
|
||||
cond(p);
|
||||
condition(p);
|
||||
block_expr(p);
|
||||
m.complete(p, WHILE_EXPR)
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
|||
// while let Some(_) | Some(_) = None {}
|
||||
// while let | Some(_) = None {}
|
||||
// }
|
||||
fn cond(p: &mut Parser) {
|
||||
fn condition(p: &mut Parser) {
|
||||
let m = p.start();
|
||||
if p.eat(T![let]) {
|
||||
patterns::pattern_top(p);
|
||||
|
@ -386,7 +386,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
|
|||
// _ => (),
|
||||
// }
|
||||
// }
|
||||
attributes::inner_attributes(p);
|
||||
attributes::inner_attrs(p);
|
||||
|
||||
while !p.at(EOF) && !p.at(T!['}']) {
|
||||
if p.at(T!['{']) {
|
||||
|
@ -437,7 +437,7 @@ fn match_arm(p: &mut Parser) -> BlockLike {
|
|||
// _ => (),
|
||||
// }
|
||||
// }
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
|
||||
patterns::pattern_top_r(p, TokenSet::EMPTY);
|
||||
if p.at(T![if]) {
|
||||
|
|
|
@ -6,9 +6,9 @@ mod traits;
|
|||
mod use_item;
|
||||
|
||||
pub(crate) use self::{
|
||||
adt::{enum_variant_list, record_field_def_list},
|
||||
expressions::{match_arm_list, record_field_list},
|
||||
traits::{impl_item_list, trait_item_list},
|
||||
adt::{record_field_list, variant_list},
|
||||
expressions::{match_arm_list, record_expr_field_list},
|
||||
traits::assoc_item_list,
|
||||
use_item::use_tree_list,
|
||||
};
|
||||
use super::*;
|
||||
|
@ -20,7 +20,7 @@ use super::*;
|
|||
// super::baz! {}
|
||||
// struct S;
|
||||
pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
|
||||
attributes::inner_attributes(p);
|
||||
attributes::inner_attrs(p);
|
||||
while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) {
|
||||
item_or_macro(p, stop_on_r_curly)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![
|
|||
|
||||
pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) {
|
||||
let m = p.start();
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
let m = match maybe_item(p, m) {
|
||||
Ok(()) => {
|
||||
if p.at(T![;]) {
|
||||
|
@ -144,30 +144,30 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
|
|||
// test fn
|
||||
// fn foo() {}
|
||||
T![fn] => {
|
||||
fn_def(p);
|
||||
fn_(p);
|
||||
m.complete(p, FN);
|
||||
}
|
||||
|
||||
// test trait
|
||||
// trait T {}
|
||||
T![trait] => {
|
||||
traits::trait_def(p);
|
||||
traits::trait_(p);
|
||||
m.complete(p, TRAIT);
|
||||
}
|
||||
|
||||
T![const] => {
|
||||
consts::const_def(p, m);
|
||||
consts::konst(p, m);
|
||||
}
|
||||
|
||||
// test impl
|
||||
// impl T for S {}
|
||||
T![impl] => {
|
||||
traits::impl_def(p);
|
||||
traits::impl_(p);
|
||||
m.complete(p, IMPL);
|
||||
}
|
||||
|
||||
T![type] => {
|
||||
type_def(p, m);
|
||||
type_alias(p, m);
|
||||
}
|
||||
_ => {
|
||||
if !has_visibility && !has_mods {
|
||||
|
@ -190,9 +190,9 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
|
|||
match p.current() {
|
||||
// test extern_crate
|
||||
// extern crate foo;
|
||||
T![extern] if la == T![crate] => extern_crate_item(p, m),
|
||||
T![extern] if la == T![crate] => extern_crate(p, m),
|
||||
T![type] => {
|
||||
type_def(p, m);
|
||||
type_alias(p, m);
|
||||
}
|
||||
T![mod] => mod_item(p, m),
|
||||
T![struct] => {
|
||||
|
@ -205,7 +205,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
|
|||
// a: i32,
|
||||
// b: f32,
|
||||
// }
|
||||
adt::struct_def(p, m);
|
||||
adt::strukt(p, m);
|
||||
}
|
||||
// test pub_macro_def
|
||||
// pub macro m($:ident) {}
|
||||
|
@ -219,12 +219,12 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
|
|||
// a: i32,
|
||||
// b: f32,
|
||||
// }
|
||||
adt::union_def(p, m);
|
||||
adt::union(p, m);
|
||||
}
|
||||
T![enum] => adt::enum_def(p, m),
|
||||
T![use] => use_item::use_item(p, m),
|
||||
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::const_def(p, m),
|
||||
T![static] => consts::static_def(p, m),
|
||||
T![enum] => adt::enum_(p, m),
|
||||
T![use] => use_item::use_(p, m),
|
||||
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m),
|
||||
T![static] => consts::static_(p, m),
|
||||
// test extern_block
|
||||
// extern {}
|
||||
T![extern]
|
||||
|
@ -239,7 +239,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn extern_crate_item(p: &mut Parser, m: Marker) {
|
||||
fn extern_crate(p: &mut Parser, m: Marker) {
|
||||
assert!(p.at(T![extern]));
|
||||
p.bump(T![extern]);
|
||||
assert!(p.at(T![crate]));
|
||||
|
@ -251,7 +251,7 @@ fn extern_crate_item(p: &mut Parser, m: Marker) {
|
|||
name_ref(p);
|
||||
}
|
||||
|
||||
opt_alias(p);
|
||||
opt_rename(p);
|
||||
p.expect(T![;]);
|
||||
m.complete(p, EXTERN_CRATE);
|
||||
}
|
||||
|
@ -265,14 +265,14 @@ pub(crate) fn extern_item_list(p: &mut Parser) {
|
|||
m.complete(p, EXTERN_ITEM_LIST);
|
||||
}
|
||||
|
||||
fn fn_def(p: &mut Parser) {
|
||||
fn fn_(p: &mut Parser) {
|
||||
assert!(p.at(T![fn]));
|
||||
p.bump(T![fn]);
|
||||
|
||||
name_r(p, ITEM_RECOVERY_SET);
|
||||
// test function_type_params
|
||||
// fn foo<T: Clone + Copy>(){}
|
||||
type_params::opt_type_param_list(p);
|
||||
type_params::opt_generic_param_list(p);
|
||||
|
||||
if p.at(T!['(']) {
|
||||
params::param_list_fn_def(p);
|
||||
|
@ -282,7 +282,7 @@ fn fn_def(p: &mut Parser) {
|
|||
// test function_ret_type
|
||||
// fn foo() {}
|
||||
// fn bar() -> () {}
|
||||
opt_fn_ret_type(p);
|
||||
opt_ret_type(p);
|
||||
|
||||
// test function_where_clause
|
||||
// fn foo<T>() where T: Copy {}
|
||||
|
@ -299,7 +299,7 @@ fn fn_def(p: &mut Parser) {
|
|||
|
||||
// test type_item
|
||||
// type Foo = Bar;
|
||||
fn type_def(p: &mut Parser, m: Marker) {
|
||||
fn type_alias(p: &mut Parser, m: Marker) {
|
||||
assert!(p.at(T![type]));
|
||||
p.bump(T![type]);
|
||||
|
||||
|
@ -307,7 +307,7 @@ fn type_def(p: &mut Parser, m: Marker) {
|
|||
|
||||
// test type_item_type_params
|
||||
// type Result<T> = ();
|
||||
type_params::opt_type_param_list(p);
|
||||
type_params::opt_generic_param_list(p);
|
||||
|
||||
if p.at(T![:]) {
|
||||
type_params::bounds(p);
|
||||
|
@ -329,14 +329,14 @@ pub(crate) fn mod_item(p: &mut Parser, m: Marker) {
|
|||
|
||||
name(p);
|
||||
if p.at(T!['{']) {
|
||||
mod_item_list(p);
|
||||
item_list(p);
|
||||
} else if !p.eat(T![;]) {
|
||||
p.error("expected `;` or `{`");
|
||||
}
|
||||
m.complete(p, MODULE);
|
||||
}
|
||||
|
||||
pub(crate) fn mod_item_list(p: &mut Parser) {
|
||||
pub(crate) fn item_list(p: &mut Parser) {
|
||||
assert!(p.at(T!['{']));
|
||||
let m = p.start();
|
||||
p.bump(T!['{']);
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn struct_def(p: &mut Parser, m: Marker) {
|
||||
pub(super) fn strukt(p: &mut Parser, m: Marker) {
|
||||
assert!(p.at(T![struct]));
|
||||
p.bump(T![struct]);
|
||||
struct_or_union(p, m, T![struct], STRUCT);
|
||||
}
|
||||
|
||||
pub(super) fn union_def(p: &mut Parser, m: Marker) {
|
||||
pub(super) fn union(p: &mut Parser, m: Marker) {
|
||||
assert!(p.at_contextual_kw("union"));
|
||||
p.bump_remap(T![union]);
|
||||
struct_or_union(p, m, T![union], UNION);
|
||||
|
@ -16,7 +16,7 @@ pub(super) fn union_def(p: &mut Parser, m: Marker) {
|
|||
|
||||
fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
|
||||
name_r(p, ITEM_RECOVERY_SET);
|
||||
type_params::opt_type_param_list(p);
|
||||
type_params::opt_generic_param_list(p);
|
||||
match p.current() {
|
||||
T![where] => {
|
||||
type_params::opt_where_clause(p);
|
||||
|
@ -24,7 +24,7 @@ fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
|
|||
T![;] => {
|
||||
p.bump(T![;]);
|
||||
}
|
||||
T!['{'] => record_field_def_list(p),
|
||||
T!['{'] => record_field_list(p),
|
||||
_ => {
|
||||
//FIXME: special case `(` error message
|
||||
p.error("expected `;` or `{`");
|
||||
|
@ -34,9 +34,9 @@ fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
|
|||
T![;] if kw == T![struct] => {
|
||||
p.bump(T![;]);
|
||||
}
|
||||
T!['{'] => record_field_def_list(p),
|
||||
T!['{'] => record_field_list(p),
|
||||
T!['('] if kw == T![struct] => {
|
||||
tuple_field_def_list(p);
|
||||
tuple_field_list(p);
|
||||
// test tuple_struct_where
|
||||
// struct Test<T>(T) where T: Clone;
|
||||
// struct Test<T>(T);
|
||||
|
@ -53,21 +53,21 @@ fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
|
|||
m.complete(p, def);
|
||||
}
|
||||
|
||||
pub(super) fn enum_def(p: &mut Parser, m: Marker) {
|
||||
pub(super) fn enum_(p: &mut Parser, m: Marker) {
|
||||
assert!(p.at(T![enum]));
|
||||
p.bump(T![enum]);
|
||||
name_r(p, ITEM_RECOVERY_SET);
|
||||
type_params::opt_type_param_list(p);
|
||||
type_params::opt_generic_param_list(p);
|
||||
type_params::opt_where_clause(p);
|
||||
if p.at(T!['{']) {
|
||||
enum_variant_list(p);
|
||||
variant_list(p);
|
||||
} else {
|
||||
p.error("expected `{`")
|
||||
}
|
||||
m.complete(p, ENUM);
|
||||
}
|
||||
|
||||
pub(crate) fn enum_variant_list(p: &mut Parser) {
|
||||
pub(crate) fn variant_list(p: &mut Parser) {
|
||||
assert!(p.at(T!['{']));
|
||||
let m = p.start();
|
||||
p.bump(T!['{']);
|
||||
|
@ -77,12 +77,12 @@ pub(crate) fn enum_variant_list(p: &mut Parser) {
|
|||
continue;
|
||||
}
|
||||
let var = p.start();
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
if p.at(IDENT) {
|
||||
name(p);
|
||||
match p.current() {
|
||||
T!['{'] => record_field_def_list(p),
|
||||
T!['('] => tuple_field_def_list(p),
|
||||
T!['{'] => record_field_list(p),
|
||||
T!['('] => tuple_field_list(p),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ pub(crate) fn enum_variant_list(p: &mut Parser) {
|
|||
m.complete(p, VARIANT_LIST);
|
||||
}
|
||||
|
||||
pub(crate) fn record_field_def_list(p: &mut Parser) {
|
||||
pub(crate) fn record_field_list(p: &mut Parser) {
|
||||
assert!(p.at(T!['{']));
|
||||
let m = p.start();
|
||||
p.bump(T!['{']);
|
||||
|
@ -128,7 +128,7 @@ pub(crate) fn record_field_def_list(p: &mut Parser) {
|
|||
// #[serde(with = "url_serde")]
|
||||
// pub uri: Uri,
|
||||
// }
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
opt_visibility(p);
|
||||
if p.at(IDENT) {
|
||||
name(p);
|
||||
|
@ -142,7 +142,7 @@ pub(crate) fn record_field_def_list(p: &mut Parser) {
|
|||
}
|
||||
}
|
||||
|
||||
fn tuple_field_def_list(p: &mut Parser) {
|
||||
fn tuple_field_list(p: &mut Parser) {
|
||||
assert!(p.at(T!['(']));
|
||||
let m = p.start();
|
||||
if !p.expect(T!['(']) {
|
||||
|
@ -159,7 +159,7 @@ fn tuple_field_def_list(p: &mut Parser) {
|
|||
// enum S {
|
||||
// Uri(#[serde(with = "url_serde")] Uri),
|
||||
// }
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
opt_visibility(p);
|
||||
if !p.at_ts(types::TYPE_FIRST) {
|
||||
p.error("expected a type");
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn static_def(p: &mut Parser, m: Marker) {
|
||||
pub(super) fn static_(p: &mut Parser, m: Marker) {
|
||||
const_or_static(p, m, T![static], STATIC)
|
||||
}
|
||||
|
||||
pub(super) fn const_def(p: &mut Parser, m: Marker) {
|
||||
pub(super) fn konst(p: &mut Parser, m: Marker) {
|
||||
const_or_static(p, m, T![const], CONST)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@ use super::*;
|
|||
// test trait_item
|
||||
// trait T<U>: Hash + Clone where U: Copy {}
|
||||
// trait X<U: Debug + Display>: Hash + Clone where U: Copy {}
|
||||
pub(super) fn trait_def(p: &mut Parser) {
|
||||
pub(super) fn trait_(p: &mut Parser) {
|
||||
assert!(p.at(T![trait]));
|
||||
p.bump(T![trait]);
|
||||
name_r(p, ITEM_RECOVERY_SET);
|
||||
type_params::opt_type_param_list(p);
|
||||
type_params::opt_generic_param_list(p);
|
||||
// test trait_alias
|
||||
// trait Z<U> = T<U>;
|
||||
// trait Z<U> = T<U> where U: Copy;
|
||||
|
@ -25,41 +25,19 @@ pub(super) fn trait_def(p: &mut Parser) {
|
|||
}
|
||||
type_params::opt_where_clause(p);
|
||||
if p.at(T!['{']) {
|
||||
trait_item_list(p);
|
||||
assoc_item_list(p);
|
||||
} else {
|
||||
p.error("expected `{`");
|
||||
}
|
||||
}
|
||||
|
||||
// test trait_item_list
|
||||
// impl F {
|
||||
// type A: Clone;
|
||||
// const B: i32;
|
||||
// fn foo() {}
|
||||
// fn bar(&self);
|
||||
// }
|
||||
pub(crate) fn trait_item_list(p: &mut Parser) {
|
||||
assert!(p.at(T!['{']));
|
||||
let m = p.start();
|
||||
p.bump(T!['{']);
|
||||
while !p.at(EOF) && !p.at(T!['}']) {
|
||||
if p.at(T!['{']) {
|
||||
error_block(p, "expected an item");
|
||||
continue;
|
||||
}
|
||||
item_or_macro(p, true);
|
||||
}
|
||||
p.expect(T!['}']);
|
||||
m.complete(p, ASSOC_ITEM_LIST);
|
||||
}
|
||||
|
||||
// test impl_def
|
||||
// impl Foo {}
|
||||
pub(super) fn impl_def(p: &mut Parser) {
|
||||
pub(super) fn impl_(p: &mut Parser) {
|
||||
assert!(p.at(T![impl]));
|
||||
p.bump(T![impl]);
|
||||
if choose_type_params_over_qpath(p) {
|
||||
type_params::opt_type_param_list(p);
|
||||
type_params::opt_generic_param_list(p);
|
||||
}
|
||||
|
||||
// FIXME: never type
|
||||
|
@ -74,7 +52,7 @@ pub(super) fn impl_def(p: &mut Parser) {
|
|||
}
|
||||
type_params::opt_where_clause(p);
|
||||
if p.at(T!['{']) {
|
||||
impl_item_list(p);
|
||||
assoc_item_list(p);
|
||||
} else {
|
||||
p.error("expected `{`");
|
||||
}
|
||||
|
@ -87,7 +65,7 @@ pub(super) fn impl_def(p: &mut Parser) {
|
|||
// fn foo() {}
|
||||
// fn bar(&self) {}
|
||||
// }
|
||||
pub(crate) fn impl_item_list(p: &mut Parser) {
|
||||
pub(crate) fn assoc_item_list(p: &mut Parser) {
|
||||
assert!(p.at(T!['{']));
|
||||
let m = p.start();
|
||||
p.bump(T!['{']);
|
||||
|
@ -97,7 +75,7 @@ pub(crate) fn impl_item_list(p: &mut Parser) {
|
|||
// //! This is a doc comment
|
||||
// #![doc("This is also a doc comment")]
|
||||
// }
|
||||
attributes::inner_attributes(p);
|
||||
attributes::inner_attrs(p);
|
||||
|
||||
while !p.at(EOF) && !p.at(T!['}']) {
|
||||
if p.at(T!['{']) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn use_item(p: &mut Parser, m: Marker) {
|
||||
pub(super) fn use_(p: &mut Parser, m: Marker) {
|
||||
assert!(p.at(T![use]));
|
||||
p.bump(T![use]);
|
||||
use_tree(p, true);
|
||||
|
@ -80,7 +80,7 @@ fn use_tree(p: &mut Parser, top_level: bool) {
|
|||
// running::out::of::synonyms::for_::different::*
|
||||
// };
|
||||
// use Trait as _;
|
||||
opt_alias(p);
|
||||
opt_rename(p);
|
||||
}
|
||||
T![:] if p.at(T![::]) => {
|
||||
p.bump(T![::]);
|
||||
|
|
|
@ -47,20 +47,20 @@ fn list_(p: &mut Parser, flavor: Flavor) {
|
|||
if let FnDef = flavor {
|
||||
// test self_param_outer_attr
|
||||
// fn f(#[must_use] self) {}
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
opt_self_param(p);
|
||||
}
|
||||
|
||||
while !p.at(EOF) && !p.at(ket) {
|
||||
// test param_outer_arg
|
||||
// fn f(#[attr1] pat: Type) {}
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
|
||||
if !p.at_ts(VALUE_PARAMETER_FIRST) {
|
||||
if !p.at_ts(PARAM_FIRST) {
|
||||
p.error("expected value parameter");
|
||||
break;
|
||||
}
|
||||
let param = value_parameter(p, flavor);
|
||||
let param = param(p, flavor);
|
||||
if !p.at(ket) {
|
||||
p.expect(T![,]);
|
||||
}
|
||||
|
@ -73,11 +73,11 @@ fn list_(p: &mut Parser, flavor: Flavor) {
|
|||
m.complete(p, PARAM_LIST);
|
||||
}
|
||||
|
||||
const VALUE_PARAMETER_FIRST: TokenSet = patterns::PATTERN_FIRST.union(types::TYPE_FIRST);
|
||||
const PARAM_FIRST: TokenSet = patterns::PATTERN_FIRST.union(types::TYPE_FIRST);
|
||||
|
||||
struct Variadic(bool);
|
||||
|
||||
fn value_parameter(p: &mut Parser, flavor: Flavor) -> Variadic {
|
||||
fn param(p: &mut Parser, flavor: Flavor) -> Variadic {
|
||||
let mut res = Variadic(false);
|
||||
let m = p.start();
|
||||
match flavor {
|
||||
|
|
|
@ -105,11 +105,11 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) {
|
|||
// type F = Box<Fn(i32) -> ()>;
|
||||
if p.at(T!['(']) {
|
||||
params::param_list_fn_trait(p);
|
||||
opt_fn_ret_type(p);
|
||||
opt_ret_type(p);
|
||||
} else {
|
||||
type_args::opt_type_arg_list(p, false)
|
||||
type_args::opt_generic_arg_list(p, false)
|
||||
}
|
||||
}
|
||||
Mode::Expr => type_args::opt_type_arg_list(p, true),
|
||||
Mode::Expr => type_args::opt_generic_arg_list(p, true),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,13 +79,13 @@ const PAT_RECOVERY_SET: TokenSet =
|
|||
fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
|
||||
let m = match p.nth(0) {
|
||||
T![box] => box_pat(p),
|
||||
T![ref] | T![mut] => bind_pat(p, true),
|
||||
T![ref] | T![mut] => ident_pat(p, true),
|
||||
IDENT => match p.nth(1) {
|
||||
// Checks the token after an IDENT to see if a pattern is a path (Struct { .. }) or macro
|
||||
// (T![x]).
|
||||
T!['('] | T!['{'] | T![!] => path_or_macro_pat(p),
|
||||
T![:] if p.nth_at(1, T![::]) => path_or_macro_pat(p),
|
||||
_ => bind_pat(p, true),
|
||||
_ => ident_pat(p, true),
|
||||
},
|
||||
|
||||
// test type_path_in_pattern
|
||||
|
@ -93,8 +93,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
|
|||
_ if paths::is_path_start(p) => path_or_macro_pat(p),
|
||||
_ if is_literal_pat_start(p) => literal_pat(p),
|
||||
|
||||
T![.] if p.at(T![..]) => dot_dot_pat(p),
|
||||
T![_] => placeholder_pat(p),
|
||||
T![.] if p.at(T![..]) => rest_pat(p),
|
||||
T![_] => wildcard_pat(p),
|
||||
T![&] => ref_pat(p),
|
||||
T!['('] => tuple_pat(p),
|
||||
T!['['] => slice_pat(p),
|
||||
|
@ -149,7 +149,7 @@ fn path_or_macro_pat(p: &mut Parser) -> CompletedMarker {
|
|||
TUPLE_STRUCT_PAT
|
||||
}
|
||||
T!['{'] => {
|
||||
record_field_pat_list(p);
|
||||
record_pat_field_list(p);
|
||||
RECORD_PAT
|
||||
}
|
||||
// test marco_pat
|
||||
|
@ -186,7 +186,7 @@ fn tuple_pat_fields(p: &mut Parser) {
|
|||
// let S { h: _, ..} = ();
|
||||
// let S { h: _, } = ();
|
||||
// }
|
||||
fn record_field_pat_list(p: &mut Parser) {
|
||||
fn record_pat_field_list(p: &mut Parser) {
|
||||
assert!(p.at(T!['{']));
|
||||
let m = p.start();
|
||||
p.bump(T!['{']);
|
||||
|
@ -214,7 +214,7 @@ fn record_field_pat_list(p: &mut Parser) {
|
|||
box_pat(p);
|
||||
}
|
||||
_ => {
|
||||
bind_pat(p, false);
|
||||
ident_pat(p, false);
|
||||
}
|
||||
}
|
||||
m.complete(p, RECORD_PAT_FIELD);
|
||||
|
@ -230,7 +230,7 @@ fn record_field_pat_list(p: &mut Parser) {
|
|||
|
||||
// test placeholder_pat
|
||||
// fn main() { let _ = (); }
|
||||
fn placeholder_pat(p: &mut Parser) -> CompletedMarker {
|
||||
fn wildcard_pat(p: &mut Parser) -> CompletedMarker {
|
||||
assert!(p.at(T![_]));
|
||||
let m = p.start();
|
||||
p.bump(T![_]);
|
||||
|
@ -263,7 +263,7 @@ fn placeholder_pat(p: &mut Parser) -> CompletedMarker {
|
|||
// let [head, .., mid, tail @ ..] = ();
|
||||
// let [head, .., mid, .., cons] = ();
|
||||
// }
|
||||
fn dot_dot_pat(p: &mut Parser) -> CompletedMarker {
|
||||
fn rest_pat(p: &mut Parser) -> CompletedMarker {
|
||||
assert!(p.at(T![..]));
|
||||
let m = p.start();
|
||||
p.bump(T![..]);
|
||||
|
@ -353,7 +353,7 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) {
|
|||
// let e @ _ = ();
|
||||
// let ref mut f @ g @ _ = ();
|
||||
// }
|
||||
fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker {
|
||||
fn ident_pat(p: &mut Parser, with_at: bool) -> CompletedMarker {
|
||||
let m = p.start();
|
||||
p.eat(T![ref]);
|
||||
p.eat(T![mut]);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) {
|
||||
pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) {
|
||||
let m;
|
||||
if p.at(T![::]) && p.nth(2) == T![<] {
|
||||
m = p.start();
|
||||
|
@ -16,7 +16,7 @@ pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) {
|
|||
}
|
||||
|
||||
while !p.at(EOF) && !p.at(T![>]) {
|
||||
type_arg(p);
|
||||
generic_arg(p);
|
||||
if !p.at(T![>]) && !p.expect(T![,]) {
|
||||
break;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) {
|
|||
|
||||
// test type_arg
|
||||
// type A = B<'static, i32, 1, { 2 }, Item=u64>;
|
||||
fn type_arg(p: &mut Parser) {
|
||||
fn generic_arg(p: &mut Parser) {
|
||||
let m = p.start();
|
||||
match p.current() {
|
||||
LIFETIME => {
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn opt_type_param_list(p: &mut Parser) {
|
||||
pub(super) fn opt_generic_param_list(p: &mut Parser) {
|
||||
if !p.at(T![<]) {
|
||||
return;
|
||||
}
|
||||
type_param_list(p);
|
||||
generic_param_list(p);
|
||||
}
|
||||
|
||||
fn type_param_list(p: &mut Parser) {
|
||||
fn generic_param_list(p: &mut Parser) {
|
||||
assert!(p.at(T![<]));
|
||||
let m = p.start();
|
||||
p.bump(T![<]);
|
||||
|
@ -20,12 +20,12 @@ fn type_param_list(p: &mut Parser) {
|
|||
// test generic_lifetime_type_attribute
|
||||
// fn foo<#[derive(Lifetime)] 'a, #[derive(Type)] T>(_: &'a T) {
|
||||
// }
|
||||
attributes::outer_attributes(p);
|
||||
attributes::outer_attrs(p);
|
||||
|
||||
match p.current() {
|
||||
LIFETIME => lifetime_param(p, m),
|
||||
IDENT => type_param(p, m),
|
||||
CONST_KW => type_const_param(p, m),
|
||||
CONST_KW => const_param(p, m),
|
||||
_ => {
|
||||
m.abandon(p);
|
||||
p.err_and_bump("expected type parameter")
|
||||
|
@ -65,7 +65,7 @@ fn type_param(p: &mut Parser, m: Marker) {
|
|||
|
||||
// test const_param
|
||||
// struct S<const N: u32>;
|
||||
fn type_const_param(p: &mut Parser, m: Marker) {
|
||||
fn const_param(p: &mut Parser, m: Marker) {
|
||||
assert!(p.at(CONST_KW));
|
||||
p.bump(T![const]);
|
||||
name(p);
|
||||
|
|
|
@ -32,11 +32,11 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
|
|||
match p.current() {
|
||||
T!['('] => paren_or_tuple_type(p),
|
||||
T![!] => never_type(p),
|
||||
T![*] => pointer_type(p),
|
||||
T![*] => ptr_type(p),
|
||||
T!['['] => array_or_slice_type(p),
|
||||
T![&] => reference_type(p),
|
||||
T![_] => placeholder_type(p),
|
||||
T![fn] | T![unsafe] | T![extern] => fn_pointer_type(p),
|
||||
T![&] => ref_type(p),
|
||||
T![_] => infer_type(p),
|
||||
T![fn] | T![unsafe] | T![extern] => fn_ptr_type(p),
|
||||
T![for] => for_type(p),
|
||||
T![impl] => impl_trait_type(p),
|
||||
T![dyn] => dyn_trait_type(p),
|
||||
|
@ -96,7 +96,7 @@ fn never_type(p: &mut Parser) {
|
|||
m.complete(p, NEVER_TYPE);
|
||||
}
|
||||
|
||||
fn pointer_type(p: &mut Parser) {
|
||||
fn ptr_type(p: &mut Parser) {
|
||||
assert!(p.at(T![*]));
|
||||
let m = p.start();
|
||||
p.bump(T![*]);
|
||||
|
@ -156,7 +156,7 @@ fn array_or_slice_type(p: &mut Parser) {
|
|||
// type A = &();
|
||||
// type B = &'static ();
|
||||
// type C = &mut ();
|
||||
fn reference_type(p: &mut Parser) {
|
||||
fn ref_type(p: &mut Parser) {
|
||||
assert!(p.at(T![&]));
|
||||
let m = p.start();
|
||||
p.bump(T![&]);
|
||||
|
@ -168,7 +168,7 @@ fn reference_type(p: &mut Parser) {
|
|||
|
||||
// test placeholder_type
|
||||
// type Placeholder = _;
|
||||
fn placeholder_type(p: &mut Parser) {
|
||||
fn infer_type(p: &mut Parser) {
|
||||
assert!(p.at(T![_]));
|
||||
let m = p.start();
|
||||
p.bump(T![_]);
|
||||
|
@ -180,7 +180,7 @@ fn placeholder_type(p: &mut Parser) {
|
|||
// type B = unsafe fn();
|
||||
// type C = unsafe extern "C" fn();
|
||||
// type D = extern "C" fn ( u8 , ... ) -> u8;
|
||||
fn fn_pointer_type(p: &mut Parser) {
|
||||
fn fn_ptr_type(p: &mut Parser) {
|
||||
let m = p.start();
|
||||
p.eat(T![unsafe]);
|
||||
if p.at(T![extern]) {
|
||||
|
@ -200,7 +200,7 @@ fn fn_pointer_type(p: &mut Parser) {
|
|||
}
|
||||
// test fn_pointer_type_with_ret
|
||||
// type F = fn() -> ();
|
||||
opt_fn_ret_type(p);
|
||||
opt_ret_type(p);
|
||||
m.complete(p, FN_PTR_TYPE);
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ pub(super) fn for_binder(p: &mut Parser) {
|
|||
assert!(p.at(T![for]));
|
||||
p.bump(T![for]);
|
||||
if p.at(T![<]) {
|
||||
type_params::opt_type_param_list(p);
|
||||
type_params::opt_generic_param_list(p);
|
||||
} else {
|
||||
p.error("expected `<`");
|
||||
}
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
SOURCE_FILE@0..83
|
||||
IMPL@0..82
|
||||
IMPL_KW@0..4 "impl"
|
||||
WHITESPACE@4..5 " "
|
||||
PATH_TYPE@5..6
|
||||
PATH@5..6
|
||||
PATH_SEGMENT@5..6
|
||||
NAME_REF@5..6
|
||||
IDENT@5..6 "F"
|
||||
WHITESPACE@6..7 " "
|
||||
ASSOC_ITEM_LIST@7..82
|
||||
L_CURLY@7..8 "{"
|
||||
WHITESPACE@8..13 "\n "
|
||||
TYPE_ALIAS@13..27
|
||||
TYPE_KW@13..17 "type"
|
||||
WHITESPACE@17..18 " "
|
||||
NAME@18..19
|
||||
IDENT@18..19 "A"
|
||||
COLON@19..20 ":"
|
||||
WHITESPACE@20..21 " "
|
||||
TYPE_BOUND_LIST@21..26
|
||||
TYPE_BOUND@21..26
|
||||
PATH_TYPE@21..26
|
||||
PATH@21..26
|
||||
PATH_SEGMENT@21..26
|
||||
NAME_REF@21..26
|
||||
IDENT@21..26 "Clone"
|
||||
SEMICOLON@26..27 ";"
|
||||
WHITESPACE@27..32 "\n "
|
||||
CONST@32..45
|
||||
CONST_KW@32..37 "const"
|
||||
WHITESPACE@37..38 " "
|
||||
NAME@38..39
|
||||
IDENT@38..39 "B"
|
||||
COLON@39..40 ":"
|
||||
WHITESPACE@40..41 " "
|
||||
PATH_TYPE@41..44
|
||||
PATH@41..44
|
||||
PATH_SEGMENT@41..44
|
||||
NAME_REF@41..44
|
||||
IDENT@41..44 "i32"
|
||||
SEMICOLON@44..45 ";"
|
||||
WHITESPACE@45..50 "\n "
|
||||
FN@50..61
|
||||
FN_KW@50..52 "fn"
|
||||
WHITESPACE@52..53 " "
|
||||
NAME@53..56
|
||||
IDENT@53..56 "foo"
|
||||
PARAM_LIST@56..58
|
||||
L_PAREN@56..57 "("
|
||||
R_PAREN@57..58 ")"
|
||||
WHITESPACE@58..59 " "
|
||||
BLOCK_EXPR@59..61
|
||||
L_CURLY@59..60 "{"
|
||||
R_CURLY@60..61 "}"
|
||||
WHITESPACE@61..66 "\n "
|
||||
FN@66..80
|
||||
FN_KW@66..68 "fn"
|
||||
WHITESPACE@68..69 " "
|
||||
NAME@69..72
|
||||
IDENT@69..72 "bar"
|
||||
PARAM_LIST@72..79
|
||||
L_PAREN@72..73 "("
|
||||
SELF_PARAM@73..78
|
||||
AMP@73..74 "&"
|
||||
SELF_KW@74..78 "self"
|
||||
R_PAREN@78..79 ")"
|
||||
SEMICOLON@79..80 ";"
|
||||
WHITESPACE@80..81 "\n"
|
||||
R_CURLY@81..82 "}"
|
||||
WHITESPACE@82..83 "\n"
|
|
@ -1,6 +0,0 @@
|
|||
impl F {
|
||||
type A: Clone;
|
||||
const B: i32;
|
||||
fn foo() {}
|
||||
fn bar(&self);
|
||||
}
|
Loading…
Reference in a new issue