Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ability to build escript

  • Loading branch information...
commit ebbd9f7e2bbbba2bb9345687e1b35e0d5fc401f2 1 parent 6cb132b
@doubleyou doubleyou authored
Showing with 22 additions and 0 deletions.
  1. +3 −0  Makefile
  2. +19 −0 src/neotoma.erl
View
3  Makefile
@@ -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
19 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.
@@ -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([]) ->
+ [].
Please sign in to comment.
Something went wrong with that request. Please try again.