diff options
-rw-r--r-- | src/bin/gen.rs | 16 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 16 |
2 files changed, 9 insertions, 23 deletions
diff --git a/src/bin/gen.rs b/src/bin/gen.rs index d3539321e..4acf381e3 100644 --- a/src/bin/gen.rs +++ b/src/bin/gen.rs | |||
@@ -40,28 +40,20 @@ impl Grammar { | |||
40 | ).unwrap(); | 40 | ).unwrap(); |
41 | } | 41 | } |
42 | acc.push_str("\n"); | 42 | acc.push_str("\n"); |
43 | write!(acc, "static INFOS: [SyntaxInfo; {}] = [\n", self.syntax_kinds.len()).unwrap(); | ||
43 | for kind in self.syntax_kinds.iter() { | 44 | for kind in self.syntax_kinds.iter() { |
44 | let sname = scream(kind); | 45 | let sname = scream(kind); |
45 | write!( | 46 | write!( |
46 | acc, | 47 | acc, |
47 | "static {sname}_INFO: SyntaxInfo = SyntaxInfo {{\n name: \"{sname}\",\n}};\n", | 48 | " SyntaxInfo {{ name: \"{sname}\" }},\n", |
48 | sname = sname | 49 | sname = sname |
49 | ).unwrap(); | 50 | ).unwrap(); |
50 | } | 51 | } |
52 | acc.push_str("];\n"); | ||
51 | acc.push_str("\n"); | 53 | acc.push_str("\n"); |
52 | 54 | ||
53 | acc.push_str("pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {\n"); | 55 | acc.push_str("pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {\n"); |
54 | acc.push_str(" match kind {\n"); | 56 | acc.push_str(" &INFOS[kind.0 as usize]\n"); |
55 | for kind in self.syntax_kinds.iter() { | ||
56 | let sname = scream(kind); | ||
57 | write!( | ||
58 | acc, | ||
59 | " {sname} => &{sname}_INFO,\n", | ||
60 | sname = sname | ||
61 | ).unwrap(); | ||
62 | } | ||
63 | acc.push_str(" _ => unreachable!()\n"); | ||
64 | acc.push_str(" }\n"); | ||
65 | acc.push_str("}\n"); | 57 | acc.push_str("}\n"); |
66 | acc | 58 | acc |
67 | } | 59 | } |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index a5485c4c1..421cae15a 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -4,17 +4,11 @@ use tree::{SyntaxKind, SyntaxInfo}; | |||
4 | pub const IDENT: SyntaxKind = SyntaxKind(0); | 4 | pub const IDENT: SyntaxKind = SyntaxKind(0); |
5 | pub const WHITESPACE: SyntaxKind = SyntaxKind(1); | 5 | pub const WHITESPACE: SyntaxKind = SyntaxKind(1); |
6 | 6 | ||
7 | static IDENT_INFO: SyntaxInfo = SyntaxInfo { | 7 | static INFOS: [SyntaxInfo; 2] = [ |
8 | name: "IDENT", | 8 | SyntaxInfo { name: "IDENT" }, |
9 | }; | 9 | SyntaxInfo { name: "WHITESPACE" }, |
10 | static WHITESPACE_INFO: SyntaxInfo = SyntaxInfo { | 10 | ]; |
11 | name: "WHITESPACE", | ||
12 | }; | ||
13 | 11 | ||
14 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { | 12 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { |
15 | match kind { | 13 | &INFOS[kind.0 as usize] |
16 | IDENT => &IDENT_INFO, | ||
17 | WHITESPACE => &WHITESPACE_INFO, | ||
18 | _ => unreachable!() | ||
19 | } | ||
20 | } | 14 | } |