File tree Expand file tree Collapse file tree
crates/plotnik-lib/src/parser Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,7 +30,11 @@ macro_rules! ast_node {
3030
3131 impl $name {
3232 pub fn cast( node: SyntaxNode ) -> Option <Self > {
33- ( node. kind( ) == SyntaxKind :: $kind) . then( || Self ( node) )
33+ Self :: can_cast( node. kind( ) ) . then( || Self ( node) )
34+ }
35+
36+ pub fn can_cast( kind: SyntaxKind ) -> bool {
37+ kind == SyntaxKind :: $kind
3438 }
3539
3640 pub fn as_cst( & self ) -> & SyntaxNode {
@@ -54,7 +58,8 @@ macro_rules! define_expr {
5458
5559 impl Expr {
5660 pub fn cast( node: SyntaxNode ) -> Option <Self > {
57- $( if let Some ( n) = $variant:: cast( node. clone( ) ) { return Some ( Expr :: $variant( n) ) ; } ) +
61+ let kind = node. kind( ) ;
62+ $( if $variant:: can_cast( kind) { return Some ( Expr :: $variant( $variant( node) ) ) ; } ) +
5863 None
5964 }
6065
@@ -138,7 +143,11 @@ pub struct AnonymousNode(SyntaxNode);
138143
139144impl AnonymousNode {
140145 pub fn cast ( node : SyntaxNode ) -> Option < Self > {
141- matches ! ( node. kind( ) , SyntaxKind :: Str | SyntaxKind :: Wildcard ) . then ( || Self ( node) )
146+ Self :: can_cast ( node. kind ( ) ) . then ( || Self ( node) )
147+ }
148+
149+ pub fn can_cast ( kind : SyntaxKind ) -> bool {
150+ matches ! ( kind, SyntaxKind :: Str | SyntaxKind :: Wildcard )
142151 }
143152
144153 pub fn as_cst ( & self ) -> & SyntaxNode {
You can’t perform that action at this time.
0 commit comments