diff options
-rw-r--r-- | src/syntax_kinds/generated.rs | 75 | ||||
-rw-r--r-- | src/syntax_kinds/generated.rs.tera | 13 | ||||
-rw-r--r-- | src/yellow/green.rs | 19 |
3 files changed, 101 insertions, 6 deletions
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs index 9dcf8992f..571b64af4 100644 --- a/src/syntax_kinds/generated.rs +++ b/src/syntax_kinds/generated.rs | |||
@@ -353,5 +353,80 @@ impl SyntaxKind { | |||
353 | }; | 353 | }; |
354 | Some(tok) | 354 | Some(tok) |
355 | } | 355 | } |
356 | |||
357 | pub(crate) fn static_text(self) -> Option<&'static str> { | ||
358 | let tok = match self { | ||
359 | SEMI => ";", | ||
360 | COMMA => ",", | ||
361 | L_PAREN => "(", | ||
362 | R_PAREN => ")", | ||
363 | L_CURLY => "{", | ||
364 | R_CURLY => "}", | ||
365 | L_BRACK => "[", | ||
366 | R_BRACK => "]", | ||
367 | L_ANGLE => "<", | ||
368 | R_ANGLE => ">", | ||
369 | AT => "@", | ||
370 | POUND => "#", | ||
371 | TILDE => "~", | ||
372 | QUESTION => "?", | ||
373 | DOLLAR => "$", | ||
374 | AMPERSAND => "&", | ||
375 | PIPE => "|", | ||
376 | PLUS => "+", | ||
377 | STAR => "*", | ||
378 | SLASH => "/", | ||
379 | CARET => "^", | ||
380 | PERCENT => "%", | ||
381 | DOT => ".", | ||
382 | DOTDOT => "..", | ||
383 | DOTDOTDOT => "...", | ||
384 | DOTDOTEQ => "..=", | ||
385 | COLON => ":", | ||
386 | COLONCOLON => "::", | ||
387 | EQ => "=", | ||
388 | EQEQ => "==", | ||
389 | FAT_ARROW => "=>", | ||
390 | EXCL => "!", | ||
391 | NEQ => "!=", | ||
392 | MINUS => "-", | ||
393 | THIN_ARROW => "->", | ||
394 | |||
395 | USE_KW => "use", | ||
396 | FN_KW => "fn", | ||
397 | STRUCT_KW => "struct", | ||
398 | ENUM_KW => "enum", | ||
399 | TRAIT_KW => "trait", | ||
400 | IMPL_KW => "impl", | ||
401 | TRUE_KW => "true", | ||
402 | FALSE_KW => "false", | ||
403 | AS_KW => "as", | ||
404 | EXTERN_KW => "extern", | ||
405 | CRATE_KW => "crate", | ||
406 | MOD_KW => "mod", | ||
407 | PUB_KW => "pub", | ||
408 | SELF_KW => "self", | ||
409 | SUPER_KW => "super", | ||
410 | IN_KW => "in", | ||
411 | WHERE_KW => "where", | ||
412 | FOR_KW => "for", | ||
413 | LOOP_KW => "loop", | ||
414 | WHILE_KW => "while", | ||
415 | IF_KW => "if", | ||
416 | MATCH_KW => "match", | ||
417 | CONST_KW => "const", | ||
418 | STATIC_KW => "static", | ||
419 | MUT_KW => "mut", | ||
420 | UNSAFE_KW => "unsafe", | ||
421 | TYPE_KW => "type", | ||
422 | REF_KW => "ref", | ||
423 | LET_KW => "let", | ||
424 | AUTO_KW => "auto", | ||
425 | DEFAULT_KW => "default", | ||
426 | UNION_KW => "union", | ||
427 | _ => return None, | ||
428 | }; | ||
429 | Some(tok) | ||
430 | } | ||
356 | } | 431 | } |
357 | 432 | ||
diff --git a/src/syntax_kinds/generated.rs.tera b/src/syntax_kinds/generated.rs.tera index 2a47c6632..d719c8312 100644 --- a/src/syntax_kinds/generated.rs.tera +++ b/src/syntax_kinds/generated.rs.tera | |||
@@ -58,5 +58,18 @@ impl SyntaxKind { | |||
58 | }; | 58 | }; |
59 | Some(tok) | 59 | Some(tok) |
60 | } | 60 | } |
61 | |||
62 | pub(crate) fn static_text(self) -> Option<&'static str> { | ||
63 | let tok = match self { | ||
64 | {%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %} | ||
65 | {{t.1}} => "{{t.0}}", | ||
66 | {%- endfor %} | ||
67 | {% for kw in concat(a=keywords, b=contextual_keywords) %} | ||
68 | {{kw | upper}}_KW => "{{kw}}", | ||
69 | {%- endfor %} | ||
70 | _ => return None, | ||
71 | }; | ||
72 | Some(tok) | ||
73 | } | ||
61 | } | 74 | } |
62 | 75 | ||
diff --git a/src/yellow/green.rs b/src/yellow/green.rs index 507e4d57e..cda4e2167 100644 --- a/src/yellow/green.rs +++ b/src/yellow/green.rs | |||
@@ -81,7 +81,7 @@ fn assert_send_sync() { | |||
81 | #[derive(Clone, Debug)] | 81 | #[derive(Clone, Debug)] |
82 | pub(crate) enum GreenLeaf { | 82 | pub(crate) enum GreenLeaf { |
83 | Whitespace { newlines: u8, spaces: u8 }, | 83 | Whitespace { newlines: u8, spaces: u8 }, |
84 | Token { kind: SyntaxKind, text: Arc<str> }, | 84 | Token { kind: SyntaxKind, text: Option<Arc<str>> }, |
85 | } | 85 | } |
86 | 86 | ||
87 | impl GreenLeaf { | 87 | impl GreenLeaf { |
@@ -96,10 +96,14 @@ impl GreenLeaf { | |||
96 | }; | 96 | }; |
97 | } | 97 | } |
98 | } | 98 | } |
99 | GreenLeaf::Token { | 99 | let text = match SyntaxKind::static_text(kind) { |
100 | kind, | 100 | Some(t) => { |
101 | text: text.to_owned().into_boxed_str().into(), | 101 | debug_assert_eq!(t, text); |
102 | } | 102 | None |
103 | } | ||
104 | None => Some(text.to_owned().into_boxed_str().into()), | ||
105 | }; | ||
106 | GreenLeaf::Token { kind, text } | ||
103 | } | 107 | } |
104 | 108 | ||
105 | pub(crate) fn kind(&self) -> SyntaxKind { | 109 | pub(crate) fn kind(&self) -> SyntaxKind { |
@@ -117,7 +121,10 @@ impl GreenLeaf { | |||
117 | assert!(newlines <= N_NEWLINES && spaces <= N_SPACES); | 121 | assert!(newlines <= N_NEWLINES && spaces <= N_SPACES); |
118 | &WS[N_NEWLINES - newlines..N_NEWLINES + spaces] | 122 | &WS[N_NEWLINES - newlines..N_NEWLINES + spaces] |
119 | } | 123 | } |
120 | GreenLeaf::Token { text, .. } => text, | 124 | GreenLeaf::Token { kind, text, } => match text { |
125 | None => kind.static_text().unwrap(), | ||
126 | Some(t) => t, | ||
127 | }, | ||
121 | } | 128 | } |
122 | } | 129 | } |
123 | 130 | ||