mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Implemented T! macro for syntax kinds
This commit is contained in:
parent
ef782adc29
commit
57bb618fd3
6 changed files with 114 additions and 1 deletions
|
@ -33,6 +33,20 @@ pub enum SyntaxKind {
|
|||
}
|
||||
use self::SyntaxKind::*;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! T {
|
||||
{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %}
|
||||
{%- if t.0 == '{' or t.0 == '}' or t.0 == '[' or t.0 == ']' %}
|
||||
('{{t.0}}') => { $crate::SyntaxKind::{{t.1}} };
|
||||
{%- else %}
|
||||
({{t.0}}) => { $crate::SyntaxKind::{{t.1}} };
|
||||
{%- endif %}
|
||||
{%- endfor -%}
|
||||
{% for kw in concat(a=keywords, b=contextual_keywords) %}
|
||||
({{kw}}) => { $crate::SyntaxKind::{{kw | upper}}_KW };
|
||||
{%- endfor %}
|
||||
}
|
||||
|
||||
impl From<u16> for SyntaxKind {
|
||||
fn from(d: u16) -> SyntaxKind {
|
||||
assert!(d <= (__LAST as u16));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue