macro_rules! eure {
({}) => { ... };
({ $($body:tt)* }) => { ... };
(@body $c:ident;) => { ... };
(@body $c:ident; = $val:expr $(, $($tail:tt)*)?) => { ... };
(@body $c:ident; $($tokens:tt)+) => { ... };
(@parse_seg $c:ident $scope:ident; $seg:ident $($rest:tt)*) => { ... };
(@parse_seg $c:ident $scope:ident; % $ext:ident $($rest:tt)*) => { ... };
(@parse_seg $c:ident $scope:ident; % $ext:literal $($rest:tt)*) => { ... };
(@parse_seg $c:ident $scope:ident; # $idx:literal $($rest:tt)*) => { ... };
(@parse_seg $c:ident $scope:ident; ($($tuple:tt)*) $($rest:tt)*) => { ... };
(@parse_seg $c:ident $scope:ident; $key:literal $($rest:tt)*) => { ... };
(@build_tuple_key;) => { ... };
(@build_tuple_key; $($item:expr),+ $(,)?) => { ... };
(@after_seg $c:ident $scope:ident; [$($arr:tt)*] $($rest:tt)*) => { ... };
(@after_seg $c:ident $scope:ident; $($rest:tt)*) => { ... };
(@handle_arr $c:ident $scope:ident []; $($rest:tt)*) => { ... };
(@handle_arr $c:ident $scope:ident [$idx:literal]; $($rest:tt)*) => { ... };
(@after_arr $c:ident $scope:ident; . $($rest:tt)+) => { ... };
(@after_arr $c:ident $scope:ident; = [$($items:expr),* $(,)?] $(, $($tail:tt)*)?) => { ... };
(@after_arr $c:ident $scope:ident; = ($($items:expr),* $(,)?) $(, $($tail:tt)*)?) => { ... };
(@after_arr $c:ident $scope:ident; = { $($key:expr => $val:expr),* $(,)? } $(, $($tail:tt)*)?) => { ... };
(@after_arr $c:ident $scope:ident; = $val:expr $(, $($tail:tt)*)?) => { ... };
(@after_arr $c:ident $scope:ident; {} $(, $($tail:tt)*)?) => { ... };
(@after_arr $c:ident $scope:ident; { $($inner:tt)+ } $(, $($tail:tt)*)?) => { ... };
}Expand description
A declarative macro for building Eure documents, inspired by serde_json’s json! macro.
§Syntax
The macro uses a TT muncher pattern to support arbitrary path combinations:
- Idents:
a.b.c - Extensions:
a.%ext(use%instead of$since$is reserved in macros) - Tuple index:
a.#0,a.#1 - Array markers:
a[](push),a[0](index) - Tuple keys:
a.(1, "key")(composite map keys) - Mixed paths:
a.%ext[].b,a[].%ext.#0,a.(1, 2).name
§Examples
use eure_document::{eure, Text};
// Simple assignment
let doc = eure!({
name = "Alice",
age = 30,
});
// Nested paths
let doc = eure!({
user.name = "Bob",
user.active = true,
});
// Blocks (for grouping)
let doc = eure!({
user {
name = "Charlie",
role = "admin",
},
});
// Extensions
let doc = eure!({
field.%variant = Text::inline_implicit("text"),
});
// Tuple index
let doc = eure!({
point.#0 = 1.0f64,
point.#1 = 2.0f64,
});
// Array markers
let doc = eure!({
items[] = 1,
items[] = 2,
});
// Tuple keys (composite map keys)
let doc = eure!({
map.(1, "key") = "value",
map.(true, 2) = "another",
});
// Arrays (literal)
let doc = eure!({
tags = [Text::inline_implicit("a"), Text::inline_implicit("b")],
});
// Tuples (literal)
let doc = eure!({
point = (1.0f64, 2.0f64),
});