aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-09 17:11:16 +0100
committerAleksey Kladov <[email protected]>2020-04-09 17:11:16 +0100
commit56c8581b901427ee3e63052c531f3ba3b1ec112d (patch)
treef31bae40498218a51c368b0ae1c18018ac1d9565 /xtask/src
parent9285cbffb66e1c497469fedc5c181b7f295742fd (diff)
Put displays at the end
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/codegen/gen_syntax.rs28
1 files changed, 16 insertions, 12 deletions
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<String> {
230 pub(crate) syntax: SyntaxNode, 230 pub(crate) syntax: SyntaxNode,
231 } 231 }
232 232
233 impl std::fmt::Display for #name {
234 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
235 std::fmt::Display::fmt(self.syntax(), f)
236 }
237 }
238
239 impl AstNode for #name { 233 impl AstNode for #name {
240 fn can_cast(kind: SyntaxKind) -> bool { 234 fn can_cast(kind: SyntaxKind) -> bool {
241 kind == #kind 235 kind == #kind
@@ -280,12 +274,6 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
280 } 274 }
281 )* 275 )*
282 276
283 impl std::fmt::Display for #name {
284 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
285 std::fmt::Display::fmt(self.syntax(), f)
286 }
287 }
288
289 impl AstNode for #name { 277 impl AstNode for #name {
290 fn can_cast(kind: SyntaxKind) -> bool { 278 fn can_cast(kind: SyntaxKind) -> bool {
291 match kind { 279 match kind {
@@ -315,6 +303,21 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
315 } 303 }
316 }); 304 });
317 305
306 let displays = grammar
307 .enums
308 .iter()
309 .map(|it| format_ident!("{}", it.name))
310 .chain(grammar.nodes.iter().map(|it| format_ident!("{}", it.name)))
311 .map(|name| {
312 quote! {
313 impl std::fmt::Display for #name {
314 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
315 std::fmt::Display::fmt(self.syntax(), f)
316 }
317 }
318 }
319 });
320
318 let defined_nodes: HashSet<_> = grammar.nodes.iter().map(|node| node.name).collect(); 321 let defined_nodes: HashSet<_> = grammar.nodes.iter().map(|node| node.name).collect();
319 322
320 for node in kinds 323 for node in kinds
@@ -336,6 +339,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
336 339
337 #(#nodes)* 340 #(#nodes)*
338 #(#enums)* 341 #(#enums)*
342 #(#displays)*
339 }; 343 };
340 344
341 let pretty = crate::reformat(ast)?; 345 let pretty = crate::reformat(ast)?;