added fmt::Display as a supertrait for AstNode and changed generation.

This commit is contained in:
Fireassember 2020-03-06 19:29:30 +02:00
parent 190179489d
commit 787043496a
2 changed files with 7 additions and 1 deletions

View file

@ -30,7 +30,7 @@ pub use self::{
/// conversion itself has zero runtime cost: ast and syntax nodes have exactly
/// the same representation: a pointer to the tree root and a pointer to the
/// node itself.
pub trait AstNode {
pub trait AstNode: std::fmt::Display {
fn can_cast(kind: SyntaxKind) -> bool
where
Self: Sized;

View file

@ -68,6 +68,12 @@ fn generate_ast(grammar: AstSrc<'_>) -> Result<String> {
pub(crate) syntax: SyntaxNode,
}
impl std::fmt::Display for #name {
fn fmt(..) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax())
}
}
impl AstNode for #name {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {