|
| 1 | +use quote::{quote, quote_spanned}; |
1 | 2 | use syn::parse::{Parse, ParseStream, Result}; |
2 | 3 | use syn::punctuated::Punctuated; |
3 | 4 | use syn::{Block, Error, Expr, Ident, Token, braced}; |
4 | 5 |
|
| 6 | +use crate::query::Query; |
| 7 | + |
5 | 8 | pub(crate) struct Desc { |
6 | 9 | pub(crate) modifier: Ident, |
7 | 10 | pub(crate) expr_list: Punctuated<Expr, Token![,]>, |
@@ -115,3 +118,68 @@ pub(crate) fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModif |
115 | 118 | return_result_from_ensure_ok, |
116 | 119 | }) |
117 | 120 | } |
| 121 | + |
| 122 | +pub(crate) fn make_modifiers_stream( |
| 123 | + query: &Query, |
| 124 | + modifiers: &QueryModifiers, |
| 125 | +) -> proc_macro2::TokenStream { |
| 126 | + let QueryModifiers { |
| 127 | + // tidy-alphabetical-start |
| 128 | + anon, |
| 129 | + arena_cache, |
| 130 | + cache_on_disk_if, |
| 131 | + cycle_delay_bug, |
| 132 | + cycle_fatal, |
| 133 | + cycle_stash, |
| 134 | + depth_limit, |
| 135 | + desc: _, |
| 136 | + eval_always, |
| 137 | + feedable, |
| 138 | + no_hash, |
| 139 | + return_result_from_ensure_ok, |
| 140 | + separate_provide_extern, |
| 141 | + // tidy-alphabetical-end |
| 142 | + } = modifiers; |
| 143 | + |
| 144 | + let is_anon = anon.is_some(); |
| 145 | + let is_arena_cache = arena_cache.is_some(); |
| 146 | + let is_cache_on_disk = cache_on_disk_if.is_some(); |
| 147 | + |
| 148 | + let cycle_error_handling = if cycle_delay_bug.is_some() { |
| 149 | + quote! { DelayBug } |
| 150 | + } else if cycle_fatal.is_some() { |
| 151 | + quote! { Fatal } |
| 152 | + } else if cycle_stash.is_some() { |
| 153 | + quote! { Stash } |
| 154 | + } else { |
| 155 | + quote! { Error } |
| 156 | + }; |
| 157 | + |
| 158 | + let is_depth_limit = depth_limit.is_some(); |
| 159 | + let is_eval_always = eval_always.is_some(); |
| 160 | + let is_feedable = feedable.is_some(); |
| 161 | + let is_no_hash = no_hash.is_some(); |
| 162 | + let is_return_result_from_ensure_ok = return_result_from_ensure_ok.is_some(); |
| 163 | + let is_separate_provide_extern = separate_provide_extern.is_some(); |
| 164 | + |
| 165 | + // Giving an input span to the modifier names in the modifier list seems |
| 166 | + // to give slightly more helpful errors when one of the callback macros |
| 167 | + // fails to parse the modifier list. |
| 168 | + let query_name_span = query.name.span(); |
| 169 | + quote_spanned! { |
| 170 | + query_name_span => |
| 171 | + // Search for (QMODLIST) to find all occurrences of this query modifier list. |
| 172 | + // tidy-alphabetical-start |
| 173 | + anon: #is_anon, |
| 174 | + arena_cache: #is_arena_cache, |
| 175 | + cache_on_disk: #is_cache_on_disk, |
| 176 | + cycle_error_handling: #cycle_error_handling, |
| 177 | + depth_limit: #is_depth_limit, |
| 178 | + eval_always: #is_eval_always, |
| 179 | + feedable: #is_feedable, |
| 180 | + no_hash: #is_no_hash, |
| 181 | + return_result_from_ensure_ok: #is_return_result_from_ensure_ok, |
| 182 | + separate_provide_extern: #is_separate_provide_extern, |
| 183 | + // tidy-alphabetical-end |
| 184 | + } |
| 185 | +} |
0 commit comments