@@ -222,7 +222,7 @@ defmodule SQL.Parser do
222
222
def parse ( << ?# , ?{ , rest :: binary >> , binary , opts , line , column , _type , data , unit , context , metadata , acc , root ) do
223
223
column = column + 2
224
224
binding = opts [ :binding ]
225
- case interpolation ( rest , line , column ) do
225
+ case interpolation ( rest , binding , line , column ) do
226
226
{ :error , "" , end_line , end_column , _acc } ->
227
227
error! ( [ line: line , column: column , end_line: end_line , end_column: end_column , file: "" , snippet: binary , opening_delimiter: :"\# {" , expected_delimiter: :"}" ] )
228
228
{ rest , end_line , end_column , result } when binding == false ->
@@ -233,7 +233,7 @@ defmodule SQL.Parser do
233
233
else
234
234
raise ArgumentError , "The variable #{ result } is not defined"
235
235
end
236
- { rest , end_line , end_column , result } ->
236
+ { rest , end_line , end_column , { result , _ } } ->
237
237
parse ( rest , binary , update_in ( opts , [ :params ] , & ( & 1 ++ [ result ] ) ) , end_line , end_column , nil , data , unit ++ [ { :binding , [ line: line , column: column , end_line: end_line , end_column: end_column ] , [ length ( opts [ :params ] ) ] } ] , context , metadata , acc , root )
238
238
end
239
239
end
@@ -287,27 +287,30 @@ defmodule SQL.Parser do
287
287
parse ( rest , binary , opts , line , column + 1 , type ( b , type ) , data ++ [ b ] , unit , context , metadata , acc , root )
288
288
end
289
289
290
- def interpolation ( binary , line , column , type \\ :var , acc \\ [ ] , n \\ 0 )
291
- def interpolation ( "" = rest , line , column , _type , acc , 0 ) , do: { :error , rest , line , column , acc }
292
- def interpolation ( << ?} , rest :: binary >> , line , column , :var , acc , 0 ) do
290
+ def interpolation ( binary , binding , line , column , type \\ :var , acc \\ [ ] , n \\ 0 )
291
+ def interpolation ( "" = rest , _binding , line , column , _type , acc , 0 ) , do: { :error , rest , line , column , acc }
292
+ def interpolation ( << ?} , rest :: binary >> , _binding , line , column , :var , acc , 0 ) do
293
293
{ << rest :: binary >> , line , column + 1 , List . to_atom ( acc ) }
294
294
end
295
- def interpolation ( << ?} , rest :: binary >> , line , column , :code , acc , 0 ) do
296
- { << rest :: binary >> , line , column + 1 , acc }
295
+ def interpolation ( << ?} , rest :: binary >> , binding , line , column , :code , acc , 0 ) do
296
+ { << rest :: binary >> , line , column + 1 , Code . eval_string ( "#{ acc } " , binding ) }
297
+ end
298
+ def interpolation ( << ?{ , rest :: binary >> , binding , line , column , _type , acc , n ) do
299
+ interpolation ( rest , binding , line , column , :code , acc ++ [ ?{ ] , n + 1 )
297
300
end
298
- def interpolation ( << ?{ , rest :: binary >> , line , column , _type , acc , n ) do
299
- interpolation ( rest , line , column , :code , acc ++ [ ?{ ] , n + 1 )
301
+ def interpolation ( << ?} , rest :: binary >> , binding , line , column , type , acc , n ) do
302
+ interpolation ( rest , binding , line , column + 1 , type , acc ++ [ ?} ] , n - 1 )
300
303
end
301
- def interpolation ( << ?} , rest :: binary >> , line , column , type , acc , n ) do
302
- interpolation ( rest , line , column + 1 , type , acc ++ [ ?} ] , n - 1 )
304
+ def interpolation ( << v , rest :: binary >> , binding , line , column , :var = type , acc , n ) when v in ?0 .. ?9 and acc != [ ] do
305
+ interpolation ( rest , binding , line + 1 , column , type , acc ++ [ v ] , n )
303
306
end
304
- def interpolation ( << v , rest :: binary >> , line , column , :var = type , acc , n ) when v in ?a .. ?z or v in ?A .. ?Z or ( v == ?_ and acc != [ ] ) do
305
- interpolation ( rest , line + 1 , column , type , acc ++ [ v ] , n )
307
+ def interpolation ( << v , rest :: binary >> , binding , line , column , :var = type , acc , n ) when v in ?a .. ?z or v in ?A .. ?Z or ( v == ?_ and acc != [ ] ) do
308
+ interpolation ( rest , binding , line + 1 , column , type , acc ++ [ v ] , n )
306
309
end
307
- def interpolation ( << ?\n , rest :: binary >> , line , column , _type , acc , n ) do
308
- interpolation ( rest , line + 1 , column , :code , acc ++ [ ?\n ] , n )
310
+ def interpolation ( << ?\n , rest :: binary >> , binding , line , column , _type , acc , n ) do
311
+ interpolation ( rest , binding , line + 1 , column , :code , acc ++ [ ?\n ] , n )
309
312
end
310
- def interpolation ( << v , rest :: binary >> , line , column , _type , acc , n ) do
311
- interpolation ( rest , line , column + 1 , :code , acc ++ [ v ] , n )
313
+ def interpolation ( << v , rest :: binary >> , binding , line , column , _type , acc , n ) do
314
+ interpolation ( rest , binding , line , column + 1 , :code , acc ++ [ v ] , n )
312
315
end
313
316
end
0 commit comments