@@ -178,20 +178,8 @@ expand({quote, Meta, [Opts, Do]}, S, E) when is_list(Do) ->
178
178
false -> file_error (Meta , E , ? MODULE , {missing_option , 'quote' , [do ]})
179
179
end ,
180
180
181
- {Binding , DefaultUnquote , ToExpandOpts } =
182
- case is_list (Opts ) andalso lists :keytake (bind_quoted , 1 , Opts ) of
183
- {value , {bind_quoted , BQ }, BQOpts } ->
184
- case is_list (BQ ) andalso
185
- lists :all (fun ({Key , _ }) when is_atom (Key ) -> true ; (_ ) -> false end , BQ ) of
186
- true -> {BQ , false , BQOpts };
187
- false -> file_error (Meta , E , ? MODULE , {invalid_bind_quoted_for_quote , BQ })
188
- end ;
189
- false ->
190
- {[], true , Opts }
191
- end ,
192
-
193
- ValidKeys = [context , location , line , file , unquote , bind_quoted , generated ],
194
- {EOpts , ST , ET } = expand_opts (Meta , quote , ValidKeys , ToExpandOpts , S , E ),
181
+ ValidOpts = [context , location , line , file , unquote , bind_quoted , generated ],
182
+ {EOpts , ST , ET } = expand_opts (Meta , quote , ValidOpts , Opts , S , E ),
195
183
196
184
Context = proplists :get_value (context , EOpts , case ? key (E , module ) of
197
185
nil -> 'Elixir' ;
@@ -205,12 +193,44 @@ expand({quote, Meta, [Opts, Do]}, S, E) when is_list(Do) ->
205
193
{proplists :get_value (file , EOpts , nil ), proplists :get_value (line , EOpts , false )}
206
194
end ,
207
195
196
+ {Binding , DefaultUnquote } = case lists :keyfind (bind_quoted , 1 , EOpts ) of
197
+ {bind_quoted , BQ } ->
198
+ case is_list (BQ ) andalso
199
+ lists :all (fun ({Key , _ }) when is_atom (Key ) -> true ; (_ ) -> false end , BQ ) of
200
+ true -> {BQ , false };
201
+ false -> file_error (Meta , E , ? MODULE , {invalid_bind_quoted_for_quote , BQ })
202
+ end ;
203
+ false ->
204
+ {[], true }
205
+ end ,
206
+
208
207
Unquote = proplists :get_value (unquote , EOpts , DefaultUnquote ),
209
208
Generated = proplists :get_value (generated , EOpts , false ),
210
209
211
- {Q , Prelude } = elixir_quote :build (Meta , Line , File , Context , Unquote , Generated , ET ),
212
- Quoted = elixir_quote :quote (Meta , Exprs , Binding , Q , Prelude ),
213
- expand (Quoted , ST , ET );
210
+ {Q , QContext , QPrelude } = elixir_quote :build (Meta , Line , File , Context , Unquote , Generated , ET ),
211
+ {EPrelude , SP , EP } = expand (QPrelude , ST , ET ),
212
+ {EContext , SC , EC } = expand (QContext , SP , EP ),
213
+ Quoted = elixir_quote :quote (Exprs , Q ),
214
+ {EQuoted , ES , EQ } = expand (Quoted , SC , EC ),
215
+
216
+ EBinding =
217
+ [{'{}' , [],
218
+ ['=' , [], [
219
+ {'{}' , [], [K , Meta , EContext ]},
220
+ V
221
+ ]
222
+ ]} || {K , V } <- Binding ],
223
+
224
+ EBindingQuoted =
225
+ case EBinding of
226
+ [] -> EQuoted ;
227
+ _ -> {'{}' , [], ['__block__' , [], EBinding ++ [EQuoted ]]}
228
+ end ,
229
+
230
+ case EPrelude of
231
+ [] -> {EBindingQuoted , ES , EQ };
232
+ _ -> {{'__block__' , [], EPrelude ++ [EBindingQuoted ]}, ES , EQ }
233
+ end ;
214
234
215
235
expand ({quote , Meta , [_ , _ ]}, _S , E ) ->
216
236
file_error (Meta , E , ? MODULE , {invalid_args , 'quote' });
0 commit comments