Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions lib/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,15 @@ defmodule SQL.Format do
defp pad([?\n|_]=acc), do: acc
defp pad(acc), do: [?\n|acc]

defp color(true, string, acc), do: [@keyword, string, @reset | acc]
defp color(false, string, acc), do: [string | acc]

newline = ~w[select from join where having window limit offset fetch when else end returning set]a
{reserved, non_reserved, operators} = SQL.BNF.get_rules()
for atom <- Enum.uniq(Enum.map(reserved++non_reserved++operators,&elem(&1, 0))), atom not in newline do
defp to_iodata(unquote(atom), true, _binding ,:lower, _errors, _indent, acc) do
[@keyword, unquote("#{atom}"), @reset|acc]
end
defp to_iodata(unquote(atom), true, _binding, :upper, _errors, _indent, acc) do
[@keyword, unquote(String.upcase("#{atom}")), @reset|acc]
end
defp to_iodata(unquote(atom), false, _binding ,:lower, _errors, _indent, acc) do
[unquote("#{atom}")|acc]
end
defp to_iodata(unquote(atom), false, _binding, :upper, _errors, _indent, acc) do
[unquote(String.upcase("#{atom}"))|acc]
defp to_iodata(unquote(atom), color, _binding, case, _errors, _indent, acc) do
string = if(case == :upper, do: unquote(String.upcase("#{atom}")), else: unquote("#{atom}"))
color(color, string, acc)
end
end
for atom <- newline do
Expand Down
7 changes: 2 additions & 5 deletions lib/token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ defmodule SQL.Token do

{reserved, non_reserved, operators} = SQL.BNF.get_rules()
for atom <- Enum.uniq(Enum.map(reserved++non_reserved++operators,&elem(&1, 0))) do
defp __to_iodata__(unquote(atom), _format, :lower, acc) do
[unquote("#{atom}")|acc]
end
defp __to_iodata__(unquote(atom), _format, :upper, acc) do
[unquote(String.upcase("#{atom}"))|acc]
defp __to_iodata__(unquote(atom), _format, case, acc) do
[if(case == :upper, do: unquote(String.upcase("#{atom}")), else: unquote("#{atom}"))|acc]
end
end
defp __to_iodata__(:comma, _format, _case, acc) do
Expand Down
Loading