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 ordinary source rather than part of the `syntax!` expansion:
4//! 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 an M2 spelling.
13///
14/// Rust spacing and string-fragment boundaries do not affect the result, so
15/// `Token![!=]`, `Token![! =]`, `Token!["!="]`, and mixed forms name the same
16/// type. String fragments can contain characters that Rust cannot tokenize.
17#[macro_export]
18macro_rules! Token {
19    [$($spelling:tt)*] => {
20        $crate::__m2_syn_token!($($spelling)*)
21    };
22}
23
24/// Names the delimiter atom for a delimiter family, as in `Delimiter![()]`.
25#[macro_export]
26macro_rules! Delimiter {
27    [()] => { $crate::nodes::_ParenthesisDelimiter };
28    [[]] => { $crate::nodes::_BracketDelimiter };
29    [{}] => { $crate::nodes::_BraceDelimiter };
30    [<| |>] => { $crate::nodes::_AngleBarDelimiter };
31    [$($unsupported:tt)*] => {
32        compile_error!("delimiter was not declared")
33    };
34}