Skip to content

Commit

Permalink
Merge pull request #10 from doubleyou/master
Browse files Browse the repository at this point in the history
Add escript building
  • Loading branch information
seancribbs committed Feb 5, 2012
2 parents 6cb132b + ebbd9f7 commit 2becaac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -15,3 +15,6 @@ dialyze: compile
bootstrap: compile
@ erl -pz ebin -b start_sasl -noshell -s init stop -eval 'neotoma:bootstrap().'
@ rebar compile

escript:
@ rebar escriptize
19 changes: 19 additions & 0 deletions src/neotoma.erl
@@ -1,9 +1,17 @@
-module(neotoma).
-author("Sean Cribbs <seancribbs@gmail.com>").
-export([file/1, file/2, bootstrap/0]).
-export([main/1]).

-type option() :: {module, atom()} | {output, file:filename()} | {transform_module, atom()}.

%% @doc Handler function for escript.
-spec main(list()) -> ok | no_return().
main([]) ->
io:format("Usage: neotoma filename [-module output_module] [-output output_dir] [-transform_module transform_module]\n");
main([Filename | Args]) ->
file(Filename, parse_options(Args)).

%% @doc Generates a parser from the specified file.
%% @equiv file(Filename, [])
-spec file(file:filename()) -> ok.
Expand Down Expand Up @@ -117,3 +125,14 @@ generate_transform_stub(XfFile,ModName) ->
-spec bootstrap() -> 'ok'.
bootstrap() ->
file("priv/neotoma_parse.peg", [{output, "src/"}]).

%% @doc Parses arguments passed to escript
-spec parse_options(list()) -> list().
parse_options(["-module", ModName | Rest]) ->
[{module, list_to_atom(ModName)} | parse_options(Rest)];
parse_options(["-output", Dir | Rest]) ->
[{output, Dir} | parse_options(Rest)];
parse_options(["-transform_module", ModName | Rest]) ->
[{transform_module, list_to_atom(ModName)} | parse_options(Rest)];
parse_options([]) ->
[].

0 comments on commit 2becaac

Please sign in to comment.