aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-01-28 08:07:56 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-01-28 08:07:56 +0000
commitaff82e5ee1d587b858e7237511e611bb8cc61cf3 (patch)
tree83d1a4bbaa4be96f76c2d48c00ad479173f61274
parentefadcf715862a2d96af0f57d2b53bfa325390779 (diff)
parent4244948c6b1a62bd0e1ef276d1f0cc22c36f6f66 (diff)
Merge #16
16: Proof-of-concept SyntaxKind as enum r=matklad a=CAD97 This was the one bit about the original RFC I was most confused about. Why isn't `SyntaxKind` a normal `enum`? If it's to signify that it's non-exhaustive [`#[non_exhaustive]`](https://github.com/rust-lang/rust/issues/44109) should be used. (Or `#[doc(hidden)] __Nonexhaustive` on stable.) If it's so that more variants can be added externally, why? There's no need for that, that I can foresee. If it's to expose the `SyntaxKind` type but not any of its instances, why? This is the only actual benefit I can see of this pseudo-enum style. This diff is meant to be as non-invasive as possible, and as such reexports all symbols as they existed prior to this. It's diffed on top of the assumed-good-to-merge #15 to avoid the conflict between them. Diff without #15: <https://github.com/matklad/libsyntax2/pull/16/commits/4244948c6b1a62bd0e1ef276d1f0cc22c36f6f66> Just `src/syntax_kinds.rs`: <https://github.com/matklad/libsyntax2/pull/16/commits/4244948c6b1a62bd0e1ef276d1f0cc22c36f6f66#diff-8f0d69eb4fe0148851505f787b6fd3bb>
-rw-r--r--src/bin/gen.rs56
-rw-r--r--src/lib.rs2
-rw-r--r--src/parser/event_parser/grammar/mod.rs1
-rw-r--r--src/parser/event_parser/parser.rs3
-rw-r--r--src/parser/mod.rs1
-rw-r--r--src/syntax_kinds.rs402
-rw-r--r--src/tree/mod.rs21
7 files changed, 243 insertions, 243 deletions
diff --git a/src/bin/gen.rs b/src/bin/gen.rs
index 8f6402f5c..4b8a5afec 100644
--- a/src/bin/gen.rs
+++ b/src/bin/gen.rs
@@ -29,8 +29,10 @@ impl Grammar {
29 29
30 fn to_syntax_kinds(&self) -> String { 30 fn to_syntax_kinds(&self) -> String {
31 let mut acc = String::new(); 31 let mut acc = String::new();
32 acc.push_str("// Generated from grammar.ron\n"); 32 acc.push_str("#![allow(bad_style, missing_docs, unreachable_pub)]\n");
33 acc.push_str("use tree::{SyntaxKind, SyntaxInfo};\n"); 33 acc.push_str("#![cfg_attr(rustfmt, rustfmt_skip)]\n");
34 acc.push_str("//! Generated from grammar.ron\n");
35 acc.push_str("use tree::SyntaxInfo;\n");
34 acc.push_str("\n"); 36 acc.push_str("\n");
35 37
36 let syntax_kinds: Vec<String> = self.keywords 38 let syntax_kinds: Vec<String> = self.keywords
@@ -40,41 +42,49 @@ impl Grammar {
40 .chain(self.nodes.iter().cloned()) 42 .chain(self.nodes.iter().cloned())
41 .collect(); 43 .collect();
42 44
43 for (idx, kind) in syntax_kinds.iter().enumerate() { 45 // enum SyntaxKind
44 let sname = scream(kind); 46 acc.push_str("/// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`.\n");
45 write!( 47 acc.push_str("#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]\n");
46 acc, 48 acc.push_str("#[repr(u32)]\n");
47 "pub const {}: SyntaxKind = SyntaxKind({});\n", 49 acc.push_str("pub enum SyntaxKind {\n");
48 sname, idx 50 for kind in syntax_kinds.iter() {
49 ).unwrap(); 51 write!(acc, " {},\n", scream(kind)).unwrap();
50 } 52 }
51 acc.push_str("\n"); 53 acc.push_str("\n");
52 write!( 54 acc.push_str(" TOMBSTONE = !0 - 1,\n");
53 acc, 55 acc.push_str(" EOF = !0,\n");
54 "static INFOS: [SyntaxInfo; {}] = [\n", 56 acc.push_str("}\n");
55 syntax_kinds.len() 57 acc.push_str("pub(crate) use self::SyntaxKind::*;\n");
56 ).unwrap(); 58 acc.push_str("\n");
59
60 // fn info
61 acc.push_str("impl SyntaxKind {\n");
62 acc.push_str(" pub(crate) fn info(self) -> &'static SyntaxInfo {\n");
63 acc.push_str(" match self {\n");
57 for kind in syntax_kinds.iter() { 64 for kind in syntax_kinds.iter() {
58 let sname = scream(kind); 65 let sname = scream(kind);
59 write!( 66 write!(
60 acc, 67 acc,
61 " SyntaxInfo {{ name: \"{sname}\" }},\n", 68 " {sname} => &SyntaxInfo {{ name: \"{sname}\" }},\n",
62 sname = sname 69 sname = sname
63 ).unwrap(); 70 ).unwrap();
64 } 71 }
65 acc.push_str("];\n"); 72 acc.push_str("\n");
73 acc.push_str(" TOMBSTONE => &SyntaxInfo { name: \"TOMBSTONE\" },\n");
74 acc.push_str(" EOF => &SyntaxInfo { name: \"EOF\" },\n");
75 acc.push_str(" }\n");
76 acc.push_str(" }\n");
77 acc.push_str("}\n");
66 acc.push_str("\n"); 78 acc.push_str("\n");
67 79
68 acc.push_str("pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {\n"); 80 // fn ident_to_keyword
69 acc.push_str(" &INFOS[kind.0 as usize]\n");
70 acc.push_str("}\n\n");
71 acc.push_str("pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {\n"); 81 acc.push_str("pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {\n");
72 acc.push_str(" match ident {\n"); 82 acc.push_str(" match ident {\n");
73 for kw in self.keywords.iter() { 83 for kw in self.keywords.iter() {
74 write!(acc, " {:?} => Some({}),\n", kw, kw_token(kw)).unwrap(); 84 write!(acc, " {:?} => Some({}),\n", kw, kw_token(kw)).unwrap();
75 } 85 }
76 acc.push_str(" _ => None,\n"); 86 acc.push_str(" _ => None,\n");
77 acc.push_str(" }\n"); 87 acc.push_str(" }\n");
78 acc.push_str("}\n"); 88 acc.push_str("}\n");
79 acc 89 acc
80 } 90 }
diff --git a/src/lib.rs b/src/lib.rs
index 87a9d11ea..ad333582c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -22,8 +22,6 @@ mod tree;
22mod lexer; 22mod lexer;
23mod parser; 23mod parser;
24 24
25#[cfg_attr(rustfmt, rustfmt_skip)]
26#[allow(missing_docs)]
27pub mod syntax_kinds; 25pub mod syntax_kinds;
28pub use text::{TextRange, TextUnit}; 26pub use text::{TextRange, TextUnit};
29pub use tree::{File, FileBuilder, Node, Sink, SyntaxKind, Token}; 27pub use tree::{File, FileBuilder, Node, Sink, SyntaxKind, Token};
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs
index c6ab1fbe2..82f8b7f3e 100644
--- a/src/parser/event_parser/grammar/mod.rs
+++ b/src/parser/event_parser/grammar/mod.rs
@@ -1,6 +1,5 @@
1use super::parser::{Parser, TokenSet}; 1use super::parser::{Parser, TokenSet};
2use SyntaxKind; 2use SyntaxKind;
3use tree::EOF;
4use syntax_kinds::*; 3use syntax_kinds::*;
5 4
6mod items; 5mod items;
diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs
index 5ba3071cb..573e3d73a 100644
--- a/src/parser/event_parser/parser.rs
+++ b/src/parser/event_parser/parser.rs
@@ -1,8 +1,7 @@
1use {SyntaxKind, TextUnit, Token}; 1use {SyntaxKind, TextUnit, Token};
2use super::Event; 2use super::Event;
3use super::super::is_insignificant; 3use super::super::is_insignificant;
4use syntax_kinds::{ERROR, L_CURLY, R_CURLY}; 4use SyntaxKind::{EOF, ERROR, L_CURLY, R_CURLY, TOMBSTONE};
5use tree::{EOF, TOMBSTONE};
6 5
7pub(crate) struct Marker { 6pub(crate) struct Marker {
8 pos: u32, 7 pos: u32,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 0f8f2ce0c..c5525ff9c 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -1,7 +1,6 @@
1use {File, FileBuilder, Sink, SyntaxKind, Token}; 1use {File, FileBuilder, Sink, SyntaxKind, Token};
2 2
3use syntax_kinds::*; 3use syntax_kinds::*;
4use tree::TOMBSTONE;
5 4
6mod event_parser; 5mod event_parser;
7use self::event_parser::Event; 6use self::event_parser::Event;
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs
index 5ab8b934b..aa19c2adf 100644
--- a/src/syntax_kinds.rs
+++ b/src/syntax_kinds.rs
@@ -1,201 +1,215 @@
1// Generated from grammar.ron 1#![allow(bad_style, missing_docs, unreachable_pub)]
2use tree::{SyntaxKind, SyntaxInfo}; 2#![cfg_attr(rustfmt, rustfmt_skip)]
3//! Generated from grammar.ron
4use tree::SyntaxInfo;
3 5
4pub const USE_KW: SyntaxKind = SyntaxKind(0); 6/// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`.
5pub const FN_KW: SyntaxKind = SyntaxKind(1); 7#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub const STRUCT_KW: SyntaxKind = SyntaxKind(2); 8#[repr(u32)]
7pub const ENUM_KW: SyntaxKind = SyntaxKind(3); 9pub enum SyntaxKind {
8pub const TRAIT_KW: SyntaxKind = SyntaxKind(4); 10 USE_KW,
9pub const IMPL_KW: SyntaxKind = SyntaxKind(5); 11 FN_KW,
10pub const TRUE_KW: SyntaxKind = SyntaxKind(6); 12 STRUCT_KW,
11pub const FALSE_KW: SyntaxKind = SyntaxKind(7); 13 ENUM_KW,
12pub const AS_KW: SyntaxKind = SyntaxKind(8); 14 TRAIT_KW,
13pub const EXTERN_KW: SyntaxKind = SyntaxKind(9); 15 IMPL_KW,
14pub const CRATE_KW: SyntaxKind = SyntaxKind(10); 16 TRUE_KW,
15pub const MOD_KW: SyntaxKind = SyntaxKind(11); 17 FALSE_KW,
16pub const PUB_KW: SyntaxKind = SyntaxKind(12); 18 AS_KW,
17pub const SELF_KW: SyntaxKind = SyntaxKind(13); 19 EXTERN_KW,
18pub const SUPER_KW: SyntaxKind = SyntaxKind(14); 20 CRATE_KW,
19pub const IN_KW: SyntaxKind = SyntaxKind(15); 21 MOD_KW,
20pub const WHERE_KW: SyntaxKind = SyntaxKind(16); 22 PUB_KW,
21pub const ERROR: SyntaxKind = SyntaxKind(17); 23 SELF_KW,
22pub const IDENT: SyntaxKind = SyntaxKind(18); 24 SUPER_KW,
23pub const UNDERSCORE: SyntaxKind = SyntaxKind(19); 25 IN_KW,
24pub const WHITESPACE: SyntaxKind = SyntaxKind(20); 26 WHERE_KW,
25pub const INT_NUMBER: SyntaxKind = SyntaxKind(21); 27 ERROR,
26pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(22); 28 IDENT,
27pub const SEMI: SyntaxKind = SyntaxKind(23); 29 UNDERSCORE,
28pub const COMMA: SyntaxKind = SyntaxKind(24); 30 WHITESPACE,
29pub const DOT: SyntaxKind = SyntaxKind(25); 31 INT_NUMBER,
30pub const DOTDOT: SyntaxKind = SyntaxKind(26); 32 FLOAT_NUMBER,
31pub const DOTDOTDOT: SyntaxKind = SyntaxKind(27); 33 SEMI,
32pub const DOTDOTEQ: SyntaxKind = SyntaxKind(28); 34 COMMA,
33pub const L_PAREN: SyntaxKind = SyntaxKind(29); 35 DOT,
34pub const R_PAREN: SyntaxKind = SyntaxKind(30); 36 DOTDOT,
35pub const L_CURLY: SyntaxKind = SyntaxKind(31); 37 DOTDOTDOT,
36pub const R_CURLY: SyntaxKind = SyntaxKind(32); 38 DOTDOTEQ,
37pub const L_BRACK: SyntaxKind = SyntaxKind(33); 39 L_PAREN,
38pub const R_BRACK: SyntaxKind = SyntaxKind(34); 40 R_PAREN,
39pub const L_ANGLE: SyntaxKind = SyntaxKind(35); 41 L_CURLY,
40pub const R_ANGLE: SyntaxKind = SyntaxKind(36); 42 R_CURLY,
41pub const AT: SyntaxKind = SyntaxKind(37); 43 L_BRACK,
42pub const POUND: SyntaxKind = SyntaxKind(38); 44 R_BRACK,
43pub const TILDE: SyntaxKind = SyntaxKind(39); 45 L_ANGLE,
44pub const QUESTION: SyntaxKind = SyntaxKind(40); 46 R_ANGLE,
45pub const COLON: SyntaxKind = SyntaxKind(41); 47 AT,
46pub const COLONCOLON: SyntaxKind = SyntaxKind(42); 48 POUND,
47pub const DOLLAR: SyntaxKind = SyntaxKind(43); 49 TILDE,
48pub const EQ: SyntaxKind = SyntaxKind(44); 50 QUESTION,
49pub const EQEQ: SyntaxKind = SyntaxKind(45); 51 COLON,
50pub const FAT_ARROW: SyntaxKind = SyntaxKind(46); 52 COLONCOLON,
51pub const NEQ: SyntaxKind = SyntaxKind(47); 53 DOLLAR,
52pub const EXCL: SyntaxKind = SyntaxKind(48); 54 EQ,
53pub const LIFETIME: SyntaxKind = SyntaxKind(49); 55 EQEQ,
54pub const CHAR: SyntaxKind = SyntaxKind(50); 56 FAT_ARROW,
55pub const BYTE: SyntaxKind = SyntaxKind(51); 57 NEQ,
56pub const STRING: SyntaxKind = SyntaxKind(52); 58 EXCL,
57pub const RAW_STRING: SyntaxKind = SyntaxKind(53); 59 LIFETIME,
58pub const BYTE_STRING: SyntaxKind = SyntaxKind(54); 60 CHAR,
59pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(55); 61 BYTE,
60pub const PLUS: SyntaxKind = SyntaxKind(56); 62 STRING,
61pub const MINUS: SyntaxKind = SyntaxKind(57); 63 RAW_STRING,
62pub const STAR: SyntaxKind = SyntaxKind(58); 64 BYTE_STRING,
63pub const SLASH: SyntaxKind = SyntaxKind(59); 65 RAW_BYTE_STRING,
64pub const CARET: SyntaxKind = SyntaxKind(60); 66 PLUS,
65pub const PERCENT: SyntaxKind = SyntaxKind(61); 67 MINUS,
66pub const AMPERSAND: SyntaxKind = SyntaxKind(62); 68 STAR,
67pub const PIPE: SyntaxKind = SyntaxKind(63); 69 SLASH,
68pub const THIN_ARROW: SyntaxKind = SyntaxKind(64); 70 CARET,
69pub const COMMENT: SyntaxKind = SyntaxKind(65); 71 PERCENT,
70pub const DOC_COMMENT: SyntaxKind = SyntaxKind(66); 72 AMPERSAND,
71pub const SHEBANG: SyntaxKind = SyntaxKind(67); 73 PIPE,
72pub const FILE: SyntaxKind = SyntaxKind(68); 74 THIN_ARROW,
73pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(69); 75 COMMENT,
74pub const NAMED_FIELD: SyntaxKind = SyntaxKind(70); 76 DOC_COMMENT,
75pub const POS_FIELD: SyntaxKind = SyntaxKind(71); 77 SHEBANG,
76pub const FN_ITEM: SyntaxKind = SyntaxKind(72); 78 FILE,
77pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(73); 79 STRUCT_ITEM,
78pub const ATTR: SyntaxKind = SyntaxKind(74); 80 NAMED_FIELD,
79pub const META_ITEM: SyntaxKind = SyntaxKind(75); 81 POS_FIELD,
80pub const MOD_ITEM: SyntaxKind = SyntaxKind(76); 82 FN_ITEM,
81pub const USE_ITEM: SyntaxKind = SyntaxKind(77); 83 EXTERN_CRATE_ITEM,
82pub const USE_TREE: SyntaxKind = SyntaxKind(78); 84 ATTR,
83pub const PATH: SyntaxKind = SyntaxKind(79); 85 META_ITEM,
84pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(80); 86 MOD_ITEM,
85pub const LITERAL: SyntaxKind = SyntaxKind(81); 87 USE_ITEM,
86pub const ALIAS: SyntaxKind = SyntaxKind(82); 88 USE_TREE,
87pub const VISIBILITY: SyntaxKind = SyntaxKind(83); 89 PATH,
90 PATH_SEGMENT,
91 LITERAL,
92 ALIAS,
93 VISIBILITY,
88 94
89static INFOS: [SyntaxInfo; 84] = [ 95 TOMBSTONE = !0 - 1,
90 SyntaxInfo { name: "USE_KW" }, 96 EOF = !0,
91 SyntaxInfo { name: "FN_KW" }, 97}
92 SyntaxInfo { name: "STRUCT_KW" }, 98pub(crate) use self::SyntaxKind::*;
93 SyntaxInfo { name: "ENUM_KW" }, 99
94 SyntaxInfo { name: "TRAIT_KW" }, 100impl SyntaxKind {
95 SyntaxInfo { name: "IMPL_KW" }, 101 pub(crate) fn info(self) -> &'static SyntaxInfo {
96 SyntaxInfo { name: "TRUE_KW" }, 102 match self {
97 SyntaxInfo { name: "FALSE_KW" }, 103 USE_KW => &SyntaxInfo { name: "USE_KW" },
98 SyntaxInfo { name: "AS_KW" }, 104 FN_KW => &SyntaxInfo { name: "FN_KW" },
99 SyntaxInfo { name: "EXTERN_KW" }, 105 STRUCT_KW => &SyntaxInfo { name: "STRUCT_KW" },
100 SyntaxInfo { name: "CRATE_KW" }, 106 ENUM_KW => &SyntaxInfo { name: "ENUM_KW" },
101 SyntaxInfo { name: "MOD_KW" }, 107 TRAIT_KW => &SyntaxInfo { name: "TRAIT_KW" },
102 SyntaxInfo { name: "PUB_KW" }, 108 IMPL_KW => &SyntaxInfo { name: "IMPL_KW" },
103 SyntaxInfo { name: "SELF_KW" }, 109 TRUE_KW => &SyntaxInfo { name: "TRUE_KW" },
104 SyntaxInfo { name: "SUPER_KW" }, 110 FALSE_KW => &SyntaxInfo { name: "FALSE_KW" },
105 SyntaxInfo { name: "IN_KW" }, 111 AS_KW => &SyntaxInfo { name: "AS_KW" },
106 SyntaxInfo { name: "WHERE_KW" }, 112 EXTERN_KW => &SyntaxInfo { name: "EXTERN_KW" },
107 SyntaxInfo { name: "ERROR" }, 113 CRATE_KW => &SyntaxInfo { name: "CRATE_KW" },
108 SyntaxInfo { name: "IDENT" }, 114 MOD_KW => &SyntaxInfo { name: "MOD_KW" },
109 SyntaxInfo { name: "UNDERSCORE" }, 115 PUB_KW => &SyntaxInfo { name: "PUB_KW" },
110 SyntaxInfo { name: "WHITESPACE" }, 116 SELF_KW => &SyntaxInfo { name: "SELF_KW" },
111 SyntaxInfo { name: "INT_NUMBER" }, 117 SUPER_KW => &SyntaxInfo { name: "SUPER_KW" },
112 SyntaxInfo { name: "FLOAT_NUMBER" }, 118 IN_KW => &SyntaxInfo { name: "IN_KW" },
113 SyntaxInfo { name: "SEMI" }, 119 WHERE_KW => &SyntaxInfo { name: "WHERE_KW" },
114 SyntaxInfo { name: "COMMA" }, 120 ERROR => &SyntaxInfo { name: "ERROR" },
115 SyntaxInfo { name: "DOT" }, 121 IDENT => &SyntaxInfo { name: "IDENT" },
116 SyntaxInfo { name: "DOTDOT" }, 122 UNDERSCORE => &SyntaxInfo { name: "UNDERSCORE" },
117 SyntaxInfo { name: "DOTDOTDOT" }, 123 WHITESPACE => &SyntaxInfo { name: "WHITESPACE" },
118 SyntaxInfo { name: "DOTDOTEQ" }, 124 INT_NUMBER => &SyntaxInfo { name: "INT_NUMBER" },
119 SyntaxInfo { name: "L_PAREN" }, 125 FLOAT_NUMBER => &SyntaxInfo { name: "FLOAT_NUMBER" },
120 SyntaxInfo { name: "R_PAREN" }, 126 SEMI => &SyntaxInfo { name: "SEMI" },
121 SyntaxInfo { name: "L_CURLY" }, 127 COMMA => &SyntaxInfo { name: "COMMA" },
122 SyntaxInfo { name: "R_CURLY" }, 128 DOT => &SyntaxInfo { name: "DOT" },
123 SyntaxInfo { name: "L_BRACK" }, 129 DOTDOT => &SyntaxInfo { name: "DOTDOT" },
124 SyntaxInfo { name: "R_BRACK" }, 130 DOTDOTDOT => &SyntaxInfo { name: "DOTDOTDOT" },
125 SyntaxInfo { name: "L_ANGLE" }, 131 DOTDOTEQ => &SyntaxInfo { name: "DOTDOTEQ" },
126 SyntaxInfo { name: "R_ANGLE" }, 132 L_PAREN => &SyntaxInfo { name: "L_PAREN" },
127 SyntaxInfo { name: "AT" }, 133 R_PAREN => &SyntaxInfo { name: "R_PAREN" },
128 SyntaxInfo { name: "POUND" }, 134 L_CURLY => &SyntaxInfo { name: "L_CURLY" },
129 SyntaxInfo { name: "TILDE" }, 135 R_CURLY => &SyntaxInfo { name: "R_CURLY" },
130 SyntaxInfo { name: "QUESTION" }, 136 L_BRACK => &SyntaxInfo { name: "L_BRACK" },
131 SyntaxInfo { name: "COLON" }, 137 R_BRACK => &SyntaxInfo { name: "R_BRACK" },
132 SyntaxInfo { name: "COLONCOLON" }, 138 L_ANGLE => &SyntaxInfo { name: "L_ANGLE" },
133 SyntaxInfo { name: "DOLLAR" }, 139 R_ANGLE => &SyntaxInfo { name: "R_ANGLE" },
134 SyntaxInfo { name: "EQ" }, 140 AT => &SyntaxInfo { name: "AT" },
135 SyntaxInfo { name: "EQEQ" }, 141 POUND => &SyntaxInfo { name: "POUND" },
136 SyntaxInfo { name: "FAT_ARROW" }, 142 TILDE => &SyntaxInfo { name: "TILDE" },
137 SyntaxInfo { name: "NEQ" }, 143 QUESTION => &SyntaxInfo { name: "QUESTION" },
138 SyntaxInfo { name: "EXCL" }, 144 COLON => &SyntaxInfo { name: "COLON" },
139 SyntaxInfo { name: "LIFETIME" }, 145 COLONCOLON => &SyntaxInfo { name: "COLONCOLON" },
140 SyntaxInfo { name: "CHAR" }, 146 DOLLAR => &SyntaxInfo { name: "DOLLAR" },
141 SyntaxInfo { name: "BYTE" }, 147 EQ => &SyntaxInfo { name: "EQ" },
142 SyntaxInfo { name: "STRING" }, 148 EQEQ => &SyntaxInfo { name: "EQEQ" },
143 SyntaxInfo { name: "RAW_STRING" }, 149 FAT_ARROW => &SyntaxInfo { name: "FAT_ARROW" },
144 SyntaxInfo { name: "BYTE_STRING" }, 150 NEQ => &SyntaxInfo { name: "NEQ" },
145 SyntaxInfo { name: "RAW_BYTE_STRING" }, 151 EXCL => &SyntaxInfo { name: "EXCL" },
146 SyntaxInfo { name: "PLUS" }, 152 LIFETIME => &SyntaxInfo { name: "LIFETIME" },
147 SyntaxInfo { name: "MINUS" }, 153 CHAR => &SyntaxInfo { name: "CHAR" },
148 SyntaxInfo { name: "STAR" }, 154 BYTE => &SyntaxInfo { name: "BYTE" },
149 SyntaxInfo { name: "SLASH" }, 155 STRING => &SyntaxInfo { name: "STRING" },
150 SyntaxInfo { name: "CARET" }, 156 RAW_STRING => &SyntaxInfo { name: "RAW_STRING" },
151 SyntaxInfo { name: "PERCENT" }, 157 BYTE_STRING => &SyntaxInfo { name: "BYTE_STRING" },
152 SyntaxInfo { name: "AMPERSAND" }, 158 RAW_BYTE_STRING => &SyntaxInfo { name: "RAW_BYTE_STRING" },
153 SyntaxInfo { name: "PIPE" }, 159 PLUS => &SyntaxInfo { name: "PLUS" },
154 SyntaxInfo { name: "THIN_ARROW" }, 160 MINUS => &SyntaxInfo { name: "MINUS" },
155 SyntaxInfo { name: "COMMENT" }, 161 STAR => &SyntaxInfo { name: "STAR" },
156 SyntaxInfo { name: "DOC_COMMENT" }, 162 SLASH => &SyntaxInfo { name: "SLASH" },
157 SyntaxInfo { name: "SHEBANG" }, 163 CARET => &SyntaxInfo { name: "CARET" },
158 SyntaxInfo { name: "FILE" }, 164 PERCENT => &SyntaxInfo { name: "PERCENT" },
159 SyntaxInfo { name: "STRUCT_ITEM" }, 165 AMPERSAND => &SyntaxInfo { name: "AMPERSAND" },
160 SyntaxInfo { name: "NAMED_FIELD" }, 166 PIPE => &SyntaxInfo { name: "PIPE" },
161 SyntaxInfo { name: "POS_FIELD" }, 167 THIN_ARROW => &SyntaxInfo { name: "THIN_ARROW" },
162 SyntaxInfo { name: "FN_ITEM" }, 168 COMMENT => &SyntaxInfo { name: "COMMENT" },
163 SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, 169 DOC_COMMENT => &SyntaxInfo { name: "DOC_COMMENT" },
164 SyntaxInfo { name: "ATTR" }, 170 SHEBANG => &SyntaxInfo { name: "SHEBANG" },
165 SyntaxInfo { name: "META_ITEM" }, 171 FILE => &SyntaxInfo { name: "FILE" },
166 SyntaxInfo { name: "MOD_ITEM" }, 172 STRUCT_ITEM => &SyntaxInfo { name: "STRUCT_ITEM" },
167 SyntaxInfo { name: "USE_ITEM" }, 173 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
168 SyntaxInfo { name: "USE_TREE" }, 174 POS_FIELD => &SyntaxInfo { name: "POS_FIELD" },
169 SyntaxInfo { name: "PATH" }, 175 FN_ITEM => &SyntaxInfo { name: "FN_ITEM" },
170 SyntaxInfo { name: "PATH_SEGMENT" }, 176 EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" },
171 SyntaxInfo { name: "LITERAL" }, 177 ATTR => &SyntaxInfo { name: "ATTR" },
172 SyntaxInfo { name: "ALIAS" }, 178 META_ITEM => &SyntaxInfo { name: "META_ITEM" },
173 SyntaxInfo { name: "VISIBILITY" }, 179 MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" },
174]; 180 USE_ITEM => &SyntaxInfo { name: "USE_ITEM" },
181 USE_TREE => &SyntaxInfo { name: "USE_TREE" },
182 PATH => &SyntaxInfo { name: "PATH" },
183 PATH_SEGMENT => &SyntaxInfo { name: "PATH_SEGMENT" },
184 LITERAL => &SyntaxInfo { name: "LITERAL" },
185 ALIAS => &SyntaxInfo { name: "ALIAS" },
186 VISIBILITY => &SyntaxInfo { name: "VISIBILITY" },
175 187
176pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { 188 TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" },
177 &INFOS[kind.0 as usize] 189 EOF => &SyntaxInfo { name: "EOF" },
190 }
191 }
178} 192}
179 193
180pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> { 194pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {
181 match ident { 195 match ident {
182 "use" => Some(USE_KW), 196 "use" => Some(USE_KW),
183 "fn" => Some(FN_KW), 197 "fn" => Some(FN_KW),
184 "struct" => Some(STRUCT_KW), 198 "struct" => Some(STRUCT_KW),
185 "enum" => Some(ENUM_KW), 199 "enum" => Some(ENUM_KW),
186 "trait" => Some(TRAIT_KW), 200 "trait" => Some(TRAIT_KW),
187 "impl" => Some(IMPL_KW), 201 "impl" => Some(IMPL_KW),
188 "true" => Some(TRUE_KW), 202 "true" => Some(TRUE_KW),
189 "false" => Some(FALSE_KW), 203 "false" => Some(FALSE_KW),
190 "as" => Some(AS_KW), 204 "as" => Some(AS_KW),
191 "extern" => Some(EXTERN_KW), 205 "extern" => Some(EXTERN_KW),
192 "crate" => Some(CRATE_KW), 206 "crate" => Some(CRATE_KW),
193 "mod" => Some(MOD_KW), 207 "mod" => Some(MOD_KW),
194 "pub" => Some(PUB_KW), 208 "pub" => Some(PUB_KW),
195 "self" => Some(SELF_KW), 209 "self" => Some(SELF_KW),
196 "super" => Some(SUPER_KW), 210 "super" => Some(SUPER_KW),
197 "in" => Some(IN_KW), 211 "in" => Some(IN_KW),
198 "where" => Some(WHERE_KW), 212 "where" => Some(WHERE_KW),
199 _ => None, 213 _ => None,
200 } 214 }
201} 215}
diff --git a/src/tree/mod.rs b/src/tree/mod.rs
index aaf048c73..43bda480d 100644
--- a/src/tree/mod.rs
+++ b/src/tree/mod.rs
@@ -1,5 +1,4 @@
1use text::{TextRange, TextUnit}; 1use text::{TextRange, TextUnit};
2use syntax_kinds::syntax_info;
3 2
4use std::fmt; 3use std::fmt;
5use std::cmp; 4use std::cmp;
@@ -7,25 +6,7 @@ use std::cmp;
7mod file_builder; 6mod file_builder;
8pub use self::file_builder::{FileBuilder, Sink}; 7pub use self::file_builder::{FileBuilder, Sink};
9 8
10/// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. 9pub use syntax_kinds::SyntaxKind;
11#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub struct SyntaxKind(pub(crate) u32);
13
14pub(crate) const EOF: SyntaxKind = SyntaxKind(!0);
15pub(crate) const EOF_INFO: SyntaxInfo = SyntaxInfo { name: "EOF" };
16
17pub(crate) const TOMBSTONE: SyntaxKind = SyntaxKind(!0 - 1);
18pub(crate) const TOMBSTONE_INFO: SyntaxInfo = SyntaxInfo { name: "TOMBSTONE" };
19
20impl SyntaxKind {
21 fn info(self) -> &'static SyntaxInfo {
22 match self {
23 EOF => &EOF_INFO,
24 TOMBSTONE => &TOMBSTONE_INFO,
25 _ => syntax_info(self),
26 }
27 }
28}
29 10
30impl fmt::Debug for SyntaxKind { 11impl fmt::Debug for SyntaxKind {
31 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 12 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {