Implement unsafe attribute parsing

This commit is contained in:
Lukas Wirth 2024-05-06 12:09:31 +02:00
parent c4618fe14d
commit e1aeed3aed
8 changed files with 534 additions and 11 deletions

View file

@ -36,8 +36,33 @@ fn attr(p: &mut Parser<'_>, inner: bool) {
attr.complete(p, ATTR);
}
// test metas
// #![simple_ident]
// #![simple::path]
// #![simple_ident_expr = ""]
// #![simple::path::Expr = ""]
// #![simple_ident_tt(a b c)]
// #![simple_ident_tt[a b c]]
// #![simple_ident_tt{a b c}]
// #![simple::path::tt(a b c)]
// #![simple::path::tt[a b c]]
// #![simple::path::tt{a b c}]
// #![unsafe(simple_ident)]
// #![unsafe(simple::path)]
// #![unsafe(simple_ident_expr = "")]
// #![unsafe(simple::path::Expr = "")]
// #![unsafe(simple_ident_tt(a b c))]
// #![unsafe(simple_ident_tt[a b c])]
// #![unsafe(simple_ident_tt{a b c})]
// #![unsafe(simple::path::tt(a b c))]
// #![unsafe(simple::path::tt[a b c])]
// #![unsafe(simple::path::tt{a b c})]
pub(super) fn meta(p: &mut Parser<'_>) {
let meta = p.start();
let is_unsafe = p.eat(T![unsafe]);
if is_unsafe {
p.expect(T!['(']);
}
paths::use_path(p);
match p.current() {
@ -50,6 +75,9 @@ pub(super) fn meta(p: &mut Parser<'_>) {
T!['('] | T!['['] | T!['{'] => items::token_tree(p),
_ => {}
}
if is_unsafe {
p.expect(T![')']);
}
meta.complete(p, META);
}