@@ -9,6 +9,14 @@ defmodule SQL.Parser do
9
9
def context ( ?[ ) , do: :"[]"
10
10
def context ( ?( ) , do: :"()"
11
11
12
+ def type ( % param { } ) , do: param
13
+ def type ( param ) when is_float ( param ) , do: :float
14
+ def type ( param ) when is_integer ( param ) , do: :integer
15
+ def type ( param ) when is_map ( param ) , do: :map
16
+ def type ( param ) when is_list ( param ) , do: { :list , Enum . uniq ( Enum . map ( param , & type / 1 ) ) }
17
+ def type ( param ) when is_binary ( param ) , do: :string
18
+ def type ( _param ) , do: nil
19
+
12
20
def type ( ?. , :integer ) , do: :float
13
21
def type ( b , type ) when b in ?0 .. ?9 and type in ~w[ nil integer float] a , do: type || :integer
14
22
def type ( _b , _type ) , do: :ident
@@ -229,12 +237,12 @@ defmodule SQL.Parser do
229
237
parse ( rest , binary , opts , end_line , end_column , nil , data , unit ++ [ { :"\# {}" , [ line: line , column: column , end_line: end_line , end_column: end_column ] , [ result ] } ] , context , metadata , acc , root )
230
238
{ rest , end_line , end_column , result } when is_atom ( result ) ->
231
239
if param = binding [ result ] do
232
- parse ( rest , binary , update_in ( opts , [ :params ] , & ( & 1 ++ [ param ] ) ) , 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 )
240
+ parse ( rest , binary , update_in ( opts , [ :params ] , & ( & 1 ++ [ param ] ) ) , end_line , end_column , nil , data , unit ++ [ { :binding , [ type: type ( param ) , line: line , column: column , end_line: end_line , end_column: end_column ] , [ length ( opts [ :params ] ) + 1 ] } ] , context , metadata , acc , root )
233
241
else
234
242
raise ArgumentError , "The variable #{ result } is not defined"
235
243
end
236
- { rest , end_line , end_column , { result , _ } } ->
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 )
244
+ { rest , end_line , end_column , { param , _ } } ->
245
+ parse ( rest , binary , update_in ( opts , [ :params ] , & ( & 1 ++ [ param ] ) ) , end_line , end_column , nil , data , unit ++ [ { :binding , [ type: type ( param ) , line: line , column: column , end_line: end_line , end_column: end_column ] , [ length ( opts [ :params ] ) + 1 ] } ] , context , metadata , acc , root )
238
246
end
239
247
end
240
248
def parse ( << ?) , rest :: binary >> , _binary , opts , line , column , type , data , unit , :"()" = context , metadata , acc , root ) do
0 commit comments