mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-05 09:23:31 +00:00
Generate a method for static retrieval of the SyntaxKind of a node, where possible
This will help for the quote macro for `ast::make`.
This commit is contained in:
@@ -42,6 +42,14 @@ pub use self::{
|
||||
/// the same representation: a pointer to the tree root and a pointer to the
|
||||
/// node itself.
|
||||
pub trait AstNode {
|
||||
/// This panics if the `SyntaxKind` is not statically known.
|
||||
fn kind() -> SyntaxKind
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
panic!("dynamic `SyntaxKind` for `AstNode::kind()`")
|
||||
}
|
||||
|
||||
fn can_cast(kind: SyntaxKind) -> bool
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -162,6 +162,13 @@ fn generate_nodes(kinds: KindsSrc, grammar: &AstSrc) -> String {
|
||||
},
|
||||
quote! {
|
||||
impl AstNode for #name {
|
||||
#[inline]
|
||||
fn kind() -> SyntaxKind
|
||||
where
|
||||
Self: Sized
|
||||
{
|
||||
#kind
|
||||
}
|
||||
#[inline]
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
kind == #kind
|
||||
|
||||
Reference in New Issue
Block a user