aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-19 09:56:39 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-19 09:56:39 +0100
commitab0a96586fd54858106cb6ac112d61eb657426f6 (patch)
tree86bbf2601069f6b0007dc181c824ef706d08c60d /crates/ra_syntax/src/ast
parentd55f1136d6444b1f50b9092c36a976d0e1c26202 (diff)
parenta6d51e09610989821aaf79871bcab0661c9b0f74 (diff)
Merge #1148
1148: Add token_tree_to_xxx functions r=matklad a=edwin0cheng <del>As discus in PR #1147 , this PR added a `mbe::MacroKind` . Currently only 2 kind of macro are supported, `SourceFile` and `Block`.</del> Added following functions for `tt::TokenTree` and `ast::Node` conversion: * token_tree_to_expr * token_tree_to_pat * token_tree_to_ty * token_tree_to_macro_stmts * token_tree_to_macro_items And added two new syntax kind: * MACRO_ITEMS * MACRO_STMTS Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 774d9bcc8..17de4f058 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1770,6 +1770,72 @@ impl MacroCall {
1770 } 1770 }
1771} 1771}
1772 1772
1773// MacroItems
1774#[derive(Debug, PartialEq, Eq, Hash)]
1775#[repr(transparent)]
1776pub struct MacroItems {
1777 pub(crate) syntax: SyntaxNode,
1778}
1779unsafe impl TransparentNewType for MacroItems {
1780 type Repr = rowan::SyntaxNode;
1781}
1782
1783impl AstNode for MacroItems {
1784 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1785 match syntax.kind() {
1786 MACRO_ITEMS => Some(MacroItems::from_repr(syntax.into_repr())),
1787 _ => None,
1788 }
1789 }
1790 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1791}
1792
1793impl ToOwned for MacroItems {
1794 type Owned = TreeArc<MacroItems>;
1795 fn to_owned(&self) -> TreeArc<MacroItems> { TreeArc::cast(self.syntax.to_owned()) }
1796}
1797
1798
1799impl ast::ModuleItemOwner for MacroItems {}
1800impl ast::FnDefOwner for MacroItems {}
1801impl MacroItems {}
1802
1803// MacroStmts
1804#[derive(Debug, PartialEq, Eq, Hash)]
1805#[repr(transparent)]
1806pub struct MacroStmts {
1807 pub(crate) syntax: SyntaxNode,
1808}
1809unsafe impl TransparentNewType for MacroStmts {
1810 type Repr = rowan::SyntaxNode;
1811}
1812
1813impl AstNode for MacroStmts {
1814 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1815 match syntax.kind() {
1816 MACRO_STMTS => Some(MacroStmts::from_repr(syntax.into_repr())),
1817 _ => None,
1818 }
1819 }
1820 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1821}
1822
1823impl ToOwned for MacroStmts {
1824 type Owned = TreeArc<MacroStmts>;
1825 fn to_owned(&self) -> TreeArc<MacroStmts> { TreeArc::cast(self.syntax.to_owned()) }
1826}
1827
1828
1829impl MacroStmts {
1830 pub fn statements(&self) -> impl Iterator<Item = &Stmt> {
1831 super::children(self)
1832 }
1833
1834 pub fn expr(&self) -> Option<&Expr> {
1835 super::child_opt(self)
1836 }
1837}
1838
1773// MatchArm 1839// MatchArm
1774#[derive(Debug, PartialEq, Eq, Hash)] 1840#[derive(Debug, PartialEq, Eq, Hash)]
1775#[repr(transparent)] 1841#[repr(transparent)]