Update ungrammar

This commit is contained in:
Jonas Schievink 2021-06-11 18:12:51 +02:00
parent 80b3b74018
commit 1d6eef1350
43 changed files with 801 additions and 676 deletions

View file

@ -144,19 +144,20 @@ impl AttrKind {
impl ast::Attr {
pub fn as_simple_atom(&self) -> Option<SmolStr> {
if self.eq_token().is_some() || self.token_tree().is_some() {
let meta = self.meta()?;
if meta.eq_token().is_some() || meta.token_tree().is_some() {
return None;
}
self.simple_name()
}
pub fn as_simple_call(&self) -> Option<(SmolStr, ast::TokenTree)> {
let tt = self.token_tree()?;
let tt = self.meta()?.token_tree()?;
Some((self.simple_name()?, tt))
}
pub fn simple_name(&self) -> Option<SmolStr> {
let path = self.path()?;
let path = self.meta()?.path()?;
match (path.segment(), path.qualifier()) {
(Some(segment), None) => Some(segment.syntax().first_token()?.text().into()),
_ => None,
@ -174,6 +175,18 @@ impl ast::Attr {
_ => AttrKind::Outer,
}
}
pub fn path(&self) -> Option<ast::Path> {
self.meta()?.path()
}
pub fn expr(&self) -> Option<ast::Expr> {
self.meta()?.expr()
}
pub fn token_tree(&self) -> Option<ast::TokenTree> {
self.meta()?.token_tree()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]