Implemented T! macro for syntax kinds

This commit is contained in:
Sergey Parilin 2019-05-08 18:35:32 +03:00
parent ef782adc29
commit 57bb618fd3
6 changed files with 114 additions and 1 deletions

View file

@ -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));