Make importing toml_internal
macro unnecessary when using the toml
macro
This commit is contained in:
parent
19ac1ea19c
commit
a6071c7aac
126
src/macros.rs
126
src/macros.rs
|
@ -36,7 +36,7 @@ macro_rules! toml {
|
||||||
($($toml:tt)+) => {{
|
($($toml:tt)+) => {{
|
||||||
let table = $crate::value::Table::new();
|
let table = $crate::value::Table::new();
|
||||||
let mut root = $crate::Value::Table(table);
|
let mut root = $crate::Value::Table(table);
|
||||||
toml_internal!(@toplevel root [] $($toml)+);
|
$crate::toml_internal!(@toplevel root [] $($toml)+);
|
||||||
root
|
root
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -81,63 +81,63 @@ macro_rules! toml_internal {
|
||||||
|
|
||||||
// Parse negative number `key = -value`.
|
// Parse negative number `key = -value`.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = - $v:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = - $v:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = (-$v) $($rest)*);
|
$crate::toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = (-$v) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse positive number `key = +value`.
|
// Parse positive number `key = +value`.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = + $v:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = + $v:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = ($v) $($rest)*);
|
$crate::toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = ($v) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse offset datetime `key = 1979-05-27T00:32:00.999999-07:00`.
|
// Parse offset datetime `key = 1979-05-27T00:32:00.999999-07:00`.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse offset datetime `key = 1979-05-27T00:32:00-07:00`.
|
// Parse offset datetime `key = 1979-05-27T00:32:00-07:00`.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local datetime `key = 1979-05-27T00:32:00.999999`.
|
// Parse local datetime `key = 1979-05-27T00:32:00.999999`.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse offset datetime `key = 1979-05-27T07:32:00Z` and local datetime `key = 1979-05-27T07:32:00`.
|
// Parse offset datetime `key = 1979-05-27T07:32:00Z` and local datetime `key = 1979-05-27T07:32:00`.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local date `key = 1979-05-27`.
|
// Parse local date `key = 1979-05-27`.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local time `key = 00:32:00.999999`.
|
// Parse local time `key = 00:32:00.999999`.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local time `key = 07:32:00`.
|
// Parse local time `key = 07:32:00`.
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt $($rest:tt)*) => {
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt $($rest:tt)*) => {
|
||||||
toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec) $($rest)*);
|
$crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse any other `key = value` including string, inline array, inline
|
// Parse any other `key = value` including string, inline array, inline
|
||||||
|
@ -145,35 +145,35 @@ macro_rules! toml_internal {
|
||||||
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $v:tt $($rest:tt)*) => {{
|
(@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $v:tt $($rest:tt)*) => {{
|
||||||
$crate::macros::insert_toml(
|
$crate::macros::insert_toml(
|
||||||
&mut $root,
|
&mut $root,
|
||||||
&[$($path)* $(&concat!($("-", toml_internal!(@path $k),)+)[1..], )+],
|
&[$($path)* $(&concat!($("-", $crate::toml_internal!(@path $k),)+)[1..], )+],
|
||||||
toml_internal!(@value $v));
|
$crate::toml_internal!(@value $v));
|
||||||
toml_internal!(@toplevel $root [$($path)*] $($rest)*);
|
$crate::toml_internal!(@toplevel $root [$($path)*] $($rest)*);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// Parse array header `[[bin]]`.
|
// Parse array header `[[bin]]`.
|
||||||
(@toplevel $root:ident $oldpath:tt [[$($($path:tt)-+).+]] $($rest:tt)*) => {
|
(@toplevel $root:ident $oldpath:tt [[$($($path:tt)-+).+]] $($rest:tt)*) => {
|
||||||
$crate::macros::push_toml(
|
$crate::macros::push_toml(
|
||||||
&mut $root,
|
&mut $root,
|
||||||
&[$(&concat!($("-", toml_internal!(@path $path),)+)[1..],)+]);
|
&[$(&concat!($("-", $crate::toml_internal!(@path $path),)+)[1..],)+]);
|
||||||
toml_internal!(@toplevel $root [$(&concat!($("-", toml_internal!(@path $path),)+)[1..],)+] $($rest)*);
|
$crate::toml_internal!(@toplevel $root [$(&concat!($("-", $crate::toml_internal!(@path $path),)+)[1..],)+] $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse table header `[patch.crates-io]`.
|
// Parse table header `[patch.crates-io]`.
|
||||||
(@toplevel $root:ident $oldpath:tt [$($($path:tt)-+).+] $($rest:tt)*) => {
|
(@toplevel $root:ident $oldpath:tt [$($($path:tt)-+).+] $($rest:tt)*) => {
|
||||||
$crate::macros::insert_toml(
|
$crate::macros::insert_toml(
|
||||||
&mut $root,
|
&mut $root,
|
||||||
&[$(&concat!($("-", toml_internal!(@path $path),)+)[1..],)+],
|
&[$(&concat!($("-", $crate::toml_internal!(@path $path),)+)[1..],)+],
|
||||||
$crate::Value::Table($crate::value::Table::new()));
|
$crate::Value::Table($crate::value::Table::new()));
|
||||||
toml_internal!(@toplevel $root [$(&concat!($("-", toml_internal!(@path $path),)+)[1..],)+] $($rest)*);
|
$crate::toml_internal!(@toplevel $root [$(&concat!($("-", $crate::toml_internal!(@path $path),)+)[1..],)+] $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse datetime from string and insert into table.
|
// Parse datetime from string and insert into table.
|
||||||
(@topleveldatetime $root:ident [$($path:tt)*] $($($k:tt)-+).+ = ($($datetime:tt)+) $($rest:tt)*) => {
|
(@topleveldatetime $root:ident [$($path:tt)*] $($($k:tt)-+).+ = ($($datetime:tt)+) $($rest:tt)*) => {
|
||||||
$crate::macros::insert_toml(
|
$crate::macros::insert_toml(
|
||||||
&mut $root,
|
&mut $root,
|
||||||
&[$($path)* $(&concat!($("-", toml_internal!(@path $k),)+)[1..], )+],
|
&[$($path)* $(&concat!($("-", $crate::toml_internal!(@path $k),)+)[1..], )+],
|
||||||
$crate::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap()));
|
$crate::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap()));
|
||||||
toml_internal!(@toplevel $root [$($path)*] $($rest)*);
|
$crate::toml_internal!(@toplevel $root [$($path)*] $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Turn a path segment into a string.
|
// Turn a path segment into a string.
|
||||||
|
@ -190,14 +190,14 @@ macro_rules! toml_internal {
|
||||||
// Construct a Value from an inline table.
|
// Construct a Value from an inline table.
|
||||||
(@value { $($inline:tt)* }) => {{
|
(@value { $($inline:tt)* }) => {{
|
||||||
let mut table = $crate::Value::Table($crate::value::Table::new());
|
let mut table = $crate::Value::Table($crate::value::Table::new());
|
||||||
toml_internal!(@trailingcomma (@table table) $($inline)*);
|
$crate::toml_internal!(@trailingcomma (@table table) $($inline)*);
|
||||||
table
|
table
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// Construct a Value from an inline array.
|
// Construct a Value from an inline array.
|
||||||
(@value [ $($inline:tt)* ]) => {{
|
(@value [ $($inline:tt)* ]) => {{
|
||||||
let mut array = $crate::value::Array::new();
|
let mut array = $crate::value::Array::new();
|
||||||
toml_internal!(@trailingcomma (@array array) $($inline)*);
|
$crate::toml_internal!(@trailingcomma (@array array) $($inline)*);
|
||||||
$crate::Value::Array(array)
|
$crate::Value::Array(array)
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
@ -237,81 +237,81 @@ macro_rules! toml_internal {
|
||||||
|
|
||||||
// Parse negative number `key = -value`.
|
// Parse negative number `key = -value`.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = - $v:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = - $v:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@table $root $($($k)-+).+ = (-$v) , $($rest)*);
|
$crate::toml_internal!(@table $root $($($k)-+).+ = (-$v) , $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse positive number `key = +value`.
|
// Parse positive number `key = +value`.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = + $v:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = + $v:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@table $root $($($k)-+).+ = ($v) , $($rest)*);
|
$crate::toml_internal!(@table $root $($($k)-+).+ = ($v) , $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse offset datetime `key = 1979-05-27T00:32:00.999999-07:00`.
|
// Parse offset datetime `key = 1979-05-27T00:32:00.999999-07:00`.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse offset datetime `key = 1979-05-27T00:32:00-07:00`.
|
// Parse offset datetime `key = 1979-05-27T00:32:00-07:00`.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local datetime `key = 1979-05-27T00:32:00.999999`.
|
// Parse local datetime `key = 1979-05-27T00:32:00.999999`.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse offset datetime `key = 1979-05-27T07:32:00Z` and local datetime `key = 1979-05-27T07:32:00`.
|
// Parse offset datetime `key = 1979-05-27T07:32:00Z` and local datetime `key = 1979-05-27T07:32:00`.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local date `key = 1979-05-27`.
|
// Parse local date `key = 1979-05-27`.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local time `key = 00:32:00.999999`.
|
// Parse local time `key = 00:32:00.999999`.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local time `key = 07:32:00`.
|
// Parse local time `key = 07:32:00`.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec) $($rest)*);
|
$crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse any other type, probably string or boolean or number.
|
// Parse any other type, probably string or boolean or number.
|
||||||
(@table $root:ident $($($k:tt)-+).+ = $v:tt , $($rest:tt)*) => {
|
(@table $root:ident $($($k:tt)-+).+ = $v:tt , $($rest:tt)*) => {
|
||||||
$crate::macros::insert_toml(
|
$crate::macros::insert_toml(
|
||||||
&mut $root,
|
&mut $root,
|
||||||
&[$(&concat!($("-", toml_internal!(@path $k),)+)[1..], )+],
|
&[$(&concat!($("-", $crate::toml_internal!(@path $k),)+)[1..], )+],
|
||||||
toml_internal!(@value $v));
|
$crate::toml_internal!(@value $v));
|
||||||
toml_internal!(@table $root $($rest)*);
|
$crate::toml_internal!(@table $root $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse a Datetime from string and continue in @table state.
|
// Parse a Datetime from string and continue in @table state.
|
||||||
(@tabledatetime $root:ident $($($k:tt)-+).+ = ($($datetime:tt)*) $($rest:tt)*) => {
|
(@tabledatetime $root:ident $($($k:tt)-+).+ = ($($datetime:tt)*) $($rest:tt)*) => {
|
||||||
$crate::macros::insert_toml(
|
$crate::macros::insert_toml(
|
||||||
&mut $root,
|
&mut $root,
|
||||||
&[$(&concat!($("-", toml_internal!(@path $k),)+)[1..], )+],
|
&[$(&concat!($("-", $crate::toml_internal!(@path $k),)+)[1..], )+],
|
||||||
$crate::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap()));
|
$crate::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap()));
|
||||||
toml_internal!(@table $root $($rest)*);
|
$crate::toml_internal!(@table $root $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Base case of inline array.
|
// Base case of inline array.
|
||||||
|
@ -319,95 +319,95 @@ macro_rules! toml_internal {
|
||||||
|
|
||||||
// Parse negative number `-value`.
|
// Parse negative number `-value`.
|
||||||
(@array $root:ident - $v:tt , $($rest:tt)*) => {
|
(@array $root:ident - $v:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@array $root (-$v) , $($rest)*);
|
$crate::toml_internal!(@array $root (-$v) , $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse positive number `+value`.
|
// Parse positive number `+value`.
|
||||||
(@array $root:ident + $v:tt , $($rest:tt)*) => {
|
(@array $root:ident + $v:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@array $root ($v) , $($rest)*);
|
$crate::toml_internal!(@array $root ($v) , $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse offset datetime `1979-05-27T00:32:00.999999-07:00`.
|
// Parse offset datetime `1979-05-27T00:32:00.999999-07:00`.
|
||||||
(@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
(@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
(@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse offset datetime `1979-05-27T00:32:00-07:00`.
|
// Parse offset datetime `1979-05-27T00:32:00-07:00`.
|
||||||
(@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
(@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
(@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local datetime `1979-05-27T00:32:00.999999`.
|
// Parse local datetime `1979-05-27T00:32:00.999999`.
|
||||||
(@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
(@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
(@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse offset datetime `1979-05-27T07:32:00Z` and local datetime `1979-05-27T07:32:00`.
|
// Parse offset datetime `1979-05-27T07:32:00Z` and local datetime `1979-05-27T07:32:00`.
|
||||||
(@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
(@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec) $($rest)*);
|
||||||
};
|
};
|
||||||
// Space instead of T.
|
// Space instead of T.
|
||||||
(@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
(@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local date `1979-05-27`.
|
// Parse local date `1979-05-27`.
|
||||||
(@array $root:ident $yr:tt - $mo:tt - $day:tt , $($rest:tt)*) => {
|
(@array $root:ident $yr:tt - $mo:tt - $day:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($yr - $mo - $day) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local time `00:32:00.999999`.
|
// Parse local time `00:32:00.999999`.
|
||||||
(@array $root:ident $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
(@array $root:ident $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($hr : $min : $sec . $frac) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($hr : $min : $sec . $frac) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse local time `07:32:00`.
|
// Parse local time `07:32:00`.
|
||||||
(@array $root:ident $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
(@array $root:ident $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => {
|
||||||
toml_internal!(@arraydatetime $root ($hr : $min : $sec) $($rest)*);
|
$crate::toml_internal!(@arraydatetime $root ($hr : $min : $sec) $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse any other type, probably string or boolean or number.
|
// Parse any other type, probably string or boolean or number.
|
||||||
(@array $root:ident $v:tt , $($rest:tt)*) => {
|
(@array $root:ident $v:tt , $($rest:tt)*) => {
|
||||||
$root.push(toml_internal!(@value $v));
|
$root.push($crate::toml_internal!(@value $v));
|
||||||
toml_internal!(@array $root $($rest)*);
|
$crate::toml_internal!(@array $root $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse a Datetime from string and continue in @array state.
|
// Parse a Datetime from string and continue in @array state.
|
||||||
(@arraydatetime $root:ident ($($datetime:tt)*) $($rest:tt)*) => {
|
(@arraydatetime $root:ident ($($datetime:tt)*) $($rest:tt)*) => {
|
||||||
$root.push($crate::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap()));
|
$root.push($crate::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap()));
|
||||||
toml_internal!(@array $root $($rest)*);
|
$crate::toml_internal!(@array $root $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// No trailing comma required if the tokens are empty.
|
// No trailing comma required if the tokens are empty.
|
||||||
(@trailingcomma ($($args:tt)*)) => {
|
(@trailingcomma ($($args:tt)*)) => {
|
||||||
toml_internal!($($args)*);
|
$crate::toml_internal!($($args)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tokens end with a trailing comma, do not append another one.
|
// Tokens end with a trailing comma, do not append another one.
|
||||||
(@trailingcomma ($($args:tt)*) ,) => {
|
(@trailingcomma ($($args:tt)*) ,) => {
|
||||||
toml_internal!($($args)* ,);
|
$crate::toml_internal!($($args)* ,);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tokens end with something other than comma, append a trailing comma.
|
// Tokens end with something other than comma, append a trailing comma.
|
||||||
(@trailingcomma ($($args:tt)*) $last:tt) => {
|
(@trailingcomma ($($args:tt)*) $last:tt) => {
|
||||||
toml_internal!($($args)* $last ,);
|
$crate::toml_internal!($($args)* $last ,);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Not yet at the last token.
|
// Not yet at the last token.
|
||||||
(@trailingcomma ($($args:tt)*) $first:tt $($rest:tt)+) => {
|
(@trailingcomma ($($args:tt)*) $first:tt $($rest:tt)+) => {
|
||||||
toml_internal!(@trailingcomma ($($args)* $first) $($rest)+);
|
$crate::toml_internal!(@trailingcomma ($($args)* $first) $($rest)+);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue