mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Finalize attribute grammar
This commit is contained in:
parent
e28ea81b2b
commit
fcce07d2d1
6 changed files with 28 additions and 79 deletions
|
@ -24,7 +24,8 @@ impl Attr {
|
|||
pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
|
||||
pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
|
||||
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
|
||||
pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) }
|
||||
pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
|
||||
pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
|
||||
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
@ -1378,11 +1379,6 @@ pub enum GenericParam {
|
|||
}
|
||||
impl ast::AttrsOwner for GenericParam {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum AttrInput {
|
||||
Literal(Literal),
|
||||
TokenTree(TokenTree),
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Stmt {
|
||||
LetStmt(LetStmt),
|
||||
ExprStmt(ExprStmt),
|
||||
|
@ -3342,34 +3338,6 @@ impl AstNode for GenericParam {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl From<Literal> for AttrInput {
|
||||
fn from(node: Literal) -> AttrInput { AttrInput::Literal(node) }
|
||||
}
|
||||
impl From<TokenTree> for AttrInput {
|
||||
fn from(node: TokenTree) -> AttrInput { AttrInput::TokenTree(node) }
|
||||
}
|
||||
impl AstNode for AttrInput {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
LITERAL | TOKEN_TREE => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
LITERAL => AttrInput::Literal(Literal { syntax }),
|
||||
TOKEN_TREE => AttrInput::TokenTree(TokenTree { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
match self {
|
||||
AttrInput::Literal(it) => &it.syntax,
|
||||
AttrInput::TokenTree(it) => &it.syntax,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<LetStmt> for Stmt {
|
||||
fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) }
|
||||
}
|
||||
|
@ -3471,11 +3439,6 @@ impl std::fmt::Display for GenericParam {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for AttrInput {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for Stmt {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue