diff options
author | Clemens Wasser <[email protected]> | 2021-06-03 10:45:10 +0100 |
---|---|---|
committer | Clemens Wasser <[email protected]> | 2021-06-03 10:46:03 +0100 |
commit | 3c6dc0f89dc9c2902d71e8639b4913917a396f8a (patch) | |
tree | 6a1acfe280a8e9369a753b4e7bb829b8b9ff6317 | |
parent | e8e14e1b13b76aaa643bc3beffb9c52bc5228d24 (diff) |
Apply a few clippy suggestions
-rw-r--r-- | crates/parser/src/grammar/expressions/atom.rs | 8 | ||||
-rw-r--r-- | crates/parser/src/syntax_kind/generated.rs | 129 | ||||
-rw-r--r-- | crates/test_utils/src/lib.rs | 11 | ||||
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 20 |
4 files changed, 121 insertions, 47 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index 269f223e6..abdfca1fe 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs | |||
@@ -252,12 +252,10 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker { | |||
252 | // test lambda_ret_block | 252 | // test lambda_ret_block |
253 | // fn main() { || -> i32 { 92 }(); } | 253 | // fn main() { || -> i32 { 92 }(); } |
254 | block_expr(p); | 254 | block_expr(p); |
255 | } else if p.at_ts(EXPR_FIRST) { | ||
256 | expr(p); | ||
255 | } else { | 257 | } else { |
256 | if p.at_ts(EXPR_FIRST) { | 258 | p.error("expected expression"); |
257 | expr(p); | ||
258 | } else { | ||
259 | p.error("expected expression"); | ||
260 | } | ||
261 | } | 259 | } |
262 | m.complete(p, CLOSURE_EXPR) | 260 | m.complete(p, CLOSURE_EXPR) |
263 | } | 261 | } |
diff --git a/crates/parser/src/syntax_kind/generated.rs b/crates/parser/src/syntax_kind/generated.rs index bcefd183a..be2dfbbea 100644 --- a/crates/parser/src/syntax_kind/generated.rs +++ b/crates/parser/src/syntax_kind/generated.rs | |||
@@ -260,33 +260,116 @@ pub enum SyntaxKind { | |||
260 | use self::SyntaxKind::*; | 260 | use self::SyntaxKind::*; |
261 | impl SyntaxKind { | 261 | impl SyntaxKind { |
262 | pub fn is_keyword(self) -> bool { | 262 | pub fn is_keyword(self) -> bool { |
263 | match self { | 263 | matches!( |
264 | AS_KW | ASYNC_KW | AWAIT_KW | BOX_KW | BREAK_KW | CONST_KW | CONTINUE_KW | CRATE_KW | 264 | self, |
265 | | DYN_KW | ELSE_KW | ENUM_KW | EXTERN_KW | FALSE_KW | FN_KW | FOR_KW | IF_KW | 265 | AS_KW |
266 | | IMPL_KW | IN_KW | LET_KW | LOOP_KW | MACRO_KW | MATCH_KW | MOD_KW | MOVE_KW | 266 | | ASYNC_KW |
267 | | MUT_KW | PUB_KW | REF_KW | RETURN_KW | SELF_KW | STATIC_KW | STRUCT_KW | SUPER_KW | 267 | | AWAIT_KW |
268 | | TRAIT_KW | TRUE_KW | TRY_KW | TYPE_KW | UNSAFE_KW | USE_KW | WHERE_KW | WHILE_KW | 268 | | BOX_KW |
269 | | YIELD_KW | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW | RAW_KW | 269 | | BREAK_KW |
270 | | MACRO_RULES_KW => true, | 270 | | CONST_KW |
271 | _ => false, | 271 | | CONTINUE_KW |
272 | } | 272 | | CRATE_KW |
273 | | DYN_KW | ||
274 | | ELSE_KW | ||
275 | | ENUM_KW | ||
276 | | EXTERN_KW | ||
277 | | FALSE_KW | ||
278 | | FN_KW | ||
279 | | FOR_KW | ||
280 | | IF_KW | ||
281 | | IMPL_KW | ||
282 | | IN_KW | ||
283 | | LET_KW | ||
284 | | LOOP_KW | ||
285 | | MACRO_KW | ||
286 | | MATCH_KW | ||
287 | | MOD_KW | ||
288 | | MOVE_KW | ||
289 | | MUT_KW | ||
290 | | PUB_KW | ||
291 | | REF_KW | ||
292 | | RETURN_KW | ||
293 | | SELF_KW | ||
294 | | STATIC_KW | ||
295 | | STRUCT_KW | ||
296 | | SUPER_KW | ||
297 | | TRAIT_KW | ||
298 | | TRUE_KW | ||
299 | | TRY_KW | ||
300 | | TYPE_KW | ||
301 | | UNSAFE_KW | ||
302 | | USE_KW | ||
303 | | WHERE_KW | ||
304 | | WHILE_KW | ||
305 | | YIELD_KW | ||
306 | | AUTO_KW | ||
307 | | DEFAULT_KW | ||
308 | | EXISTENTIAL_KW | ||
309 | | UNION_KW | ||
310 | | RAW_KW | ||
311 | | MACRO_RULES_KW | ||
312 | ) | ||
273 | } | 313 | } |
274 | pub fn is_punct(self) -> bool { | 314 | pub fn is_punct(self) -> bool { |
275 | match self { | 315 | matches!( |
276 | SEMICOLON | COMMA | L_PAREN | R_PAREN | L_CURLY | R_CURLY | L_BRACK | R_BRACK | 316 | self, |
277 | | L_ANGLE | R_ANGLE | AT | POUND | TILDE | QUESTION | DOLLAR | AMP | PIPE | PLUS | 317 | SEMICOLON |
278 | | STAR | SLASH | CARET | PERCENT | UNDERSCORE | DOT | DOT2 | DOT3 | DOT2EQ | COLON | 318 | | COMMA |
279 | | COLON2 | EQ | EQ2 | FAT_ARROW | BANG | NEQ | MINUS | THIN_ARROW | LTEQ | GTEQ | 319 | | L_PAREN |
280 | | PLUSEQ | MINUSEQ | PIPEEQ | AMPEQ | CARETEQ | SLASHEQ | STAREQ | PERCENTEQ | AMP2 | 320 | | R_PAREN |
281 | | PIPE2 | SHL | SHR | SHLEQ | SHREQ => true, | 321 | | L_CURLY |
282 | _ => false, | 322 | | R_CURLY |
283 | } | 323 | | L_BRACK |
324 | | R_BRACK | ||
325 | | L_ANGLE | ||
326 | | R_ANGLE | ||
327 | | AT | ||
328 | | POUND | ||
329 | | TILDE | ||
330 | | QUESTION | ||
331 | | DOLLAR | ||
332 | | AMP | ||
333 | | PIPE | ||
334 | | PLUS | ||
335 | | STAR | ||
336 | | SLASH | ||
337 | | CARET | ||
338 | | PERCENT | ||
339 | | UNDERSCORE | ||
340 | | DOT | ||
341 | | DOT2 | ||
342 | | DOT3 | ||
343 | | DOT2EQ | ||
344 | | COLON | ||
345 | | COLON2 | ||
346 | | EQ | ||
347 | | EQ2 | ||
348 | | FAT_ARROW | ||
349 | | BANG | ||
350 | | NEQ | ||
351 | | MINUS | ||
352 | | THIN_ARROW | ||
353 | | LTEQ | ||
354 | | GTEQ | ||
355 | | PLUSEQ | ||
356 | | MINUSEQ | ||
357 | | PIPEEQ | ||
358 | | AMPEQ | ||
359 | | CARETEQ | ||
360 | | SLASHEQ | ||
361 | | STAREQ | ||
362 | | PERCENTEQ | ||
363 | | AMP2 | ||
364 | | PIPE2 | ||
365 | | SHL | ||
366 | | SHR | ||
367 | | SHLEQ | ||
368 | | SHREQ | ||
369 | ) | ||
284 | } | 370 | } |
285 | pub fn is_literal(self) -> bool { | 371 | pub fn is_literal(self) -> bool { |
286 | match self { | 372 | matches!(self, INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE | STRING | BYTE_STRING) |
287 | INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE | STRING | BYTE_STRING => true, | ||
288 | _ => false, | ||
289 | } | ||
290 | } | 373 | } |
291 | pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { | 374 | pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { |
292 | let kw = match ident { | 375 | let kw = match ident { |
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index bd017567c..ac5a9509d 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs | |||
@@ -238,14 +238,9 @@ fn extract_line_annotations(mut line: &str) -> Vec<LineAnnotation> { | |||
238 | let mut res = Vec::new(); | 238 | let mut res = Vec::new(); |
239 | let mut offset: TextSize = 0.into(); | 239 | let mut offset: TextSize = 0.into(); |
240 | let marker: fn(char) -> bool = if line.contains('^') { |c| c == '^' } else { |c| c == '|' }; | 240 | let marker: fn(char) -> bool = if line.contains('^') { |c| c == '^' } else { |c| c == '|' }; |
241 | loop { | 241 | while let Some(idx) = line.find(marker) { |
242 | match line.find(marker) { | 242 | offset += TextSize::try_from(idx).unwrap(); |
243 | Some(idx) => { | 243 | line = &line[idx..]; |
244 | offset += TextSize::try_from(idx).unwrap(); | ||
245 | line = &line[idx..]; | ||
246 | } | ||
247 | None => break, | ||
248 | }; | ||
249 | 244 | ||
250 | let mut len = line.chars().take_while(|&it| it == '^').count(); | 245 | let mut len = line.chars().take_while(|&it| it == '^').count(); |
251 | let mut continuation = false; | 246 | let mut continuation = false; |
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index ba4b24848..b0b9e30db 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs | |||
@@ -94,18 +94,16 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> { | |||
94 | support::children(&self.syntax) | 94 | support::children(&self.syntax) |
95 | } | 95 | } |
96 | } | 96 | } |
97 | } else { | 97 | } else if let Some(token_kind) = field.token_kind() { |
98 | if let Some(token_kind) = field.token_kind() { | 98 | quote! { |
99 | quote! { | 99 | pub fn #method_name(&self) -> Option<#ty> { |
100 | pub fn #method_name(&self) -> Option<#ty> { | 100 | support::token(&self.syntax, #token_kind) |
101 | support::token(&self.syntax, #token_kind) | ||
102 | } | ||
103 | } | 101 | } |
104 | } else { | 102 | } |
105 | quote! { | 103 | } else { |
106 | pub fn #method_name(&self) -> Option<#ty> { | 104 | quote! { |
107 | support::child(&self.syntax) | 105 | pub fn #method_name(&self) -> Option<#ty> { |
108 | } | 106 | support::child(&self.syntax) |
109 | } | 107 | } |
110 | } | 108 | } |
111 | } | 109 | } |