Packages

A library for parsing a simple query language into an abstract syntax tree.

Current section

Files

Jump to
dreaeql lib terms.ex
Raw

lib/terms.ex

defmodule DreaeQL.Terms do
defmacro term(name, type, params) do
quote do
defmodule DreaeQL.Terms.unquote(name) do
@type t :: %DreaeQL.Terms.unquote(name){term: unquote(type)}
defstruct [term: unquote(type)] ++ unquote(params)
end
end
end
defmacro literal(name, type) do
quote do
DreaeQL.Terms.term(unquote(name), unquote(type), [:value])
end
end
defmacro __using__(_params) do
quote do
alias DreaeQL.Terms
Terms.literal LiteralInt, :int
Terms.literal LiteralFloat, :float
Terms.literal LiteralBool, :bool
Terms.literal LiteralString, :string
Terms.term Identifier, :ident, [:ident]
@type dreaeql_term ::
Terms.Identifier.t
| Terms.LiteralBool.t
| Terms.LiteralInt.t
| Terms.LiteralFloat.t
| Terms.LiteralString.t
end
end
end