mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 03:45:04 +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:
parent
59bc7b49d0
commit
737500137f
3 changed files with 1093 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue