From 3900b54cc90be9c882bbbcd5585fae34faf09728 Mon Sep 17 00:00:00 2001 From: Thomas Moulia Date: Wed, 16 Jul 2014 13:08:50 -0700 Subject: [PATCH] added mix neotoma task and mix.exs for elixir mix.exs is used instead of project.exs so that the neotoma task will be compiled. The downside is that there are now configs for two different build tools, elixir and rebar. Luckily, the rebar config is primarily for testing. --- .gitignore | 1 + VERSION | 1 + lib/mix/tasks/compile.neotoma.ex | 69 ++++++++++++++++++++++++++++++++ mix.exs | 32 +++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 VERSION create mode 100644 lib/mix/tasks/compile.neotoma.ex create mode 100644 mix.exs diff --git a/.gitignore b/.gitignore index cbe6bac..3777770 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ ebin/*.beam ebin/neotoma.app +_build/ extra/*.beam *#* .eunit diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..0a182f2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.7.2 \ No newline at end of file diff --git a/lib/mix/tasks/compile.neotoma.ex b/lib/mix/tasks/compile.neotoma.ex new file mode 100644 index 0000000..17d4315 --- /dev/null +++ b/lib/mix/tasks/compile.neotoma.ex @@ -0,0 +1,69 @@ +defmodule Mix.Tasks.Compile.Neotoma do + use Mix.Task + alias Mix.Compilers.Erlang + + @recursive true + @manifest ".compile.peg" + + @moduledoc """ + Compile peg source files using Neotoma. + + When this task runs, it will check the modification time of every file, and + if it has changed, the file will be compiled. Files will be + compiled in the same source directory with a .erl extension. + You can force compilation regardless of modification times by passing + the `--force` option. + + ## Command line options + + * `--force` - forces compilation regardless of modification times + + ## Configuration + + * `:erlc_paths` - directories to find source files. Defaults to `["src"]`. + + * `:neotoma_options` - compilation options that apply + to Neooma's PEG compiler. There are many other available + options here: http://www.erlang.org/doc/man/yecc.html#file-1. + + """ + + @doc """ + Runs this task. + """ + def run(args) do + {opts, _, _} = OptionParser.parse(args, switches: [force: :boolean]) + + project = Mix.Project.config + source_paths = project[:erlc_paths] + mappings = Enum.zip(source_paths, source_paths) + options = project[:neotoma_options] || [] + + Erlang.compile(manifest(), mappings, :peg, :erl, opts[:force], fn + input, output -> + # Neotoma accepts the output dir, not the output filename + options = options ++ [output: Path.dirname(output)] + + # Neotoma's file\1,2 functions' return value is adjusted for Erlang.compile/6 + case :neotoma.file(Erlang.to_erl_file(input), options) do + :ok -> + {:ok, Path.basename(input, ".peg")} + {:error, _} -> + :error + end + end) + end + + @doc """ + Returns Peg manifests. + """ + def manifests, do: [manifest] + defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest) + + @doc """ + Cleans up compilation artifacts. + """ + def clean do + Erlang.clean(manifest()) + end +end diff --git a/mix.exs b/mix.exs new file mode 100644 index 0000000..639f6bc --- /dev/null +++ b/mix.exs @@ -0,0 +1,32 @@ +defmodule Neotoma.Mixfile do + use Mix.Project + + @version File.read!("VERSION") |> String.strip + + def project do + [app: :neotoma, + version: @version, + elixir: "~> 0.14", + package: package, + description: description + ] + end + + def application do + [applications: []] + end + + defp package do + [files: ~w(src lib mix.exs priv rebar.config README.textile LICENSE VERSION), + contributors: ["Sean Cribbs"], + licenses: ["MIT License"], + links: %{"GitHub" => "https://github.com/seancribbs/neotoma"}] + end + + defp description do + """ + Erlang library and packrat parser-generator for parsing expression grammars. + """ + end + +end \ No newline at end of file