summaryrefslogtreecommitdiffstats
path: root/vendor/time-macros/src/quote.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /vendor/time-macros/src/quote.rs
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/time-macros/src/quote.rs')
-rw-r--r--vendor/time-macros/src/quote.rs134
1 files changed, 134 insertions, 0 deletions
diff --git a/vendor/time-macros/src/quote.rs b/vendor/time-macros/src/quote.rs
new file mode 100644
index 000000000..2fe86cc98
--- /dev/null
+++ b/vendor/time-macros/src/quote.rs
@@ -0,0 +1,134 @@
+macro_rules! quote {
+ () => (::proc_macro::TokenStream::new());
+ ($($x:tt)*) => {{
+ let mut ts = ::proc_macro::TokenStream::new();
+ let ts_mut = &mut ts;
+ quote_inner!(ts_mut $($x)*);
+ ts
+ }};
+}
+
+#[cfg(any(feature = "formatting", feature = "parsing"))]
+macro_rules! quote_append {
+ ($ts:ident $($x:tt)*) => {{
+ quote_inner!($ts $($x)*);
+ }};
+}
+
+macro_rules! quote_group {
+ ({ $($x:tt)* }) => {
+ ::proc_macro::TokenTree::Group(::proc_macro::Group::new(
+ ::proc_macro::Delimiter::Brace,
+ quote!($($x)*)
+ ))
+ };
+}
+
+macro_rules! sym {
+ ($ts:ident $x:tt $y:tt) => {
+ $ts.extend([
+ ::proc_macro::TokenTree::from(::proc_macro::Punct::new(
+ $x,
+ ::proc_macro::Spacing::Joint,
+ )),
+ ::proc_macro::TokenTree::from(::proc_macro::Punct::new(
+ $y,
+ ::proc_macro::Spacing::Alone,
+ )),
+ ]);
+ };
+ ($ts:ident $x:tt) => {
+ $ts.extend([::proc_macro::TokenTree::from(::proc_macro::Punct::new(
+ $x,
+ ::proc_macro::Spacing::Alone,
+ ))]);
+ };
+}
+
+macro_rules! quote_inner {
+ // Base case
+ ($ts:ident) => {};
+
+ // Single or double symbols
+ ($ts:ident :: $($tail:tt)*) => { sym!($ts ':' ':'); quote_inner!($ts $($tail)*); };
+ ($ts:ident .. $($tail:tt)*) => { sym!($ts '.' '.'); quote_inner!($ts $($tail)*); };
+ ($ts:ident : $($tail:tt)*) => { sym!($ts ':'); quote_inner!($ts $($tail)*); };
+ ($ts:ident = $($tail:tt)*) => { sym!($ts '='); quote_inner!($ts $($tail)*); };
+ ($ts:ident ; $($tail:tt)*) => { sym!($ts ';'); quote_inner!($ts $($tail)*); };
+ ($ts:ident , $($tail:tt)*) => { sym!($ts ','); quote_inner!($ts $($tail)*); };
+ ($ts:ident . $($tail:tt)*) => { sym!($ts '.'); quote_inner!($ts $($tail)*); };
+ ($ts:ident & $($tail:tt)*) => { sym!($ts '&'); quote_inner!($ts $($tail)*); };
+ ($ts:ident << $($tail:tt)*) => { sym!($ts '<' '<'); quote_inner!($ts $($tail)*); };
+ ($ts:ident < $($tail:tt)*) => { sym!($ts '<'); quote_inner!($ts $($tail)*); };
+ ($ts:ident >> $($tail:tt)*) => { sym!($ts '>' '>'); quote_inner!($ts $($tail)*); };
+ ($ts:ident > $($tail:tt)*) => { sym!($ts '>'); quote_inner!($ts $($tail)*); };
+ ($ts:ident -> $($tail:tt)*) => { sym!($ts '-' '>'); quote_inner!($ts $($tail)*); };
+ ($ts:ident ? $($tail:tt)*) => { sym!($ts '?'); quote_inner!($ts $($tail)*); };
+ ($ts:ident ! $($tail:tt)*) => { sym!($ts '!'); quote_inner!($ts $($tail)*); };
+ ($ts:ident | $($tail:tt)*) => { sym!($ts '|'); quote_inner!($ts $($tail)*); };
+ ($ts:ident * $($tail:tt)*) => { sym!($ts '*'); quote_inner!($ts $($tail)*); };
+
+ // Identifier
+ ($ts:ident $i:ident $($tail:tt)*) => {
+ $ts.extend([::proc_macro::TokenTree::from(::proc_macro::Ident::new(
+ &stringify!($i),
+ ::proc_macro::Span::mixed_site(),
+ ))]);
+ quote_inner!($ts $($tail)*);
+ };
+
+ // Literal
+ ($ts:ident $l:literal $($tail:tt)*) => {
+ $ts.extend([::proc_macro::TokenTree::from(::proc_macro::Literal::string(&$l))]);
+ quote_inner!($ts $($tail)*);
+ };
+
+ // Lifetime
+ ($ts:ident $l:lifetime $($tail:tt)*) => {
+ $ts.extend([
+ ::proc_macro::TokenTree::from(
+ ::proc_macro::Punct::new('\'', ::proc_macro::Spacing::Joint)
+ ),
+ ::proc_macro::TokenTree::from(::proc_macro::Ident::new(
+ stringify!($l).trim_start_matches(|c| c == '\''),
+ ::proc_macro::Span::mixed_site(),
+ )),
+ ]);
+ quote_inner!($ts $($tail)*);
+ };
+
+ // Groups
+ ($ts:ident ($($inner:tt)*) $($tail:tt)*) => {
+ $ts.extend([::proc_macro::TokenTree::Group(::proc_macro::Group::new(
+ ::proc_macro::Delimiter::Parenthesis,
+ quote!($($inner)*)
+ ))]);
+ quote_inner!($ts $($tail)*);
+ };
+ ($ts:ident [$($inner:tt)*] $($tail:tt)*) => {
+ $ts.extend([::proc_macro::TokenTree::Group(::proc_macro::Group::new(
+ ::proc_macro::Delimiter::Bracket,
+ quote!($($inner)*)
+ ))]);
+ quote_inner!($ts $($tail)*);
+ };
+ ($ts:ident {$($inner:tt)*} $($tail:tt)*) => {
+ $ts.extend([::proc_macro::TokenTree::Group(::proc_macro::Group::new(
+ ::proc_macro::Delimiter::Brace,
+ quote!($($inner)*)
+ ))]);
+ quote_inner!($ts $($tail)*);
+ };
+
+ // Interpolated values
+ // TokenTree by default
+ ($ts:ident #($e:expr) $($tail:tt)*) => {
+ $ts.extend([$crate::to_tokens::ToTokenTree::into_token_tree($e)]);
+ quote_inner!($ts $($tail)*);
+ };
+ // Allow a TokenStream by request. It's more expensive, so avoid if possible.
+ ($ts:ident #S($e:expr) $($tail:tt)*) => {
+ $crate::to_tokens::ToTokenStream::append_to($e, $ts);
+ quote_inner!($ts $($tail)*);
+ };
+}