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 an M2 spelling.
25///
26/// Rust spacing and string-fragment boundaries do not affect the result, so
27/// `Token![!=]`, `Token![! =]`, `Token!["!="]`, and mixed forms name the same
28/// type. String fragments can contain characters that Rust cannot tokenize.
29#[macro_export]
30macro_rules! Token {
31 [$($spelling:tt)*] => {
32 $crate::__m2_syn_token!($($spelling)*)
33 };
34}
35
36/// Names the delimiter atom for a delimiter family, as in `Delimiter![()]`.
37#[macro_export]
38macro_rules! Delimiter {
39 [()] => { $crate::nodes::_ParenthesisDelimiter };
40 [[]] => { $crate::nodes::_BracketDelimiter };
41 [{}] => { $crate::nodes::_BraceDelimiter };
42 [<| |>] => { $crate::nodes::_AngleBarDelimiter };
43 [$($unsupported:tt)*] => {
44 compile_error!("delimiter was not declared")
45 };
46}