2018-02-03 12:05:25 +03:00
|
|
|
mod consts;
|
2018-09-08 10:55:09 +03:00
|
|
|
mod nominal;
|
2018-02-04 13:39:24 +03:00
|
|
|
mod traits;
|
2018-07-30 14:08:06 +03:00
|
|
|
mod use_item;
|
2018-01-28 17:46:30 +03:00
|
|
|
|
2018-09-10 20:14:09 +02:00
|
|
|
pub(crate) use self::{
|
2018-10-15 17:44:23 -04:00
|
|
|
expressions::{match_arm_list, named_field_list},
|
2018-09-10 20:14:09 +02:00
|
|
|
nominal::{enum_variant_list, named_field_def_list},
|
2018-10-15 17:44:23 -04:00
|
|
|
traits::{impl_item_list, trait_item_list},
|
2018-09-10 20:14:09 +02:00
|
|
|
use_item::use_tree_list,
|
|
|
|
};
|
2018-10-15 17:44:23 -04:00
|
|
|
use super::*;
|
2018-08-25 13:17:54 +03:00
|
|
|
|
2018-08-05 14:08:46 +03:00
|
|
|
// test mod_contents
|
|
|
|
// fn foo() {}
|
|
|
|
// macro_rules! foo {}
|
|
|
|
// foo::bar!();
|
|
|
|
// super::baz! {}
|
|
|
|
// struct S;
|
2018-01-28 12:57:03 +03:00
|
|
|
pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
|
2018-01-09 22:35:55 +03:00
|
|
|
attributes::inner_attributes(p);
|
2019-05-15 15:35:47 +03:00
|
|
|
while !p.at(EOF) && !(stop_on_r_curly && p.at(T!['}'])) {
|
2018-08-13 18:40:47 +03:00
|
|
|
item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod)
|
2018-08-04 13:17:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 18:40:47 +03:00
|
|
|
pub(super) enum ItemFlavor {
|
2018-10-15 17:44:23 -04:00
|
|
|
Mod,
|
|
|
|
Trait,
|
2018-08-13 18:40:47 +03:00
|
|
|
}
|
|
|
|
|
2018-11-21 18:34:20 +03:00
|
|
|
pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![
|
2018-10-15 17:44:23 -04:00
|
|
|
FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW,
|
|
|
|
CRATE_KW
|
|
|
|
];
|
2018-08-31 13:35:48 +03:00
|
|
|
|
2018-08-13 18:40:47 +03:00
|
|
|
pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) {
|
2019-03-18 13:03:04 +09:00
|
|
|
let m = p.start();
|
2019-01-26 22:02:23 +00:00
|
|
|
attributes::outer_attributes(p);
|
2019-03-18 13:03:04 +09:00
|
|
|
let m = match maybe_item(p, m, flavor) {
|
|
|
|
Ok(()) => return,
|
|
|
|
Err(m) => m,
|
2019-03-17 22:04:25 +09:00
|
|
|
};
|
|
|
|
if paths::is_path_start(p) {
|
|
|
|
match macro_call(p) {
|
|
|
|
BlockLike::Block => (),
|
|
|
|
BlockLike::NotBlock => {
|
2019-05-15 15:35:47 +03:00
|
|
|
p.expect(T![;]);
|
2018-08-04 13:17:24 +03:00
|
|
|
}
|
|
|
|
}
|
2019-03-17 22:04:25 +09:00
|
|
|
m.complete(p, MACRO_CALL);
|
|
|
|
} else {
|
|
|
|
m.abandon(p);
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(T!['{']) {
|
2019-03-17 22:04:25 +09:00
|
|
|
error_block(p, "expected an item");
|
2019-05-15 15:35:47 +03:00
|
|
|
} else if p.at(T!['}']) && !stop_on_r_curly {
|
2019-03-17 22:04:25 +09:00
|
|
|
let e = p.start();
|
|
|
|
p.error("unmatched `}`");
|
|
|
|
p.bump();
|
|
|
|
e.complete(p, ERROR);
|
2019-05-15 15:35:47 +03:00
|
|
|
} else if !p.at(EOF) && !p.at(T!['}']) {
|
2019-03-17 22:04:25 +09:00
|
|
|
p.err_and_bump("expected an item");
|
|
|
|
} else {
|
|
|
|
p.error("expected an item");
|
2018-08-04 13:17:24 +03:00
|
|
|
}
|
2018-01-07 21:46:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 13:03:04 +09:00
|
|
|
pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Result<(), Marker> {
|
2019-03-18 14:34:08 +09:00
|
|
|
// test_err pub_expr
|
|
|
|
// fn foo() { pub 92; }
|
|
|
|
let has_visibility = opt_visibility(p);
|
|
|
|
|
|
|
|
let m = match items_without_modifiers(p, m) {
|
|
|
|
Ok(()) => return Ok(()),
|
|
|
|
Err(m) => m,
|
|
|
|
};
|
2018-08-04 13:17:24 +03:00
|
|
|
|
|
|
|
let mut has_mods = false;
|
2019-03-09 20:40:22 -03:00
|
|
|
|
2018-08-04 13:17:24 +03:00
|
|
|
// modifiers
|
2019-05-15 15:35:47 +03:00
|
|
|
has_mods |= p.eat(T![const]);
|
2019-04-03 17:11:56 +02:00
|
|
|
|
2018-12-20 16:45:54 +00:00
|
|
|
// test_err unsafe_block_in_mod
|
2018-08-04 13:17:24 +03:00
|
|
|
// fn foo(){} unsafe { } fn bar(){}
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(T![unsafe]) && p.nth(1) != T!['{'] {
|
|
|
|
p.eat(T![unsafe]);
|
2018-08-04 13:17:24 +03:00
|
|
|
has_mods = true;
|
|
|
|
}
|
2019-04-03 17:11:56 +02:00
|
|
|
|
|
|
|
// test_err async_without_semicolon
|
|
|
|
// fn foo() { let _ = async {} }
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(T![async]) && p.nth(1) != T!['{'] && p.nth(1) != T![move] && p.nth(1) != T![|] {
|
|
|
|
p.eat(T![async]);
|
2019-04-03 17:11:56 +02:00
|
|
|
has_mods = true;
|
|
|
|
}
|
|
|
|
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(T![extern]) {
|
2018-08-04 13:17:24 +03:00
|
|
|
has_mods = true;
|
|
|
|
abi(p);
|
|
|
|
}
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(IDENT) && p.at_contextual_kw("auto") && p.nth(1) == T![trait] {
|
|
|
|
p.bump_remap(T![auto]);
|
2018-08-04 13:17:24 +03:00
|
|
|
has_mods = true;
|
|
|
|
}
|
2019-05-24 01:48:44 +03:00
|
|
|
if p.at(IDENT) && p.at_contextual_kw("default") && p.nth(1) == T![impl] {
|
2019-05-15 15:35:47 +03:00
|
|
|
p.bump_remap(T![default]);
|
2018-08-04 13:17:24 +03:00
|
|
|
has_mods = true;
|
|
|
|
}
|
2019-06-11 21:24:14 +08:00
|
|
|
if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] {
|
|
|
|
p.bump_remap(T![existential]);
|
|
|
|
has_mods = true;
|
|
|
|
}
|
2018-08-04 13:17:24 +03:00
|
|
|
|
|
|
|
// items
|
2019-03-17 22:04:25 +09:00
|
|
|
match p.current() {
|
2019-03-09 20:40:22 -03:00
|
|
|
// test async_fn
|
|
|
|
// async fn foo() {}
|
|
|
|
|
2018-08-04 13:17:24 +03:00
|
|
|
// test extern_fn
|
|
|
|
// extern fn foo() {}
|
|
|
|
|
|
|
|
// test const_fn
|
|
|
|
// const fn foo() {}
|
|
|
|
|
|
|
|
// test const_unsafe_fn
|
|
|
|
// const unsafe fn foo() {}
|
|
|
|
|
|
|
|
// test unsafe_extern_fn
|
|
|
|
// unsafe extern "C" fn foo() {}
|
|
|
|
|
|
|
|
// test unsafe_fn
|
|
|
|
// unsafe fn foo() {}
|
2019-04-03 17:11:56 +02:00
|
|
|
|
|
|
|
// test combined_fns
|
|
|
|
// unsafe async fn foo() {}
|
|
|
|
// const unsafe fn bar() {}
|
|
|
|
|
|
|
|
// test_err wrong_order_fns
|
|
|
|
// async unsafe fn foo() {}
|
|
|
|
// unsafe const fn bar() {}
|
2019-05-15 15:35:47 +03:00
|
|
|
T![fn] => {
|
2018-08-26 12:09:28 +03:00
|
|
|
fn_def(p, flavor);
|
2019-03-17 22:04:25 +09:00
|
|
|
m.complete(p, FN_DEF);
|
2018-07-31 18:24:30 +03:00
|
|
|
}
|
2018-08-04 13:17:24 +03:00
|
|
|
|
|
|
|
// test unsafe_trait
|
|
|
|
// unsafe trait T {}
|
|
|
|
|
2018-07-31 18:24:30 +03:00
|
|
|
// test auto_trait
|
|
|
|
// auto trait T {}
|
2018-08-04 13:17:24 +03:00
|
|
|
|
|
|
|
// test unsafe_auto_trait
|
|
|
|
// unsafe auto trait T {}
|
2019-05-15 15:35:47 +03:00
|
|
|
T![trait] => {
|
2018-08-13 18:34:02 +03:00
|
|
|
traits::trait_def(p);
|
2019-03-17 22:04:25 +09:00
|
|
|
m.complete(p, TRAIT_DEF);
|
2018-07-31 18:24:30 +03:00
|
|
|
}
|
2018-08-04 13:17:24 +03:00
|
|
|
|
|
|
|
// test unsafe_impl
|
|
|
|
// unsafe impl Foo {}
|
|
|
|
|
2018-07-31 14:00:22 +03:00
|
|
|
// test default_impl
|
|
|
|
// default impl Foo {}
|
2018-08-04 13:17:24 +03:00
|
|
|
|
|
|
|
// test unsafe_default_impl
|
|
|
|
// unsafe default impl Foo {}
|
2019-05-24 01:48:44 +03:00
|
|
|
T![impl] => {
|
2018-12-30 18:38:44 +01:00
|
|
|
traits::impl_block(p);
|
2019-03-17 22:04:25 +09:00
|
|
|
m.complete(p, IMPL_BLOCK);
|
2018-07-31 14:00:22 +03:00
|
|
|
}
|
2019-06-11 21:24:14 +08:00
|
|
|
// test existential_type
|
|
|
|
// existential type Foo: Fn() -> usize;
|
|
|
|
T![type] => {
|
|
|
|
type_def(p, m);
|
|
|
|
}
|
2018-10-15 17:44:23 -04:00
|
|
|
_ => {
|
2019-03-18 14:34:08 +09:00
|
|
|
if !has_visibility && !has_mods {
|
2019-03-18 13:03:04 +09:00
|
|
|
return Err(m);
|
|
|
|
} else {
|
2019-03-18 14:34:08 +09:00
|
|
|
if has_mods {
|
2019-06-11 21:24:14 +08:00
|
|
|
p.error("expected existential, fn, trait or impl");
|
2019-03-18 14:34:08 +09:00
|
|
|
} else {
|
|
|
|
p.error("expected an item");
|
|
|
|
}
|
2019-03-17 22:04:25 +09:00
|
|
|
m.complete(p, ERROR);
|
|
|
|
}
|
2018-08-04 13:17:24 +03:00
|
|
|
}
|
2019-03-17 22:04:25 +09:00
|
|
|
}
|
2019-03-18 13:03:04 +09:00
|
|
|
Ok(())
|
2018-08-04 13:17:24 +03:00
|
|
|
}
|
|
|
|
|
2019-03-18 14:34:08 +09:00
|
|
|
fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
|
2018-08-04 13:17:24 +03:00
|
|
|
let la = p.nth(1);
|
2019-03-18 14:34:08 +09:00
|
|
|
match p.current() {
|
2018-08-04 13:17:24 +03:00
|
|
|
// test extern_crate
|
|
|
|
// extern crate foo;
|
2019-05-15 15:35:47 +03:00
|
|
|
T![extern] if la == T![crate] => extern_crate_item(p, m),
|
2019-06-11 21:24:14 +08:00
|
|
|
T![type] => {
|
|
|
|
type_def(p, m);
|
|
|
|
}
|
2019-05-15 15:35:47 +03:00
|
|
|
T![mod] => mod_item(p, m),
|
|
|
|
T![struct] => {
|
2018-09-14 22:51:12 +02:00
|
|
|
// test struct_items
|
|
|
|
// struct Foo;
|
|
|
|
// struct Foo {}
|
|
|
|
// struct Foo();
|
|
|
|
// struct Foo(String, usize);
|
|
|
|
// struct Foo {
|
|
|
|
// a: i32,
|
|
|
|
// b: f32,
|
|
|
|
// }
|
2019-05-15 15:35:47 +03:00
|
|
|
nominal::struct_def(p, m, T![struct]);
|
2018-01-20 23:25:34 +03:00
|
|
|
}
|
2018-12-20 19:46:03 +00:00
|
|
|
IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => {
|
2018-09-14 22:51:12 +02:00
|
|
|
// test union_items
|
|
|
|
// union Foo {}
|
|
|
|
// union Foo {
|
|
|
|
// a: i32,
|
|
|
|
// b: f32,
|
|
|
|
// }
|
2019-05-15 15:35:47 +03:00
|
|
|
nominal::struct_def(p, m, T![union]);
|
2018-08-04 13:17:24 +03:00
|
|
|
}
|
2019-05-15 15:35:47 +03:00
|
|
|
T![enum] => nominal::enum_def(p, m),
|
|
|
|
T![use] => use_item::use_item(p, m),
|
|
|
|
T![const] if (la == IDENT || la == T![mut]) => consts::const_def(p, m),
|
|
|
|
T![static] => consts::static_def(p, m),
|
2018-08-04 13:17:24 +03:00
|
|
|
// test extern_block
|
|
|
|
// extern {}
|
2019-05-15 15:35:47 +03:00
|
|
|
T![extern]
|
|
|
|
if la == T!['{'] || ((la == STRING || la == RAW_STRING) && p.nth(2) == T!['{']) =>
|
2018-10-15 17:44:23 -04:00
|
|
|
{
|
2018-08-04 13:17:24 +03:00
|
|
|
abi(p);
|
2018-08-24 19:27:30 +03:00
|
|
|
extern_item_list(p);
|
2019-03-18 14:34:08 +09:00
|
|
|
m.complete(p, EXTERN_BLOCK);
|
2018-01-20 17:21:13 +03:00
|
|
|
}
|
2019-03-18 14:34:08 +09:00
|
|
|
_ => return Err(m),
|
2018-01-20 17:21:13 +03:00
|
|
|
};
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(T![;]) {
|
2019-03-18 14:34:08 +09:00
|
|
|
p.err_and_bump(
|
|
|
|
"expected item, found `;`\n\
|
|
|
|
consider removing this semicolon",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
Ok(())
|
2018-01-07 21:46:10 +03:00
|
|
|
}
|
|
|
|
|
2019-03-18 14:34:08 +09:00
|
|
|
fn extern_crate_item(p: &mut Parser, m: Marker) {
|
2019-05-15 15:35:47 +03:00
|
|
|
assert!(p.at(T![extern]));
|
2018-01-20 17:21:13 +03:00
|
|
|
p.bump();
|
2019-05-15 15:35:47 +03:00
|
|
|
assert!(p.at(T![crate]));
|
2018-01-20 17:21:13 +03:00
|
|
|
p.bump();
|
2019-02-02 00:33:54 +01:00
|
|
|
name_ref(p);
|
2018-08-24 01:19:38 +03:00
|
|
|
opt_alias(p);
|
2019-05-15 15:35:47 +03:00
|
|
|
p.expect(T![;]);
|
2019-03-18 14:34:08 +09:00
|
|
|
m.complete(p, EXTERN_CRATE_ITEM);
|
2018-01-09 00:06:42 +03:00
|
|
|
}
|
|
|
|
|
2018-09-10 20:14:09 +02:00
|
|
|
pub(crate) fn extern_item_list(p: &mut Parser) {
|
2019-05-15 15:35:47 +03:00
|
|
|
assert!(p.at(T!['{']));
|
2018-08-24 19:27:30 +03:00
|
|
|
let m = p.start();
|
2018-02-02 23:45:15 +03:00
|
|
|
p.bump();
|
2018-09-04 00:49:21 +03:00
|
|
|
mod_contents(p, true);
|
2019-05-15 15:35:47 +03:00
|
|
|
p.expect(T!['}']);
|
2018-08-24 19:27:30 +03:00
|
|
|
m.complete(p, EXTERN_ITEM_LIST);
|
2018-02-02 23:45:15 +03:00
|
|
|
}
|
2018-02-04 13:39:24 +03:00
|
|
|
|
2018-08-26 12:09:28 +03:00
|
|
|
fn fn_def(p: &mut Parser, flavor: ItemFlavor) {
|
2019-05-15 15:35:47 +03:00
|
|
|
assert!(p.at(T![fn]));
|
2018-01-20 17:21:13 +03:00
|
|
|
p.bump();
|
|
|
|
|
2018-08-31 13:35:48 +03:00
|
|
|
name_r(p, ITEM_RECOVERY_SET);
|
2018-08-09 17:44:40 +03:00
|
|
|
// test function_type_params
|
2018-07-31 19:58:12 +03:00
|
|
|
// fn foo<T: Clone + Copy>(){}
|
2018-08-24 02:14:10 +03:00
|
|
|
type_params::opt_type_param_list(p);
|
2018-07-31 19:58:12 +03:00
|
|
|
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(T!['(']) {
|
2018-08-13 18:40:47 +03:00
|
|
|
match flavor {
|
2018-10-15 17:44:23 -04:00
|
|
|
ItemFlavor::Mod => params::param_list(p),
|
|
|
|
ItemFlavor::Trait => params::param_list_opt_patterns(p),
|
2018-08-13 18:40:47 +03:00
|
|
|
}
|
2018-01-28 14:26:24 +03:00
|
|
|
} else {
|
2018-02-09 22:44:50 +03:00
|
|
|
p.error("expected function arguments");
|
2018-01-28 14:26:24 +03:00
|
|
|
}
|
2018-08-09 17:44:40 +03:00
|
|
|
// test function_ret_type
|
2018-07-30 15:32:19 +03:00
|
|
|
// fn foo() {}
|
|
|
|
// fn bar() -> () {}
|
2018-08-24 02:14:10 +03:00
|
|
|
opt_fn_ret_type(p);
|
2018-07-31 19:58:12 +03:00
|
|
|
|
2018-08-09 17:44:40 +03:00
|
|
|
// test function_where_clause
|
2018-07-31 19:58:12 +03:00
|
|
|
// fn foo<T>() where T: Copy {}
|
2018-08-24 02:14:10 +03:00
|
|
|
type_params::opt_where_clause(p);
|
2018-07-31 19:58:12 +03:00
|
|
|
|
2018-08-08 00:53:03 +03:00
|
|
|
// test fn_decl
|
|
|
|
// trait T { fn foo(); }
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(T![;]) {
|
2018-08-25 13:21:43 +03:00
|
|
|
p.bump();
|
2018-08-24 20:50:37 +03:00
|
|
|
} else {
|
2018-08-25 13:21:43 +03:00
|
|
|
expressions::block(p)
|
2018-08-08 00:53:03 +03:00
|
|
|
}
|
2018-01-07 21:46:10 +03:00
|
|
|
}
|
2018-02-10 12:35:40 +03:00
|
|
|
|
|
|
|
// test type_item
|
|
|
|
// type Foo = Bar;
|
2019-03-18 14:34:08 +09:00
|
|
|
fn type_def(p: &mut Parser, m: Marker) {
|
2019-05-15 15:35:47 +03:00
|
|
|
assert!(p.at(T![type]));
|
2018-02-10 12:35:40 +03:00
|
|
|
p.bump();
|
|
|
|
|
2018-02-10 14:22:31 +03:00
|
|
|
name(p);
|
2018-02-10 12:35:40 +03:00
|
|
|
|
|
|
|
// test type_item_type_params
|
|
|
|
// type Result<T> = ();
|
2018-08-24 02:14:10 +03:00
|
|
|
type_params::opt_type_param_list(p);
|
2018-02-10 12:35:40 +03:00
|
|
|
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(T![:]) {
|
2018-08-08 00:53:03 +03:00
|
|
|
type_params::bounds(p);
|
|
|
|
}
|
|
|
|
|
2018-02-10 12:35:40 +03:00
|
|
|
// test type_item_where_clause
|
|
|
|
// type Foo where Foo: Copy = ();
|
2018-08-24 02:14:10 +03:00
|
|
|
type_params::opt_where_clause(p);
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.eat(T![=]) {
|
2018-08-08 00:53:03 +03:00
|
|
|
types::type_(p);
|
|
|
|
}
|
2019-05-15 15:35:47 +03:00
|
|
|
p.expect(T![;]);
|
2019-03-18 14:34:08 +09:00
|
|
|
m.complete(p, TYPE_ALIAS_DEF);
|
2018-02-10 12:35:40 +03:00
|
|
|
}
|
|
|
|
|
2019-03-18 14:34:08 +09:00
|
|
|
pub(crate) fn mod_item(p: &mut Parser, m: Marker) {
|
2019-05-15 15:35:47 +03:00
|
|
|
assert!(p.at(T![mod]));
|
2018-02-10 12:35:40 +03:00
|
|
|
p.bump();
|
|
|
|
|
2018-02-10 14:23:18 +03:00
|
|
|
name(p);
|
2019-05-15 15:35:47 +03:00
|
|
|
if p.at(T!['{']) {
|
2018-08-24 19:27:30 +03:00
|
|
|
mod_item_list(p);
|
2019-05-15 15:35:47 +03:00
|
|
|
} else if !p.eat(T![;]) {
|
2018-08-24 19:27:30 +03:00
|
|
|
p.error("expected `;` or `{`");
|
2018-02-10 12:35:40 +03:00
|
|
|
}
|
2019-03-18 14:34:08 +09:00
|
|
|
m.complete(p, MODULE);
|
2018-02-10 12:35:40 +03:00
|
|
|
}
|
2018-08-05 14:08:46 +03:00
|
|
|
|
2018-09-10 20:14:09 +02:00
|
|
|
pub(crate) fn mod_item_list(p: &mut Parser) {
|
2019-05-15 15:35:47 +03:00
|
|
|
assert!(p.at(T!['{']));
|
2018-08-24 19:27:30 +03:00
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
|
|
|
mod_contents(p, true);
|
2019-05-15 15:35:47 +03:00
|
|
|
p.expect(T!['}']);
|
2018-08-24 19:27:30 +03:00
|
|
|
m.complete(p, ITEM_LIST);
|
|
|
|
}
|
|
|
|
|
2018-08-07 16:11:40 +03:00
|
|
|
fn macro_call(p: &mut Parser) -> BlockLike {
|
2018-08-05 14:08:46 +03:00
|
|
|
assert!(paths::is_path_start(p));
|
|
|
|
paths::use_path(p);
|
2018-08-05 14:16:38 +03:00
|
|
|
macro_call_after_excl(p)
|
|
|
|
}
|
|
|
|
|
2018-08-07 16:11:40 +03:00
|
|
|
pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
|
2019-05-15 15:35:47 +03:00
|
|
|
p.expect(T![!]);
|
2019-02-11 19:23:13 +03:00
|
|
|
if p.at(IDENT) {
|
|
|
|
name(p);
|
|
|
|
}
|
2018-10-16 11:51:58 -04:00
|
|
|
match p.current() {
|
2019-05-15 15:35:47 +03:00
|
|
|
T!['{'] => {
|
2018-08-05 14:08:46 +03:00
|
|
|
token_tree(p);
|
2018-08-07 16:11:40 +03:00
|
|
|
BlockLike::Block
|
2018-08-05 14:08:46 +03:00
|
|
|
}
|
2019-05-15 15:35:47 +03:00
|
|
|
T!['('] | T!['['] => {
|
2018-08-05 14:08:46 +03:00
|
|
|
token_tree(p);
|
2018-08-07 16:11:40 +03:00
|
|
|
BlockLike::NotBlock
|
2018-08-05 14:08:46 +03:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
p.error("expected `{`, `[`, `(`");
|
2018-08-07 16:11:40 +03:00
|
|
|
BlockLike::NotBlock
|
2018-10-15 17:44:23 -04:00
|
|
|
}
|
2018-10-16 11:51:58 -04:00
|
|
|
}
|
2018-08-05 14:08:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-10 20:14:09 +02:00
|
|
|
pub(crate) fn token_tree(p: &mut Parser) {
|
2018-08-05 14:08:46 +03:00
|
|
|
let closing_paren_kind = match p.current() {
|
2019-05-15 15:35:47 +03:00
|
|
|
T!['{'] => T!['}'],
|
|
|
|
T!['('] => T![')'],
|
|
|
|
T!['['] => T![']'],
|
2018-08-05 14:08:46 +03:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
2018-08-16 12:51:40 +03:00
|
|
|
let m = p.start();
|
2018-08-05 14:08:46 +03:00
|
|
|
p.bump();
|
|
|
|
while !p.at(EOF) && !p.at(closing_paren_kind) {
|
|
|
|
match p.current() {
|
2019-05-15 15:35:47 +03:00
|
|
|
T!['{'] | T!['('] | T!['['] => token_tree(p),
|
|
|
|
T!['}'] => {
|
2018-09-08 10:28:53 +03:00
|
|
|
p.error("unmatched `}`");
|
|
|
|
m.complete(p, TOKEN_TREE);
|
|
|
|
return;
|
|
|
|
}
|
2019-05-15 15:35:47 +03:00
|
|
|
T![')'] | T![']'] => p.err_and_bump("unmatched brace"),
|
2019-04-28 23:46:03 +08:00
|
|
|
_ => p.bump_raw(),
|
2018-08-05 14:08:46 +03:00
|
|
|
}
|
2018-10-15 17:44:23 -04:00
|
|
|
}
|
2018-08-05 14:08:46 +03:00
|
|
|
p.expect(closing_paren_kind);
|
2018-08-16 12:51:40 +03:00
|
|
|
m.complete(p, TOKEN_TREE);
|
2018-08-05 14:08:46 +03:00
|
|
|
}
|