| 1 | |
| 2 |
|
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | #[macro_export]
|
| 92 | macro_rules! custom_keyword {
|
| 93 | ($ident:ident) => {
|
| 94 | #[allow(non_camel_case_types)]
|
| 95 | pub struct $ident {
|
| 96 | #[allow(dead_code)]
|
| 97 | pub span: $crate::__private::Span,
|
| 98 | }
|
| 99 |
|
| 100 | #[doc(hidden)]
|
| 101 | #[allow(dead_code, non_snake_case)]
|
| 102 | pub fn $ident<__S: $crate::__private::IntoSpans<$crate::__private::Span>>(
|
| 103 | span: __S,
|
| 104 | ) -> $ident {
|
| 105 | $ident {
|
| 106 | span: $crate::__private::IntoSpans::into_spans(span),
|
| 107 | }
|
| 108 | }
|
| 109 |
|
| 110 | const _: () = {
|
| 111 | impl $crate::__private::Default for $ident {
|
| 112 | fn default() -> Self {
|
| 113 | $ident {
|
| 114 | span: $crate::__private::Span::call_site(),
|
| 115 | }
|
| 116 | }
|
| 117 | }
|
| 118 |
|
| 119 | $crate::impl_parse_for_custom_keyword!($ident);
|
| 120 | $crate::impl_to_tokens_for_custom_keyword!($ident);
|
| 121 | $crate::impl_clone_for_custom_keyword!($ident);
|
| 122 | $crate::impl_extra_traits_for_custom_keyword!($ident);
|
| 123 | };
|
| 124 | };
|
| 125 | }
|
| 126 |
|
| 127 | |
| 128 | #[cfg(feature = "parsing")]
|
| 129 | #[doc(hidden)]
|
| 130 | #[macro_export]
|
| 131 | macro_rules! impl_parse_for_custom_keyword {
|
| 132 | ($ident:ident) => {
|
| 133 | |
| 134 | impl $crate::__private::CustomToken for $ident {
|
| 135 | fn peek(cursor: $crate::buffer::Cursor) -> $crate::__private::bool {
|
| 136 | if let $crate::__private::Some((ident, _rest)) = cursor.ident() {
|
| 137 | ident == $crate::__private::stringify!($ident)
|
| 138 | } else {
|
| 139 | false
|
| 140 | }
|
| 141 | }
|
| 142 |
|
| 143 | fn display() -> &'static $crate::__private::str {
|
| 144 | $crate::__private::concat!("`", $crate::__private::stringify!($ident), "`")
|
| 145 | }
|
| 146 | }
|
| 147 |
|
| 148 | impl $crate::parse::Parse for $ident {
|
| 149 | fn parse(input: $crate::parse::ParseStream) -> $crate::parse::Result<$ident> {
|
| 150 | input.step(|cursor| {
|
| 151 | if let $crate::__private::Some((ident, rest)) = cursor.ident() {
|
| 152 | if ident == $crate::__private::stringify!($ident) {
|
| 153 | return $crate::__private::Ok(($ident { span: ident.span() }, rest));
|
| 154 | }
|
| 155 | }
|
| 156 | $crate::__private::Err(cursor.error($crate::__private::concat!(
|
| 157 | "expected `",
|
| 158 | $crate::__private::stringify!($ident),
|
| 159 | "`",
|
| 160 | )))
|
| 161 | })
|
| 162 | }
|
| 163 | }
|
| 164 | };
|
| 165 | }
|
| 166 |
|
| 167 | |
| 168 | #[cfg(not(feature = "parsing"))]
|
| 169 | #[doc(hidden)]
|
| 170 | #[macro_export]
|
| 171 | macro_rules! impl_parse_for_custom_keyword {
|
| 172 | ($ident:ident) => {};
|
| 173 | }
|
| 174 |
|
| 175 | |
| 176 | #[cfg(feature = "printing")]
|
| 177 | #[doc(hidden)]
|
| 178 | #[macro_export]
|
| 179 | macro_rules! impl_to_tokens_for_custom_keyword {
|
| 180 | ($ident:ident) => {
|
| 181 | impl $crate::__private::ToTokens for $ident {
|
| 182 | fn to_tokens(&self, tokens: &mut $crate::__private::TokenStream2) {
|
| 183 | let ident = $crate::Ident::new($crate::__private::stringify!($ident), self.span);
|
| 184 | $crate::__private::TokenStreamExt::append(tokens, ident);
|
| 185 | }
|
| 186 | }
|
| 187 | };
|
| 188 | }
|
| 189 |
|
| 190 | |
| 191 | #[cfg(not(feature = "printing"))]
|
| 192 | #[doc(hidden)]
|
| 193 | #[macro_export]
|
| 194 | macro_rules! impl_to_tokens_for_custom_keyword {
|
| 195 | ($ident:ident) => {};
|
| 196 | }
|
| 197 |
|
| 198 | |
| 199 | #[cfg(feature = "clone-impls")]
|
| 200 | #[doc(hidden)]
|
| 201 | #[macro_export]
|
| 202 | macro_rules! impl_clone_for_custom_keyword {
|
| 203 | ($ident:ident) => {
|
| 204 | impl $crate::__private::Copy for $ident {}
|
| 205 |
|
| 206 | #[allow(clippy::expl_impl_clone_on_copy)]
|
| 207 | impl $crate::__private::Clone for $ident {
|
| 208 | fn clone(&self) -> Self {
|
| 209 | *self
|
| 210 | }
|
| 211 | }
|
| 212 | };
|
| 213 | }
|
| 214 |
|
| 215 | |
| 216 | #[cfg(not(feature = "clone-impls"))]
|
| 217 | #[doc(hidden)]
|
| 218 | #[macro_export]
|
| 219 | macro_rules! impl_clone_for_custom_keyword {
|
| 220 | ($ident:ident) => {};
|
| 221 | }
|
| 222 |
|
| 223 | |
| 224 | #[cfg(feature = "extra-traits")]
|
| 225 | #[doc(hidden)]
|
| 226 | #[macro_export]
|
| 227 | macro_rules! impl_extra_traits_for_custom_keyword {
|
| 228 | ($ident:ident) => {
|
| 229 | impl $crate::__private::Debug for $ident {
|
| 230 | fn fmt(&self, f: &mut $crate::__private::Formatter) -> $crate::__private::FmtResult {
|
| 231 | $crate::__private::Formatter::write_str(
|
| 232 | f,
|
| 233 | $crate::__private::concat!(
|
| 234 | "Keyword [",
|
| 235 | $crate::__private::stringify!($ident),
|
| 236 | "]",
|
| 237 | ),
|
| 238 | )
|
| 239 | }
|
| 240 | }
|
| 241 |
|
| 242 | impl $crate::__private::Eq for $ident {}
|
| 243 |
|
| 244 | impl $crate::__private::PartialEq for $ident {
|
| 245 | fn eq(&self, _other: &Self) -> $crate::__private::bool {
|
| 246 | true
|
| 247 | }
|
| 248 | }
|
| 249 |
|
| 250 | impl $crate::__private::Hash for $ident {
|
| 251 | fn hash<__H: $crate::__private::Hasher>(&self, _state: &mut __H) {}
|
| 252 | }
|
| 253 | };
|
| 254 | }
|
| 255 |
|
| 256 | |
| 257 | #[cfg(not(feature = "extra-traits"))]
|
| 258 | #[doc(hidden)]
|
| 259 | #[macro_export]
|
| 260 | macro_rules! impl_extra_traits_for_custom_keyword {
|
| 261 | ($ident:ident) => {};
|
| 262 | }
|