aboutsummaryrefslogtreecommitdiff
path: root/src/syntax_kinds
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-30 12:06:22 +0100
committerAleksey Kladov <[email protected]>2018-07-30 12:06:22 +0100
commit6983091d6d255bcfd17c4f8c14015d8abc77928d (patch)
tree153359a05ca3fd887b59fe47ee84a60be0e6dfaf /src/syntax_kinds
parent9a4957d143397256dc04f715660f758a65fcb9d1 (diff)
Cleanup tools
Diffstat (limited to 'src/syntax_kinds')
-rw-r--r--src/syntax_kinds/generated.rs69
-rw-r--r--src/syntax_kinds/generated.rs.tera59
2 files changed, 93 insertions, 35 deletions
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index d332fd02e..029972bb3 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -1,6 +1,5 @@
1#![allow(bad_style, missing_docs, unreachable_pub)] 1#![allow(bad_style, missing_docs, unreachable_pub)]
2#![cfg_attr(rustfmt, rustfmt_skip)] 2#![cfg_attr(rustfmt, rustfmt_skip)]
3//! Generated from grammar.ron
4use super::SyntaxInfo; 3use super::SyntaxInfo;
5 4
6/// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. 5/// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`.
@@ -138,7 +137,6 @@ pub enum SyntaxKind {
138 VALUE_PARAMETER, 137 VALUE_PARAMETER,
139 BLOCK, 138 BLOCK,
140 LET_STMT, 139 LET_STMT,
141
142 // Technical SyntaxKinds: they appear temporally during parsing, 140 // Technical SyntaxKinds: they appear temporally during parsing,
143 // but never end up in the final tree 141 // but never end up in the final tree
144 #[doc(hidden)] 142 #[doc(hidden)]
@@ -146,7 +144,7 @@ pub enum SyntaxKind {
146 #[doc(hidden)] 144 #[doc(hidden)]
147 EOF, 145 EOF,
148} 146}
149pub(crate) use self::SyntaxKind::*; 147use self::SyntaxKind::*;
150 148
151impl SyntaxKind { 149impl SyntaxKind {
152 pub(crate) fn info(self) -> &'static SyntaxInfo { 150 pub(crate) fn info(self) -> &'static SyntaxInfo {
@@ -289,38 +287,39 @@ impl SyntaxKind {
289 } 287 }
290 } 288 }
291 pub(crate) fn from_keyword(ident: &str) -> Option<SyntaxKind> { 289 pub(crate) fn from_keyword(ident: &str) -> Option<SyntaxKind> {
292 match ident { 290 let kw = match ident {
293 "use" => Some(USE_KW), 291 "use" => USE_KW,
294 "fn" => Some(FN_KW), 292 "fn" => FN_KW,
295 "struct" => Some(STRUCT_KW), 293 "struct" => STRUCT_KW,
296 "enum" => Some(ENUM_KW), 294 "enum" => ENUM_KW,
297 "trait" => Some(TRAIT_KW), 295 "trait" => TRAIT_KW,
298 "impl" => Some(IMPL_KW), 296 "impl" => IMPL_KW,
299 "true" => Some(TRUE_KW), 297 "true" => TRUE_KW,
300 "false" => Some(FALSE_KW), 298 "false" => FALSE_KW,
301 "as" => Some(AS_KW), 299 "as" => AS_KW,
302 "extern" => Some(EXTERN_KW), 300 "extern" => EXTERN_KW,
303 "crate" => Some(CRATE_KW), 301 "crate" => CRATE_KW,
304 "mod" => Some(MOD_KW), 302 "mod" => MOD_KW,
305 "pub" => Some(PUB_KW), 303 "pub" => PUB_KW,
306 "self" => Some(SELF_KW), 304 "self" => SELF_KW,
307 "super" => Some(SUPER_KW), 305 "super" => SUPER_KW,
308 "in" => Some(IN_KW), 306 "in" => IN_KW,
309 "where" => Some(WHERE_KW), 307 "where" => WHERE_KW,
310 "for" => Some(FOR_KW), 308 "for" => FOR_KW,
311 "loop" => Some(LOOP_KW), 309 "loop" => LOOP_KW,
312 "while" => Some(WHILE_KW), 310 "while" => WHILE_KW,
313 "if" => Some(IF_KW), 311 "if" => IF_KW,
314 "match" => Some(MATCH_KW), 312 "match" => MATCH_KW,
315 "const" => Some(CONST_KW), 313 "const" => CONST_KW,
316 "static" => Some(STATIC_KW), 314 "static" => STATIC_KW,
317 "mut" => Some(MUT_KW), 315 "mut" => MUT_KW,
318 "unsafe" => Some(UNSAFE_KW), 316 "unsafe" => UNSAFE_KW,
319 "type" => Some(TYPE_KW), 317 "type" => TYPE_KW,
320 "ref" => Some(REF_KW), 318 "ref" => REF_KW,
321 "let" => Some(LET_KW), 319 "let" => LET_KW,
322 _ => None, 320 _ => return None,
323 } 321 };
322 Some(kw)
324 } 323 }
325} 324}
326 325
diff --git a/src/syntax_kinds/generated.rs.tera b/src/syntax_kinds/generated.rs.tera
new file mode 100644
index 000000000..aa672d89a
--- /dev/null
+++ b/src/syntax_kinds/generated.rs.tera
@@ -0,0 +1,59 @@
1#![allow(bad_style, missing_docs, unreachable_pub)]
2#![cfg_attr(rustfmt, rustfmt_skip)]
3use super::SyntaxInfo;
4
5/// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`.
6#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub enum SyntaxKind {
8{%- for t in tokens %}
9 {{t}},
10{%- endfor -%}
11{% for kw in keywords %}
12 {{kw | upper}}_KW,
13{%- endfor -%}
14{% for kw in contextual_keywords %}
15 {{kw | upper}}_KW,
16{%- endfor -%}
17{% for node in nodes %}
18 {{node}},
19{%- endfor %}
20 // Technical SyntaxKinds: they appear temporally during parsing,
21 // but never end up in the final tree
22 #[doc(hidden)]
23 TOMBSTONE,
24 #[doc(hidden)]
25 EOF,
26}
27use self::SyntaxKind::*;
28
29impl SyntaxKind {
30 pub(crate) fn info(self) -> &'static SyntaxInfo {
31 match self {
32{%- for t in tokens %}
33 {{t}} => &SyntaxInfo { name: "{{t}}" },
34{%- endfor -%}
35{% for kw in keywords %}
36 {{kw | upper}}_KW => &SyntaxInfo { name: "{{kw | upper}}_KW" },
37{%- endfor -%}
38{% for kw in contextual_keywords %}
39 {{kw | upper}}_KW => &SyntaxInfo { name: "{{kw | upper}}_KW" },
40{%- endfor -%}
41{% for node in nodes %}
42 {{node}} => &SyntaxInfo { name: "{{node}}" },
43{%- endfor %}
44
45 TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" },
46 EOF => &SyntaxInfo { name: "EOF" },
47 }
48 }
49 pub(crate) fn from_keyword(ident: &str) -> Option<SyntaxKind> {
50 let kw = match ident {
51{%- for kw in keywords %}
52 "{{kw}}" => {{kw | upper}}_KW,
53{%- endfor %}
54 _ => return None,
55 };
56 Some(kw)
57 }
58}
59