From 56c8581b901427ee3e63052c531f3ba3b1ec112d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 18:11:16 +0200 Subject: Put displays at the end --- xtask/src/codegen/gen_syntax.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index f9a50c5b9..6657c9fc5 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -230,12 +230,6 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result { pub(crate) syntax: SyntaxNode, } - impl std::fmt::Display for #name { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } - } - impl AstNode for #name { fn can_cast(kind: SyntaxKind) -> bool { kind == #kind @@ -280,12 +274,6 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result { } )* - impl std::fmt::Display for #name { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } - } - impl AstNode for #name { fn can_cast(kind: SyntaxKind) -> bool { match kind { @@ -315,6 +303,21 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result { } }); + let displays = grammar + .enums + .iter() + .map(|it| format_ident!("{}", it.name)) + .chain(grammar.nodes.iter().map(|it| format_ident!("{}", it.name))) + .map(|name| { + quote! { + impl std::fmt::Display for #name { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } + } + } + }); + let defined_nodes: HashSet<_> = grammar.nodes.iter().map(|node| node.name).collect(); for node in kinds @@ -336,6 +339,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result { #(#nodes)* #(#enums)* + #(#displays)* }; let pretty = crate::reformat(ast)?; -- cgit v1.2.3