Permalink
Browse files

Ability to build escript

  • Loading branch information...
1 parent 6cb132b commit ebbd9f7e2bbbba2bb9345687e1b35e0d5fc401f2 @doubleyou doubleyou committed Feb 4, 2012
Showing with 22 additions and 0 deletions.
  1. +3 −0 Makefile
  2. +19 −0 src/neotoma.erl
View
@@ -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
View
@@ -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.
@@ -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 ebbd9f7

Please sign in to comment.