aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
Diffstat (limited to 'xtask')
-rw-r--r--xtask/src/codegen/gen_syntax.rs15
1 files changed, 4 insertions, 11 deletions
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs
index fa48853d2..7dc7f396c 100644
--- a/xtask/src/codegen/gen_syntax.rs
+++ b/xtask/src/codegen/gen_syntax.rs
@@ -3,7 +3,7 @@
3//! Specifically, it generates the `SyntaxKind` enum and a number of newtype 3//! Specifically, it generates the `SyntaxKind` enum and a number of newtype
4//! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. 4//! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`.
5 5
6use std::collections::{BTreeSet, HashSet}; 6use std::collections::HashSet;
7 7
8use proc_macro2::{Punct, Spacing}; 8use proc_macro2::{Punct, Spacing};
9use quote::{format_ident, quote}; 9use quote::{format_ident, quote};
@@ -20,7 +20,7 @@ pub fn generate_syntax(mode: Mode) -> Result<()> {
20 update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?; 20 update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?;
21 21
22 let ast_tokens_file = project_root().join(codegen::AST_TOKENS); 22 let ast_tokens_file = project_root().join(codegen::AST_TOKENS);
23 let contents = generate_tokens(KINDS_SRC, AST_SRC)?; 23 let contents = generate_tokens(AST_SRC)?;
24 update(ast_tokens_file.as_path(), &contents, mode)?; 24 update(ast_tokens_file.as_path(), &contents, mode)?;
25 25
26 let ast_nodes_file = project_root().join(codegen::AST_NODES); 26 let ast_nodes_file = project_root().join(codegen::AST_NODES);
@@ -30,14 +30,7 @@ pub fn generate_syntax(mode: Mode) -> Result<()> {
30 Ok(()) 30 Ok(())
31} 31}
32 32
33#[derive(Debug, Default, Clone)] 33fn generate_tokens(grammar: AstSrc<'_>) -> Result<String> {
34struct ElementKinds {
35 kinds: BTreeSet<proc_macro2::Ident>,
36 has_nodes: bool,
37 has_tokens: bool,
38}
39
40fn generate_tokens(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
41 let tokens = grammar.tokens.iter().map(|token| { 34 let tokens = grammar.tokens.iter().map(|token| {
42 let name = format_ident!("{}", token); 35 let name = format_ident!("{}", token);
43 let kind = format_ident!("{}", to_upper_snake_case(token)); 36 let kind = format_ident!("{}", to_upper_snake_case(token));
@@ -91,7 +84,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
91 if let Some(token_kind) = field.token_kind() { 84 if let Some(token_kind) = field.token_kind() {
92 quote! { 85 quote! {
93 pub fn #method_name(&self) -> Option<#ty> { 86 pub fn #method_name(&self) -> Option<#ty> {
94 support::token2(&self.syntax, #token_kind) 87 support::token(&self.syntax, #token_kind)
95 } 88 }
96 } 89 }
97 } else { 90 } else {