Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/expr_ext.rs')
| -rw-r--r-- | crates/syntax/src/ast/expr_ext.rs | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/crates/syntax/src/ast/expr_ext.rs b/crates/syntax/src/ast/expr_ext.rs index 28a9dadace..b0ee9dfd50 100644 --- a/crates/syntax/src/ast/expr_ext.rs +++ b/crates/syntax/src/ast/expr_ext.rs @@ -6,7 +6,8 @@ use crate::{ ast::{ self, operators::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp}, - support, AstChildren, AstNode, + support, ArgList, AstChildren, AstNode, BlockExpr, ClosureExpr, Const, Expr, Fn, + FormatArgsArg, FormatArgsExpr, MacroDef, Static, TokenTree, }, AstToken, SyntaxKind::*, @@ -435,3 +436,57 @@ impl AstNode for CallableExpr { } } } + +impl MacroDef { + fn tts(&self) -> (Option<ast::TokenTree>, Option<ast::TokenTree>) { + let mut types = support::children(self.syntax()); + let first = types.next(); + let second = types.next(); + (first, second) + } + + pub fn args(&self) -> Option<TokenTree> { + match self.tts() { + (Some(args), Some(_)) => Some(args), + _ => None, + } + } + + pub fn body(&self) -> Option<TokenTree> { + match self.tts() { + (Some(body), None) | (_, Some(body)) => Some(body), + _ => None, + } + } +} + +impl ClosureExpr { + pub fn body(&self) -> Option<Expr> { + support::child(&self.syntax) + } +} +impl Const { + pub fn body(&self) -> Option<Expr> { + support::child(&self.syntax) + } +} +impl Fn { + pub fn body(&self) -> Option<BlockExpr> { + support::child(&self.syntax) + } +} +impl Static { + pub fn body(&self) -> Option<Expr> { + support::child(&self.syntax) + } +} +impl FormatArgsExpr { + pub fn args(&self) -> AstChildren<FormatArgsArg> { + support::children(&self.syntax) + } +} +impl ArgList { + pub fn args(&self) -> AstChildren<Expr> { + support::children(&self.syntax) + } +} |