Derive kinds information from ungrammar file

This commit is contained in:
Lukas Wirth 2024-07-17 10:04:45 +02:00
parent 8f044d9681
commit 983c9c122e
12 changed files with 448 additions and 718 deletions

View file

@ -165,42 +165,6 @@ pub(crate) mod entry {
}
m.complete(p, ERROR);
}
pub(crate) fn eager_macro_input(p: &mut Parser<'_>) {
let m = p.start();
let closing_paren_kind = match p.current() {
T!['{'] => T!['}'],
T!['('] => T![')'],
T!['['] => T![']'],
_ => {
p.error("expected `{`, `[`, `(`");
while !p.at(EOF) {
p.bump_any();
}
m.complete(p, ERROR);
return;
}
};
p.bump_any();
while !p.at(EOF) && !p.at(closing_paren_kind) {
if expressions::expr(p).is_none() {
break;
}
if !p.at(EOF) && !p.at(closing_paren_kind) {
p.expect(T![,]);
}
}
p.expect(closing_paren_kind);
if p.at(EOF) {
m.complete(p, MACRO_EAGER_INPUT);
return;
}
while !p.at(EOF) {
p.bump_any();
}
m.complete(p, ERROR);
}
}
}

View file

@ -173,13 +173,6 @@ pub(super) fn opt_item(p: &mut Parser<'_>, m: Marker) -> Result<(), Marker> {
}
}
// test existential_type
// existential type Foo: Fn() -> usize;
if p.at_contextual_kw(T![existential]) && p.nth(1) == T![type] {
p.bump_remap(T![existential]);
has_mods = true;
}
// items
match p.current() {
T![fn] => fn_(p, m),
@ -201,7 +194,7 @@ pub(super) fn opt_item(p: &mut Parser<'_>, m: Marker) -> Result<(), Marker> {
_ if has_visibility || has_mods => {
if has_mods {
p.error("expected existential, fn, trait or impl");
p.error("expected fn, trait or impl");
} else {
p.error("expected an item");
}

View file

@ -82,8 +82,6 @@ pub enum TopEntryPoint {
/// Edge case -- macros generally don't expand to attributes, with the
/// exception of `cfg_attr` which does!
MetaItem,
/// Edge case 2 -- eager macros expand their input to a delimited list of comma separated expressions
MacroEagerInput,
}
impl TopEntryPoint {
@ -97,7 +95,6 @@ impl TopEntryPoint {
TopEntryPoint::Type => grammar::entry::top::type_,
TopEntryPoint::Expr => grammar::entry::top::expr,
TopEntryPoint::MetaItem => grammar::entry::top::meta_item,
TopEntryPoint::MacroEagerInput => grammar::entry::top::eager_macro_input,
};
let mut p = parser::Parser::new(input, edition);
entry_point(&mut p);

File diff suppressed because one or more lines are too long