diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/gen.rs | 56 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/mod.rs | 1 | ||||
-rw-r--r-- | src/parser/event_parser/parser.rs | 3 | ||||
-rw-r--r-- | src/parser/mod.rs | 1 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 402 | ||||
-rw-r--r-- | src/tree/mod.rs | 21 |
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 2d8ddade0..0ea8f6a63 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
@@ -22,8 +22,6 @@ mod tree; | |||
22 | mod lexer; | 22 | mod lexer; |
23 | mod parser; | 23 | mod parser; |
24 | 24 | ||
25 | #[cfg_attr(rustfmt, rustfmt_skip)] | ||
26 | #[allow(missing_docs)] | ||
27 | pub mod syntax_kinds; | 25 | pub mod syntax_kinds; |
28 | pub use text::{TextRange, TextUnit}; | 26 | pub use text::{TextRange, TextUnit}; |
29 | pub use tree::{File, Node, SyntaxKind, Token}; | 27 | pub use tree::{File, Node, 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 @@ | |||
1 | use super::parser::{Parser, TokenSet}; | 1 | use super::parser::{Parser, TokenSet}; |
2 | use SyntaxKind; | 2 | use SyntaxKind; |
3 | use tree::EOF; | ||
4 | use syntax_kinds::*; | 3 | use syntax_kinds::*; |
5 | 4 | ||
6 | mod items; | 5 | mod 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 @@ | |||
1 | use {SyntaxKind, TextUnit, Token}; | 1 | use {SyntaxKind, TextUnit, Token}; |
2 | use super::Event; | 2 | use super::Event; |
3 | use super::super::is_insignificant; | 3 | use super::super::is_insignificant; |
4 | use syntax_kinds::{ERROR, L_CURLY, R_CURLY}; | 4 | use SyntaxKind::{EOF, ERROR, L_CURLY, R_CURLY, TOMBSTONE}; |
5 | use tree::{EOF, TOMBSTONE}; | ||
6 | 5 | ||
7 | pub(crate) struct Marker { | 6 | pub(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 @@ | |||
1 | use {File, FileBuilder, Sink, SyntaxKind, Token}; | 1 | use {File, FileBuilder, Sink, SyntaxKind, Token}; |
2 | 2 | ||
3 | use syntax_kinds::*; | 3 | use syntax_kinds::*; |
4 | use tree::TOMBSTONE; | ||
5 | 4 | ||
6 | mod event_parser; | 5 | mod event_parser; |
7 | use self::event_parser::Event; | 6 | use 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)] |
2 | use tree::{SyntaxKind, SyntaxInfo}; | 2 | #![cfg_attr(rustfmt, rustfmt_skip)] |
3 | //! Generated from grammar.ron | ||
4 | use tree::SyntaxInfo; | ||
3 | 5 | ||
4 | pub const USE_KW: SyntaxKind = SyntaxKind(0); | 6 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. |
5 | pub const FN_KW: SyntaxKind = SyntaxKind(1); | 7 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
6 | pub const STRUCT_KW: SyntaxKind = SyntaxKind(2); | 8 | #[repr(u32)] |
7 | pub const ENUM_KW: SyntaxKind = SyntaxKind(3); | 9 | pub enum SyntaxKind { |
8 | pub const TRAIT_KW: SyntaxKind = SyntaxKind(4); | 10 | USE_KW, |
9 | pub const IMPL_KW: SyntaxKind = SyntaxKind(5); | 11 | FN_KW, |
10 | pub const TRUE_KW: SyntaxKind = SyntaxKind(6); | 12 | STRUCT_KW, |
11 | pub const FALSE_KW: SyntaxKind = SyntaxKind(7); | 13 | ENUM_KW, |
12 | pub const AS_KW: SyntaxKind = SyntaxKind(8); | 14 | TRAIT_KW, |
13 | pub const EXTERN_KW: SyntaxKind = SyntaxKind(9); | 15 | IMPL_KW, |
14 | pub const CRATE_KW: SyntaxKind = SyntaxKind(10); | 16 | TRUE_KW, |
15 | pub const MOD_KW: SyntaxKind = SyntaxKind(11); | 17 | FALSE_KW, |
16 | pub const PUB_KW: SyntaxKind = SyntaxKind(12); | 18 | AS_KW, |
17 | pub const SELF_KW: SyntaxKind = SyntaxKind(13); | 19 | EXTERN_KW, |
18 | pub const SUPER_KW: SyntaxKind = SyntaxKind(14); | 20 | CRATE_KW, |
19 | pub const IN_KW: SyntaxKind = SyntaxKind(15); | 21 | MOD_KW, |
20 | pub const WHERE_KW: SyntaxKind = SyntaxKind(16); | 22 | PUB_KW, |
21 | pub const ERROR: SyntaxKind = SyntaxKind(17); | 23 | SELF_KW, |
22 | pub const IDENT: SyntaxKind = SyntaxKind(18); | 24 | SUPER_KW, |
23 | pub const UNDERSCORE: SyntaxKind = SyntaxKind(19); | 25 | IN_KW, |
24 | pub const WHITESPACE: SyntaxKind = SyntaxKind(20); | 26 | WHERE_KW, |
25 | pub const INT_NUMBER: SyntaxKind = SyntaxKind(21); | 27 | ERROR, |
26 | pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(22); | 28 | IDENT, |
27 | pub const SEMI: SyntaxKind = SyntaxKind(23); | 29 | UNDERSCORE, |
28 | pub const COMMA: SyntaxKind = SyntaxKind(24); | 30 | WHITESPACE, |
29 | pub const DOT: SyntaxKind = SyntaxKind(25); | 31 | INT_NUMBER, |
30 | pub const DOTDOT: SyntaxKind = SyntaxKind(26); | 32 | FLOAT_NUMBER, |
31 | pub const DOTDOTDOT: SyntaxKind = SyntaxKind(27); | 33 | SEMI, |
32 | pub const DOTDOTEQ: SyntaxKind = SyntaxKind(28); | 34 | COMMA, |
33 | pub const L_PAREN: SyntaxKind = SyntaxKind(29); | 35 | DOT, |
34 | pub const R_PAREN: SyntaxKind = SyntaxKind(30); | 36 | DOTDOT, |
35 | pub const L_CURLY: SyntaxKind = SyntaxKind(31); | 37 | DOTDOTDOT, |
36 | pub const R_CURLY: SyntaxKind = SyntaxKind(32); | 38 | DOTDOTEQ, |
37 | pub const L_BRACK: SyntaxKind = SyntaxKind(33); | 39 | L_PAREN, |
38 | pub const R_BRACK: SyntaxKind = SyntaxKind(34); | 40 | R_PAREN, |
39 | pub const L_ANGLE: SyntaxKind = SyntaxKind(35); | 41 | L_CURLY, |
40 | pub const R_ANGLE: SyntaxKind = SyntaxKind(36); | 42 | R_CURLY, |
41 | pub const AT: SyntaxKind = SyntaxKind(37); | 43 | L_BRACK, |
42 | pub const POUND: SyntaxKind = SyntaxKind(38); | 44 | R_BRACK, |
43 | pub const TILDE: SyntaxKind = SyntaxKind(39); | 45 | L_ANGLE, |
44 | pub const QUESTION: SyntaxKind = SyntaxKind(40); | 46 | R_ANGLE, |
45 | pub const COLON: SyntaxKind = SyntaxKind(41); | 47 | AT, |
46 | pub const COLONCOLON: SyntaxKind = SyntaxKind(42); | 48 | POUND, |
47 | pub const DOLLAR: SyntaxKind = SyntaxKind(43); | 49 | TILDE, |
48 | pub const EQ: SyntaxKind = SyntaxKind(44); | 50 | QUESTION, |
49 | pub const EQEQ: SyntaxKind = SyntaxKind(45); | 51 | COLON, |
50 | pub const FAT_ARROW: SyntaxKind = SyntaxKind(46); | 52 | COLONCOLON, |
51 | pub const NEQ: SyntaxKind = SyntaxKind(47); | 53 | DOLLAR, |
52 | pub const EXCL: SyntaxKind = SyntaxKind(48); | 54 | EQ, |
53 | pub const LIFETIME: SyntaxKind = SyntaxKind(49); | 55 | EQEQ, |
54 | pub const CHAR: SyntaxKind = SyntaxKind(50); | 56 | FAT_ARROW, |
55 | pub const BYTE: SyntaxKind = SyntaxKind(51); | 57 | NEQ, |
56 | pub const STRING: SyntaxKind = SyntaxKind(52); | 58 | EXCL, |
57 | pub const RAW_STRING: SyntaxKind = SyntaxKind(53); | 59 | LIFETIME, |
58 | pub const BYTE_STRING: SyntaxKind = SyntaxKind(54); | 60 | CHAR, |
59 | pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(55); | 61 | BYTE, |
60 | pub const PLUS: SyntaxKind = SyntaxKind(56); | 62 | STRING, |
61 | pub const MINUS: SyntaxKind = SyntaxKind(57); | 63 | RAW_STRING, |
62 | pub const STAR: SyntaxKind = SyntaxKind(58); | 64 | BYTE_STRING, |
63 | pub const SLASH: SyntaxKind = SyntaxKind(59); | 65 | RAW_BYTE_STRING, |
64 | pub const CARET: SyntaxKind = SyntaxKind(60); | 66 | PLUS, |
65 | pub const PERCENT: SyntaxKind = SyntaxKind(61); | 67 | MINUS, |
66 | pub const AMPERSAND: SyntaxKind = SyntaxKind(62); | 68 | STAR, |
67 | pub const PIPE: SyntaxKind = SyntaxKind(63); | 69 | SLASH, |
68 | pub const THIN_ARROW: SyntaxKind = SyntaxKind(64); | 70 | CARET, |
69 | pub const COMMENT: SyntaxKind = SyntaxKind(65); | 71 | PERCENT, |
70 | pub const DOC_COMMENT: SyntaxKind = SyntaxKind(66); | 72 | AMPERSAND, |
71 | pub const SHEBANG: SyntaxKind = SyntaxKind(67); | 73 | PIPE, |
72 | pub const FILE: SyntaxKind = SyntaxKind(68); | 74 | THIN_ARROW, |
73 | pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(69); | 75 | COMMENT, |
74 | pub const NAMED_FIELD: SyntaxKind = SyntaxKind(70); | 76 | DOC_COMMENT, |
75 | pub const POS_FIELD: SyntaxKind = SyntaxKind(71); | 77 | SHEBANG, |
76 | pub const FN_ITEM: SyntaxKind = SyntaxKind(72); | 78 | FILE, |
77 | pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(73); | 79 | STRUCT_ITEM, |
78 | pub const ATTR: SyntaxKind = SyntaxKind(74); | 80 | NAMED_FIELD, |
79 | pub const META_ITEM: SyntaxKind = SyntaxKind(75); | 81 | POS_FIELD, |
80 | pub const MOD_ITEM: SyntaxKind = SyntaxKind(76); | 82 | FN_ITEM, |
81 | pub const USE_ITEM: SyntaxKind = SyntaxKind(77); | 83 | EXTERN_CRATE_ITEM, |
82 | pub const USE_TREE: SyntaxKind = SyntaxKind(78); | 84 | ATTR, |
83 | pub const PATH: SyntaxKind = SyntaxKind(79); | 85 | META_ITEM, |
84 | pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(80); | 86 | MOD_ITEM, |
85 | pub const LITERAL: SyntaxKind = SyntaxKind(81); | 87 | USE_ITEM, |
86 | pub const ALIAS: SyntaxKind = SyntaxKind(82); | 88 | USE_TREE, |
87 | pub const VISIBILITY: SyntaxKind = SyntaxKind(83); | 89 | PATH, |
90 | PATH_SEGMENT, | ||
91 | LITERAL, | ||
92 | ALIAS, | ||
93 | VISIBILITY, | ||
88 | 94 | ||
89 | static 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" }, | 98 | pub(crate) use self::SyntaxKind::*; |
93 | SyntaxInfo { name: "ENUM_KW" }, | 99 | |
94 | SyntaxInfo { name: "TRAIT_KW" }, | 100 | impl 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 | ||
176 | pub(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 | ||
180 | pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> { | 194 | pub(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 30a4b33a9..795f23f42 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | use text::{TextRange, TextUnit}; | 1 | use text::{TextRange, TextUnit}; |
2 | use syntax_kinds::syntax_info; | ||
3 | 2 | ||
4 | use std::fmt; | 3 | use std::fmt; |
5 | use std::cmp; | 4 | use std::cmp; |
@@ -7,25 +6,7 @@ use std::cmp; | |||
7 | mod file_builder; | 6 | mod file_builder; |
8 | pub(crate) use self::file_builder::{FileBuilder, Sink}; | 7 | pub(crate) use self::file_builder::{FileBuilder, Sink}; |
9 | 8 | ||
10 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. | 9 | pub use syntax_kinds::SyntaxKind; |
11 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
12 | pub struct SyntaxKind(pub(crate) u32); | ||
13 | |||
14 | pub(crate) const EOF: SyntaxKind = SyntaxKind(!0); | ||
15 | pub(crate) const EOF_INFO: SyntaxInfo = SyntaxInfo { name: "EOF" }; | ||
16 | |||
17 | pub(crate) const TOMBSTONE: SyntaxKind = SyntaxKind(!0 - 1); | ||
18 | pub(crate) const TOMBSTONE_INFO: SyntaxInfo = SyntaxInfo { name: "TOMBSTONE" }; | ||
19 | |||
20 | impl 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 | ||
30 | impl fmt::Debug for SyntaxKind { | 11 | impl fmt::Debug for SyntaxKind { |
31 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 12 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |