diff options
author | Aleksey Kladov <[email protected]> | 2020-07-31 14:40:48 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-31 14:40:48 +0100 |
commit | a7ca6583fbce6f1bddce7b31ad5bb1fc0665b616 (patch) | |
tree | b148be3186c9de3de526fe798eac36f27517c178 /xtask/src | |
parent | 4d38b0dce1884dab0da7394ccc979eef0a21076c (diff) |
Handwrite Stmt
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 51 |
1 files changed, 26 insertions, 25 deletions
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<String> { | |||
153 | quote!(impl ast::#trait_name for #name {}) | 153 | quote!(impl ast::#trait_name for #name {}) |
154 | }); | 154 | }); |
155 | 155 | ||
156 | ( | 156 | let ast_node = if en.name == "Stmt" { |
157 | quote! { | 157 | quote! {} |
158 | #[pretty_doc_comment_placeholder_workaround] | 158 | } else { |
159 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
160 | pub enum #name { | ||
161 | #(#variants(#variants),)* | ||
162 | } | ||
163 | |||
164 | #(#traits)* | ||
165 | }, | ||
166 | quote! { | 159 | quote! { |
167 | #( | ||
168 | impl From<#variants> for #name { | ||
169 | fn from(node: #variants) -> #name { | ||
170 | #name::#variants(node) | ||
171 | } | ||
172 | } | ||
173 | )* | ||
174 | |||
175 | impl AstNode for #name { | 160 | impl AstNode for #name { |
176 | fn can_cast(kind: SyntaxKind) -> bool { | 161 | fn can_cast(kind: SyntaxKind) -> bool { |
177 | match kind { | 162 | match kind { |
@@ -196,6 +181,28 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> { | |||
196 | } | 181 | } |
197 | } | 182 | } |
198 | } | 183 | } |
184 | } | ||
185 | }; | ||
186 | |||
187 | ( | ||
188 | quote! { | ||
189 | #[pretty_doc_comment_placeholder_workaround] | ||
190 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
191 | pub enum #name { | ||
192 | #(#variants(#variants),)* | ||
193 | } | ||
194 | |||
195 | #(#traits)* | ||
196 | }, | ||
197 | quote! { | ||
198 | #( | ||
199 | impl From<#variants> for #name { | ||
200 | fn from(node: #variants) -> #name { | ||
201 | #name::#variants(node) | ||
202 | } | ||
203 | } | ||
204 | )* | ||
205 | #ast_node | ||
199 | }, | 206 | }, |
200 | ) | 207 | ) |
201 | }) | 208 | }) |
@@ -497,13 +504,7 @@ fn lower(grammar: &Grammar) -> AstSrc { | |||
497 | let mut res = AstSrc::default(); | 504 | let mut res = AstSrc::default(); |
498 | res.tokens = vec!["Whitespace".into(), "Comment".into(), "String".into(), "RawString".into()]; | 505 | res.tokens = vec!["Whitespace".into(), "Comment".into(), "String".into(), "RawString".into()]; |
499 | 506 | ||
500 | let nodes = grammar | 507 | let nodes = grammar.iter().collect::<Vec<_>>(); |
501 | .iter() | ||
502 | .filter(|&node| match grammar[node].rule { | ||
503 | Rule::Node(it) if it == node => false, | ||
504 | _ => true, | ||
505 | }) | ||
506 | .collect::<Vec<_>>(); | ||
507 | 508 | ||
508 | for &node in &nodes { | 509 | for &node in &nodes { |
509 | let name = grammar[node].name.clone(); | 510 | let name = grammar[node].name.clone(); |