From 71efdaa6364142b359c59659ec10f35a1e53b5d2 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Mon, 30 Sep 2019 04:44:33 +0800 Subject: Parse correct AttrInput --- crates/ra_syntax/src/ast/generated.rs | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index dc1f8c82c..408449fd6 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -166,11 +166,55 @@ impl AstNode for Attr { } } impl Attr { + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn input(&self) -> Option { + AstChildren::new(&self.syntax).next() + } pub fn value(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum AttrInput { + Literal(Literal), + TokenTree(TokenTree), +} +impl From for AttrInput { + fn from(node: Literal) -> AttrInput { + AttrInput::Literal(node) + } +} +impl From 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 { + 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 AttrInput {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct AwaitExpr { pub(crate) syntax: SyntaxNode, } -- cgit v1.2.3