From a7ca6583fbce6f1bddce7b31ad5bb1fc0665b616 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 15:40:48 +0200 Subject: Handwrite Stmt --- xtask/src/codegen/gen_syntax.rs | 51 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'xtask/src/codegen/gen_syntax.rs') diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index d6a72ccc0..e3d4269f6 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -153,25 +153,10 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result { quote!(impl ast::#trait_name for #name {}) }); - ( - quote! { - #[pretty_doc_comment_placeholder_workaround] - #[derive(Debug, Clone, PartialEq, Eq, Hash)] - pub enum #name { - #(#variants(#variants),)* - } - - #(#traits)* - }, + let ast_node = if en.name == "Stmt" { + quote! {} + } else { quote! { - #( - impl From<#variants> for #name { - fn from(node: #variants) -> #name { - #name::#variants(node) - } - } - )* - impl AstNode for #name { fn can_cast(kind: SyntaxKind) -> bool { match kind { @@ -196,6 +181,28 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result { } } } + } + }; + + ( + quote! { + #[pretty_doc_comment_placeholder_workaround] + #[derive(Debug, Clone, PartialEq, Eq, Hash)] + pub enum #name { + #(#variants(#variants),)* + } + + #(#traits)* + }, + quote! { + #( + impl From<#variants> for #name { + fn from(node: #variants) -> #name { + #name::#variants(node) + } + } + )* + #ast_node }, ) }) @@ -497,13 +504,7 @@ fn lower(grammar: &Grammar) -> AstSrc { let mut res = AstSrc::default(); res.tokens = vec!["Whitespace".into(), "Comment".into(), "String".into(), "RawString".into()]; - let nodes = grammar - .iter() - .filter(|&node| match grammar[node].rule { - Rule::Node(it) if it == node => false, - _ => true, - }) - .collect::>(); + let nodes = grammar.iter().collect::>(); for &node in &nodes { let name = grammar[node].name.clone(); -- cgit v1.2.3 From d4d986c7f850e1f535bb4c22e3a7f7fba5483628 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 15:46:12 +0200 Subject: Item is a Stmt --- xtask/src/codegen/gen_syntax.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'xtask/src/codegen/gen_syntax.rs') diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index e3d4269f6..d9f358513 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -694,6 +694,9 @@ fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str fn extract_enum_traits(ast: &mut AstSrc) { for enm in &mut ast.enums { + if enm.name == "Stmt" { + continue; + } let nodes = &ast.nodes; let mut variant_traits = enm .variants -- cgit v1.2.3