From beaddb478097223c87e507bf9367d85d86df5d06 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Jul 2018 18:11:33 +0300 Subject: Intern static tokens --- src/syntax_kinds/generated.rs | 75 ++++++++++++++++++++++++++++++++++++++ src/syntax_kinds/generated.rs.tera | 13 +++++++ 2 files changed, 88 insertions(+) (limited to 'src/syntax_kinds') 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 { }; Some(tok) } + + pub(crate) fn static_text(self) -> Option<&'static str> { + let tok = match self { + SEMI => ";", + COMMA => ",", + L_PAREN => "(", + R_PAREN => ")", + L_CURLY => "{", + R_CURLY => "}", + L_BRACK => "[", + R_BRACK => "]", + L_ANGLE => "<", + R_ANGLE => ">", + AT => "@", + POUND => "#", + TILDE => "~", + QUESTION => "?", + DOLLAR => "$", + AMPERSAND => "&", + PIPE => "|", + PLUS => "+", + STAR => "*", + SLASH => "/", + CARET => "^", + PERCENT => "%", + DOT => ".", + DOTDOT => "..", + DOTDOTDOT => "...", + DOTDOTEQ => "..=", + COLON => ":", + COLONCOLON => "::", + EQ => "=", + EQEQ => "==", + FAT_ARROW => "=>", + EXCL => "!", + NEQ => "!=", + MINUS => "-", + THIN_ARROW => "->", + + USE_KW => "use", + FN_KW => "fn", + STRUCT_KW => "struct", + ENUM_KW => "enum", + TRAIT_KW => "trait", + IMPL_KW => "impl", + TRUE_KW => "true", + FALSE_KW => "false", + AS_KW => "as", + EXTERN_KW => "extern", + CRATE_KW => "crate", + MOD_KW => "mod", + PUB_KW => "pub", + SELF_KW => "self", + SUPER_KW => "super", + IN_KW => "in", + WHERE_KW => "where", + FOR_KW => "for", + LOOP_KW => "loop", + WHILE_KW => "while", + IF_KW => "if", + MATCH_KW => "match", + CONST_KW => "const", + STATIC_KW => "static", + MUT_KW => "mut", + UNSAFE_KW => "unsafe", + TYPE_KW => "type", + REF_KW => "ref", + LET_KW => "let", + AUTO_KW => "auto", + DEFAULT_KW => "default", + UNION_KW => "union", + _ => return None, + }; + Some(tok) + } } 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 @@ -53,6 +53,19 @@ impl SyntaxKind { let tok = match c { {%- for t in single_byte_tokens %} '{{t.0}}' => {{t.1}}, +{%- endfor %} + _ => return None, + }; + Some(tok) + } + + pub(crate) fn static_text(self) -> Option<&'static str> { + let tok = match self { +{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %} + {{t.1}} => "{{t.0}}", +{%- endfor %} +{% for kw in concat(a=keywords, b=contextual_keywords) %} + {{kw | upper}}_KW => "{{kw}}", {%- endfor %} _ => return None, }; -- cgit v1.2.3