Skip to main content

m2_syn/schema/
macros.rs

1//! Spelling-to-type macros for the generated token and delimiter atoms.
2//!
3//! These are the only two `macro_rules!` in the crate, and they are ordinary
4//! source rather than part of the `syntax!` expansion: rust-analyzer does not
5//! register `macro_rules!` produced by a procedural macro, which would leave
6//! every call site unresolved in the editor (rust-lang/rust-analyzer#10644).
7//!
8//! Neither needs the schema. `Token!` defers the spelling-to-name computation
9//! to the `token!` procedural macro, and the delimiter families are a fixed
10//! set.
11
12/// Names the token type generated for a spelling, as in `Token![;]`.
13#[macro_export]
14macro_rules! Token {
15    [$($spelling:tt)*] => {
16        $crate::__m2_syn_token!($($spelling)*)
17    };
18}
19
20/// Names the delimiter atom for a delimiter family, as in `Delimiter![()]`.
21#[macro_export]
22macro_rules! Delimiter {
23    [()] => { $crate::_ParenthesisDelimiter };
24    [[]] => { $crate::_BracketDelimiter };
25    [{}] => { $crate::_BraceDelimiter };
26    [<| |>] => { $crate::_AngleBarDelimiter };
27    [$($unsupported:tt)*] => {
28        compile_error!("delimiter was not declared")
29    };
30}