Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added mix neotoma task and mix.exs for elixir #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ebin/*.beam
ebin/neotoma.app
_build/
extra/*.beam
*#*
.eunit
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.7.2
69 changes: 69 additions & 0 deletions lib/mix/tasks/compile.neotoma.ex
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -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