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/// Declares typed syntax nodes, token atoms, and enabled derived APIs.
13///
14/// The main crate selects the internal procedural-macro entry point so that
15/// `pretty` and `walk` are resolved as `m2-syn` dependency features rather
16/// than as features of the crate invoking this macro.
17#[macro_export]
18macro_rules! syntax {
19    ($($syntax:tt)*) => {
20        $crate::__m2_syn_syntax! { $($syntax)* }
21    };
22}
23
24/// Names the token type generated for a spelling, as in `Token![;]`.
25#[macro_export]
26macro_rules! Token {
27    [$($spelling:tt)*] => {
28        $crate::__m2_syn_token!($($spelling)*)
29    };
30}
31
32/// Names the delimiter atom for a delimiter family, as in `Delimiter![()]`.
33#[macro_export]
34macro_rules! Delimiter {
35    [()] => { $crate::nodes::_ParenthesisDelimiter };
36    [[]] => { $crate::nodes::_BracketDelimiter };
37    [{}] => { $crate::nodes::_BraceDelimiter };
38    [<| |>] => { $crate::nodes::_AngleBarDelimiter };
39    [$($unsupported:tt)*] => {
40        compile_error!("delimiter was not declared")
41    };
42}