diff options
-rw-r--r-- | crates/ra_ide_api/src/extend_selection.rs | 3 | ||||
-rw-r--r-- | crates/ra_parser/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind.rs | 1 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 95 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs.tera | 14 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 1 |
6 files changed, 114 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 7293ba359..163fa8c3c 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs | |||
@@ -4,6 +4,7 @@ use ra_syntax::{ | |||
4 | algo::{find_covering_element, find_token_at_offset, TokenAtOffset}, | 4 | algo::{find_covering_element, find_token_at_offset, TokenAtOffset}, |
5 | SyntaxKind::*, SyntaxToken, | 5 | SyntaxKind::*, SyntaxToken, |
6 | ast::{self, AstNode, AstToken}, | 6 | ast::{self, AstNode, AstToken}, |
7 | T | ||
7 | }; | 8 | }; |
8 | 9 | ||
9 | use crate::{FileRange, db::RootDatabase}; | 10 | use crate::{FileRange, db::RootDatabase}; |
@@ -135,7 +136,7 @@ fn pick_best<'a>(l: SyntaxToken<'a>, r: SyntaxToken<'a>) -> SyntaxToken<'a> { | |||
135 | fn priority(n: SyntaxToken) -> usize { | 136 | fn priority(n: SyntaxToken) -> usize { |
136 | match n.kind() { | 137 | match n.kind() { |
137 | WHITESPACE => 0, | 138 | WHITESPACE => 0, |
138 | IDENT | SELF_KW | SUPER_KW | CRATE_KW | LIFETIME => 2, | 139 | IDENT | T![self] | T![super] | T![crate] | LIFETIME => 2, |
139 | _ => 1, | 140 | _ => 1, |
140 | } | 141 | } |
141 | } | 142 | } |
diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 970d699c0..697d1b794 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs | |||
@@ -14,6 +14,7 @@ | |||
14 | 14 | ||
15 | #[macro_use] | 15 | #[macro_use] |
16 | mod token_set; | 16 | mod token_set; |
17 | #[macro_use] | ||
17 | mod syntax_kind; | 18 | mod syntax_kind; |
18 | mod event; | 19 | mod event; |
19 | mod parser; | 20 | mod parser; |
diff --git a/crates/ra_parser/src/syntax_kind.rs b/crates/ra_parser/src/syntax_kind.rs index a2353317f..00faa7799 100644 --- a/crates/ra_parser/src/syntax_kind.rs +++ b/crates/ra_parser/src/syntax_kind.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | #[macro_use] | ||
1 | mod generated; | 2 | mod generated; |
2 | 3 | ||
3 | use std::fmt; | 4 | use std::fmt; |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 6f984aea1..1a08cc6eb 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -241,6 +241,101 @@ pub enum SyntaxKind { | |||
241 | } | 241 | } |
242 | use self::SyntaxKind::*; | 242 | use self::SyntaxKind::*; |
243 | 243 | ||
244 | #[macro_export] | ||
245 | macro_rules! T { | ||
246 | (;) => { $crate::SyntaxKind::SEMI }; | ||
247 | (,) => { $crate::SyntaxKind::COMMA }; | ||
248 | (() => { $crate::SyntaxKind::L_PAREN }; | ||
249 | ()) => { $crate::SyntaxKind::R_PAREN }; | ||
250 | ('{') => { $crate::SyntaxKind::L_CURLY }; | ||
251 | ('}') => { $crate::SyntaxKind::R_CURLY }; | ||
252 | ('[') => { $crate::SyntaxKind::L_BRACK }; | ||
253 | (']') => { $crate::SyntaxKind::R_BRACK }; | ||
254 | (<) => { $crate::SyntaxKind::L_ANGLE }; | ||
255 | (>) => { $crate::SyntaxKind::R_ANGLE }; | ||
256 | (@) => { $crate::SyntaxKind::AT }; | ||
257 | (#) => { $crate::SyntaxKind::POUND }; | ||
258 | (~) => { $crate::SyntaxKind::TILDE }; | ||
259 | (?) => { $crate::SyntaxKind::QUESTION }; | ||
260 | ($) => { $crate::SyntaxKind::DOLLAR }; | ||
261 | (&) => { $crate::SyntaxKind::AMP }; | ||
262 | (|) => { $crate::SyntaxKind::PIPE }; | ||
263 | (+) => { $crate::SyntaxKind::PLUS }; | ||
264 | (*) => { $crate::SyntaxKind::STAR }; | ||
265 | (/) => { $crate::SyntaxKind::SLASH }; | ||
266 | (^) => { $crate::SyntaxKind::CARET }; | ||
267 | (%) => { $crate::SyntaxKind::PERCENT }; | ||
268 | (_) => { $crate::SyntaxKind::UNDERSCORE }; | ||
269 | (.) => { $crate::SyntaxKind::DOT }; | ||
270 | (..) => { $crate::SyntaxKind::DOTDOT }; | ||
271 | (...) => { $crate::SyntaxKind::DOTDOTDOT }; | ||
272 | (..=) => { $crate::SyntaxKind::DOTDOTEQ }; | ||
273 | (:) => { $crate::SyntaxKind::COLON }; | ||
274 | (::) => { $crate::SyntaxKind::COLONCOLON }; | ||
275 | (=) => { $crate::SyntaxKind::EQ }; | ||
276 | (==) => { $crate::SyntaxKind::EQEQ }; | ||
277 | (=>) => { $crate::SyntaxKind::FAT_ARROW }; | ||
278 | (!) => { $crate::SyntaxKind::EXCL }; | ||
279 | (!=) => { $crate::SyntaxKind::NEQ }; | ||
280 | (-) => { $crate::SyntaxKind::MINUS }; | ||
281 | (->) => { $crate::SyntaxKind::THIN_ARROW }; | ||
282 | (<=) => { $crate::SyntaxKind::LTEQ }; | ||
283 | (>=) => { $crate::SyntaxKind::GTEQ }; | ||
284 | (+=) => { $crate::SyntaxKind::PLUSEQ }; | ||
285 | (-=) => { $crate::SyntaxKind::MINUSEQ }; | ||
286 | (|=) => { $crate::SyntaxKind::PIPEEQ }; | ||
287 | (&=) => { $crate::SyntaxKind::AMPEQ }; | ||
288 | (^=) => { $crate::SyntaxKind::CARETEQ }; | ||
289 | (/=) => { $crate::SyntaxKind::SLASHEQ }; | ||
290 | (*=) => { $crate::SyntaxKind::STAREQ }; | ||
291 | (%=) => { $crate::SyntaxKind::PERCENTEQ }; | ||
292 | (&&) => { $crate::SyntaxKind::AMPAMP }; | ||
293 | (||) => { $crate::SyntaxKind::PIPEPIPE }; | ||
294 | (<<) => { $crate::SyntaxKind::SHL }; | ||
295 | (>>) => { $crate::SyntaxKind::SHR }; | ||
296 | (<<=) => { $crate::SyntaxKind::SHLEQ }; | ||
297 | (>>=) => { $crate::SyntaxKind::SHREQ }; | ||
298 | (async) => { $crate::SyntaxKind::ASYNC_KW }; | ||
299 | (use) => { $crate::SyntaxKind::USE_KW }; | ||
300 | (fn) => { $crate::SyntaxKind::FN_KW }; | ||
301 | (struct) => { $crate::SyntaxKind::STRUCT_KW }; | ||
302 | (enum) => { $crate::SyntaxKind::ENUM_KW }; | ||
303 | (trait) => { $crate::SyntaxKind::TRAIT_KW }; | ||
304 | (impl) => { $crate::SyntaxKind::IMPL_KW }; | ||
305 | (dyn) => { $crate::SyntaxKind::DYN_KW }; | ||
306 | (true) => { $crate::SyntaxKind::TRUE_KW }; | ||
307 | (false) => { $crate::SyntaxKind::FALSE_KW }; | ||
308 | (as) => { $crate::SyntaxKind::AS_KW }; | ||
309 | (extern) => { $crate::SyntaxKind::EXTERN_KW }; | ||
310 | (crate) => { $crate::SyntaxKind::CRATE_KW }; | ||
311 | (mod) => { $crate::SyntaxKind::MOD_KW }; | ||
312 | (pub) => { $crate::SyntaxKind::PUB_KW }; | ||
313 | (self) => { $crate::SyntaxKind::SELF_KW }; | ||
314 | (super) => { $crate::SyntaxKind::SUPER_KW }; | ||
315 | (in) => { $crate::SyntaxKind::IN_KW }; | ||
316 | (where) => { $crate::SyntaxKind::WHERE_KW }; | ||
317 | (for) => { $crate::SyntaxKind::FOR_KW }; | ||
318 | (loop) => { $crate::SyntaxKind::LOOP_KW }; | ||
319 | (while) => { $crate::SyntaxKind::WHILE_KW }; | ||
320 | (continue) => { $crate::SyntaxKind::CONTINUE_KW }; | ||
321 | (break) => { $crate::SyntaxKind::BREAK_KW }; | ||
322 | (if) => { $crate::SyntaxKind::IF_KW }; | ||
323 | (else) => { $crate::SyntaxKind::ELSE_KW }; | ||
324 | (match) => { $crate::SyntaxKind::MATCH_KW }; | ||
325 | (const) => { $crate::SyntaxKind::CONST_KW }; | ||
326 | (static) => { $crate::SyntaxKind::STATIC_KW }; | ||
327 | (mut) => { $crate::SyntaxKind::MUT_KW }; | ||
328 | (unsafe) => { $crate::SyntaxKind::UNSAFE_KW }; | ||
329 | (type) => { $crate::SyntaxKind::TYPE_KW }; | ||
330 | (ref) => { $crate::SyntaxKind::REF_KW }; | ||
331 | (let) => { $crate::SyntaxKind::LET_KW }; | ||
332 | (move) => { $crate::SyntaxKind::MOVE_KW }; | ||
333 | (return) => { $crate::SyntaxKind::RETURN_KW }; | ||
334 | (auto) => { $crate::SyntaxKind::AUTO_KW }; | ||
335 | (default) => { $crate::SyntaxKind::DEFAULT_KW }; | ||
336 | (union) => { $crate::SyntaxKind::UNION_KW }; | ||
337 | } | ||
338 | |||
244 | impl From<u16> for SyntaxKind { | 339 | impl From<u16> for SyntaxKind { |
245 | fn from(d: u16) -> SyntaxKind { | 340 | fn from(d: u16) -> SyntaxKind { |
246 | assert!(d <= (__LAST as u16)); | 341 | assert!(d <= (__LAST as u16)); |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs.tera b/crates/ra_parser/src/syntax_kind/generated.rs.tera index 5b9ff21af..ccb8ca4ba 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs.tera +++ b/crates/ra_parser/src/syntax_kind/generated.rs.tera | |||
@@ -33,6 +33,20 @@ pub enum SyntaxKind { | |||
33 | } | 33 | } |
34 | use self::SyntaxKind::*; | 34 | use self::SyntaxKind::*; |
35 | 35 | ||
36 | #[macro_export] | ||
37 | macro_rules! T { | ||
38 | {%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %} | ||
39 | {%- if t.0 == '{' or t.0 == '}' or t.0 == '[' or t.0 == ']' %} | ||
40 | ('{{t.0}}') => { $crate::SyntaxKind::{{t.1}} }; | ||
41 | {%- else %} | ||
42 | ({{t.0}}) => { $crate::SyntaxKind::{{t.1}} }; | ||
43 | {%- endif %} | ||
44 | {%- endfor -%} | ||
45 | {% for kw in concat(a=keywords, b=contextual_keywords) %} | ||
46 | ({{kw}}) => { $crate::SyntaxKind::{{kw | upper}}_KW }; | ||
47 | {%- endfor %} | ||
48 | } | ||
49 | |||
36 | impl From<u16> for SyntaxKind { | 50 | impl From<u16> for SyntaxKind { |
37 | fn from(d: u16) -> SyntaxKind { | 51 | fn from(d: u16) -> SyntaxKind { |
38 | assert!(d <= (__LAST as u16)); | 52 | assert!(d <= (__LAST as u16)); |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 39c25dbdc..65c65d6aa 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -33,6 +33,7 @@ pub mod fuzz; | |||
33 | 33 | ||
34 | pub use rowan::{SmolStr, TextRange, TextUnit}; | 34 | pub use rowan::{SmolStr, TextRange, TextUnit}; |
35 | pub use ra_parser::SyntaxKind; | 35 | pub use ra_parser::SyntaxKind; |
36 | pub use ra_parser::T; | ||
36 | pub use crate::{ | 37 | pub use crate::{ |
37 | ast::AstNode, | 38 | ast::AstNode, |
38 | syntax_error::{SyntaxError, SyntaxErrorKind, Location}, | 39 | syntax_error::{SyntaxError, SyntaxErrorKind, Location}, |