Lines Matching +full:single +full:- +full:tt
1 // SPDX-License-Identifier: Apache-2.0 OR MIT
3 …]](https://github.com/dtolnay/quote) [![crates-io]](https://crates.io/crates/quote) [![d…
5 //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo…
6 //! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=55555…
7 //! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&lo…
17 //! crate. Quasi-quoting is a solution to one piece of that — producing
20 //! The idea of quasi-quoting is that we write *code* that we treat as *data*.
29 //! general-purpose Rust quasi-quoting library and is not specific to procedural
41 //! The following quasi-quoted block of code is something you might find in [a]
67 //! fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
84 //! # Non-macro code generators
102 // false positive https://github.com/rust-lang/rust-clippy/issues/6983
108 #[cfg(feature = "proc-macro")]
158 /// - `#(#var)*` — no separators
159 /// - `#(#var),*` — the character before the asterisk is used as a separator
160 /// - `#( struct #var; )*` — the repetition can contain other tokens
161 /// - `#( #k => println!("{}", #v), )*` — even multiple interpolations
186 /// tests and non-macro code like main.rs and build.rs. This is why even the
188 /// that ensures the libraries are unit testable and accessible in non-macro
191 /// There is a [`From`]-conversion in both directions so returning the output of
220 /// pub fn derive_heap_size(input: TokenStream) -> TokenStream {
233 /// fn heap_size_of_children(&self) -> usize {
307 /// Alternatively, the APIs provided by Syn and proc-macro2 can be used to
450 /// # fn from(i: usize) -> Self {
467 /// # fn example(&self) -> TokenStream {
485 ($($tt:tt)*) => {
499 // Special case rule for a single tt, for performance.
500 ($tt:tt) => {{
502 $crate::quote_token!{$tt _s}
512 ($tt1:tt $tt2:tt) => {{
520 ($($tt:tt)*) => {{
522 $crate::quote_each_token!{_s $($tt)*}
565 /// off-balance and draw the eye a particular way, due to the span expression
592 /// # fn span(&self) -> Span {
615 /// --> src/main.rs:10:21
621 /// In this example it is important for the where-clause to be spanned with the
632 ($span:expr=> $($tt:tt)*) => {
647 // Special case rule for a single tt, for performance.
648 ($span:expr=> $tt:tt) => {{
651 $crate::quote_token_spanned!{$tt _s _span}
662 ($span:expr=> $tt1:tt $tt2:tt) => {{
671 ($span:expr=> $($tt:tt)*) => {{
674 $crate::quote_each_token_spanned!{_s _span $($tt)*}
689 ($call:ident! $extra:tt $($tts:tt)*) => {
700 ($call:ident! $extra:tt ($($b1:tt)*) ($($curr:tt)*)) => {
710 ($call:ident! $extra:tt $b1:tt ( $($inner:tt)* )) => {
714 ($call:ident! $extra:tt $b1:tt [ $($inner:tt)* ]) => {
718 ($call:ident! $extra:tt $b1:tt { $($inner:tt)* }) => {
722 ($call:ident!($($extra:tt)*) # $var:ident) => {
726 ($call:ident! $extra:tt $b1:tt $curr:tt) => {};
751 // The obvious way to write this macro is as a tt muncher. This implementation
754 // - With a tt muncher it's easy to hit Rust's built-in recursion_limit, which
757 // - Compile times for a tt muncher are quadratic relative to the length of
760 // of this implementation are higher than that of a tt muncher, so it is
761 // somewhat slower than a tt muncher if there are many invocations with
799 // Without having used muncher-style recursion, we get one invocation of
800 // quote_token_with_context for each original tt, with three tts of context on
803 // the first or last tt in the middle.
805 // The middle tt (surrounded by parentheses) is the tt being processed.
807 // - When it is a `#`, quote_token_with_context can do an interpolation. The
810 // - When it is within a later part of an interpolation, it can be ignored
813 // - When it is not part of an interpolation it can be pushed as a single
816 // - When the middle token is an unparenthesized `@`, that call is one of the
822 ($tokens:ident $($tts:tt)*) => {
839 ($tokens:ident $span:ident $($tts:tt)*) => {
857 ($($b3:tt)*) ($($b2:tt)*) ($($b1:tt)*)
858 ($($curr:tt)*)
859 ($($a1:tt)*) ($($a2:tt)*) ($($a3:tt)*)
872 ($($b3:tt)*) ($($b2:tt)*) ($($b1:tt)*)
873 ($($curr:tt)*)
874 ($($a1:tt)*) ($($a2:tt)*) ($($a3:tt)*)
888 ($tokens:ident $b3:tt $b2:tt $b1:tt @ $a1:tt $a2:tt $a3:tt) => {};
891 ($tokens:ident $b3:tt $b2:tt $b1:tt (#) ( $($inner:tt)* ) * $a3:tt) => {{
908 ($tokens:ident $b3:tt $b2:tt # (( $($inner:tt)* )) * $a2:tt $a3:tt) => {};
910 ($tokens:ident $b3:tt # ( $($inner:tt)* ) (*) $a1:tt $a2:tt $a3:tt) => {};
913 ($tokens:ident $b3:tt $b2:tt $b1:tt (#) ( $($inner:tt)* ) $sep:tt *) => {{
929 ($tokens:ident $b3:tt $b2:tt # (( $($inner:tt)* )) $sep:tt * $a3:tt) => {};
931 ($tokens:ident $b3:tt # ( $($inner:tt)* ) ($sep:tt) * $a2:tt $a3:tt) => {};
934 ($tokens:ident # ( $($inner:tt)* ) * (*) $a1:tt $a2:tt $a3:tt) => {
939 ($tokens:ident # ( $($inner:tt)* ) $sep:tt (*) $a1:tt $a2:tt $a3:tt) => {};
941 // A non-repetition interpolation.
942 ($tokens:ident $b3:tt $b2:tt $b1:tt (#) $var:ident $a2:tt $a3:tt) => {
946 ($tokens:ident $b3:tt $b2:tt # ($var:ident) $a1:tt $a2:tt $a3:tt) => {};
949 ($tokens:ident $b3:tt $b2:tt $b1:tt ($curr:tt) $a1:tt $a2:tt $a3:tt) => {
959 ($tokens:ident $span:ident $b3:tt $b2:tt $b1:tt @ $a1:tt $a2:tt $a3:tt) => {};
961 ($tokens:ident $span:ident $b3:tt $b2:tt $b1:tt (#) ( $($inner:tt)* ) * $a3:tt) => {{
971 ($tokens:ident $span:ident $b3:tt $b2:tt # (( $($inner:tt)* )) * $a2:tt $a3:tt) => {};
972 ($tokens:ident $span:ident $b3:tt # ( $($inner:tt)* ) (*) $a1:tt $a2:tt $a3:tt) => {};
974 ($tokens:ident $span:ident $b3:tt $b2:tt $b1:tt (#) ( $($inner:tt)* ) $sep:tt *) => {{
989 ($tokens:ident $span:ident $b3:tt $b2:tt # (( $($inner:tt)* )) $sep:tt * $a3:tt) => {};
990 ($tokens:ident $span:ident $b3:tt # ( $($inner:tt)* ) ($sep:tt) * $a2:tt $a3:tt) => {};
991 ($tokens:ident $span:ident # ( $($inner:tt)* ) * (*) $a1:tt $a2:tt $a3:tt) => {
995 ($tokens:ident $span:ident # ( $($inner:tt)* ) $sep:tt (*) $a1:tt $a2:tt $a3:tt) => {};
997 ($tokens:ident $span:ident $b3:tt $b2:tt $b1:tt (#) $var:ident $a2:tt $a3:tt) => {
1000 ($tokens:ident $span:ident $b3:tt $b2:tt # ($var:ident) $a1:tt $a2:tt $a3:tt) => {};
1002 ($tokens:ident $span:ident $b3:tt $b2:tt $b1:tt ($curr:tt) $a1:tt $a2:tt $a3:tt) => {
1009 // most important because it's typically 2-3x more common than the next most
1025 (( $($inner:tt)* ) $tokens:ident) => {
1033 ([ $($inner:tt)* ] $tokens:ident) => {
1041 ({ $($inner:tt)* } $tokens:ident) => {
1173 (-> $tokens:ident) => {
1177 (<- $tokens:ident) => {
1213 (- $tokens:ident) => {
1217 (-= $tokens:ident) => {
1229 ($other:tt $tokens:ident) => {
1246 (( $($inner:tt)* ) $tokens:ident $span:ident) => {
1255 ([ $($inner:tt)* ] $tokens:ident $span:ident) => {
1264 ({ $($inner:tt)* } $tokens:ident $span:ident) => {
1397 (-> $tokens:ident $span:ident) => {
1401 (<- $tokens:ident $span:ident) => {
1437 (- $tokens:ident $span:ident) => {
1441 (-= $tokens:ident $span:ident) => {
1453 ($other:tt $tokens:ident $span:ident) => {