@@ -9,6 +9,14 @@ defmodule SQL.Parser do
99 def context ( ?[ ) , do: :"[]"
1010 def context ( ?( ) , do: :"()"
1111
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+
1220 def type ( ?. , :integer ) , do: :float
1321 def type ( b , type ) when b in ?0 .. ?9 and type in ~w[ nil integer float] a , do: type || :integer
1422 def type ( _b , _type ) , do: :ident
@@ -229,12 +237,12 @@ defmodule SQL.Parser do
229237 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 )
230238 { rest , end_line , end_column , result } when is_atom ( result ) ->
231239 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 )
233241 else
234242 raise ArgumentError , "The variable #{ result } is not defined"
235243 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 )
238246 end
239247 end
240248 def parse ( << ?) , rest :: binary >> , _binary , opts , line , column , type , data , unit , :"()" = context , metadata , acc , root ) do
0 commit comments