Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

housekeeping (for currently broken)

  • Loading branch information...
commit 756ac2508d427c1057504aeedefa58f68ed7f57b 1 parent 59acfc5
Roberto Saccon rsaccon authored
4 demo/templates/test_for.html
View
@@ -1,8 +1,8 @@
before
<ul>
-{% for fruit in fruit_list %}
- <li>{{ fruit }}</li>
+{% for iterator in link_list %}
+ <li><a href="{{ iterator.url }}">{{ iterator.name }}</a></li>
{% endfor %}
</ul>
5 src/demo/erlydtl_demo.erl
View
@@ -126,7 +126,10 @@ render("comment" = Name) ->
render(Name, ".html");
render("for" = Name) ->
- render(Name, ".html", [{fruit_list, ["apple", "banana"]}]);
+ Link1 = [{name, "Amazon"}, {url, "http://amazon.com"}],
+ Link2 = [{name, "Google"}, {url, "http://google.com"}],
+ Link3 = [{name, "Microsoft"}, {url, "http://microsoft.com"}],
+ render(Name, ".html", [{link_list, [Link1, Link2, Link3]}]);
render("htmltags" = Name) ->
render(Name, ".html");
75 src/erlydtl/erlydtl.erl
View
@@ -3,7 +3,8 @@
%%% @author Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
%%% @copyright 2007 Roberto Saccon
%%% @doc
-%%% Helper module to start and stop ErlyDTL application
+%%% Helper module to start and stop ErlyDTL application and for
+%%% creating yecc-grammar based template parser
%%% @end
%%%
%%% The MIT License
@@ -34,7 +35,16 @@
-author('rsaccon@gmail.com').
%% API
--export([start/0, stop/0]).
+-export([start/0, stop/0, create_parser/0, reload/2, write_beam/3]).
+
+%% --------------------------------------------------------------------
+%% Definitions
+%% --------------------------------------------------------------------
+-ifdef(debug).
+-define(PRINT_ERR_WARNS, [report_warnings, report_errors]).
+-else.
+-define(PRINT_ERR_WARNS, []).
+-endif.
%% @spec start() -> ok
@@ -42,7 +52,66 @@
start() ->
application:start(erlydtl).
+
%% @spec stop() -> ok
%% @doc Stop the erlydtl server.
stop() ->
- application:stop(erlydtl).
+ application:stop(erlydtl).
+
+
+%%--------------------------------------------------------------------
+%% @spec
+%% @doc
+%% @end
+%%--------------------------------------------------------------------
+create_parser() ->
+ create_parser("src/erlydtl/erlydtl_parser", "ebin").
+
+
+%%--------------------------------------------------------------------
+%% @spec (ModuleName::string(), Bin,::binary()) -> Ok::atom() | Error::atom()
+%% @doc reloads byte code
+%% @end
+%%--------------------------------------------------------------------
+reload(Module, Bin) ->
+ code:purge(Module),
+ SrcName = atom_to_list(Module) ++ ".erl",
+ case code:load_binary(Module, SrcName, Bin) of
+ {module, _} -> ok;
+ _ -> error
+ end.
+
+
+%%--------------------------------------------------------------------
+%% @spec (ModuleName::string(), Bin,::binary(), Dir::string()) -> any()
+%% @doc writes byte code to beam file
+%% @end
+%%--------------------------------------------------------------------
+write_beam(ModuleName, Bin, Dir) ->
+ File = filename:join([Dir, atom_to_list(ModuleName) ++ ".beam"]),
+ file:write_file(File, Bin).
+
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
+
+create_parser(Path, Outdir) ->
+ case yecc:file(Path) of
+ {ok, _} ->
+ compile_reload_parser(Path, Outdir);
+ Err ->
+ io:format("TRACE ~p:~p ~p~n",[?MODULE, ?LINE, Path ++ ": yecc failed"]),
+ Err
+ end.
+
+
+compile_reload_parser(Path, Outdir) ->
+ case compile:file(Path, ?PRINT_ERR_WARNS ++ [{outdir, Outdir}]) of
+ {ok, Bin} ->
+ code:purge(Bin),
+ code:load_file(Bin);
+ Err ->
+ io:format("TRACE ~p:~p ~p~n",[?MODULE, ?LINE, Path ++ ": compilation failed"]),
+ Err
+ end.
57 src/erlydtl/erlydtl_base.erl
View
@@ -0,0 +1,57 @@
+%%%-------------------------------------------------------------------
+%%% File: erlydtl_base.erl
+%%% @author Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
+%%% @copyright 2007 Roberto Saccon
+%%% @doc
+%%% For creating yecc-grammar based template parser and utility functions to be called from
+%%%
+%%% @end
+%%%
+%%% The MIT License
+%%%
+%%% Copyright (c) 2007 Roberto Saccon
+%%%
+%%% Permission is hereby granted, free of charge, to any person obtaining a copy
+%%% of this software and associated documentation files (the "Software"), to deal
+%%% in the Software without restriction, including without limitation the rights
+%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+%%% copies of the Software, and to permit persons to whom the Software is
+%%% furnished to do so, subject to the following conditions:
+%%%
+%%% The above copyright notice and this permission notice shall be included in
+%%% all copies or substantial portions of the Software.
+%%%
+%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+%%% THE SOFTWARE.
+%%%
+%%% @since 2007-11-17 by Roberto Saccon
+%%%-------------------------------------------------------------------
+-module(erlydtl_base).
+-author('rsaccon@gmail.com').
+
+
+
+
+list_comp_helper(X, Rec, List) ->
+ ReplaceMe = lists:foldl(fun(X, Acc) ->
+
+ end,
+ [],
+ Rec1),
+
+
+ Pattern = erl_syntax:variable('X'),
+ Vars = lists:foldl(fun(X, Acc) ->
+ A = erl_syntax:variable(X),
+ B = erl_syntax:application(erl_syntax:atom(proplists),
+ erl_syntax:atom(get_value), [erl_syntax:atom(X), Pattern]),
+ [erl_syntax:match_expr(A, B) | Acc]
+ end,
+ [],
+ Rec1),
+
13 src/erlydtl/erlydtl_parser.erl
View
@@ -7,7 +7,12 @@ string({_, String}) ->
var({_, Line, Var}) ->
- {var, Line, list_to_atom("A" ++ Var)}.
+ case string:tokens(Var, ".") of
+ [Namespace, Var1] ->
+ {var, Line, list_to_atom("A" ++ Namespace), list_to_atom(Var1)};
+ _ ->
+ {var, Line, list_to_atom("A" ++ Var)}
+ end.
extends({_, Line, [Name]}) ->
@@ -40,7 +45,7 @@ tag({_, Line, [TagName | Args]}) ->
for({_, Line, [Iterator, _, Var]}, Content) ->
- {for, Line, list_to_atom("A" ++ Iterator), list_to_atom("A" ++ Var), Content}.
+ {for, Line, list_to_atom("A" ++ Iterator), list_to_atom(Var), Content}.
-file("/Users/rsaccon/R11B/erlang/lib/parsetools-1.4.1.1/include/yeccpre.hrl", 0).
%% ``The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -134,7 +139,7 @@ yecctoken2string(Other) ->
--file("src/erlydtl/erlydtl_parser.erl", 137).
+-file("src/erlydtl/erlydtl_parser.erl", 142).
yeccpars2(0, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) ->
__NewStack = yeccpars2_0_(__Stack),
@@ -306,4 +311,4 @@ yeccpars2_12_([__3,__2,__1 | __Stack]) ->
end | __Stack].
--file("src/erlydtl/erlydtl_parser.yrl", 108).
+-file("src/erlydtl/erlydtl_parser.yrl", 113).
9 src/erlydtl/erlydtl_parser.yrl
View
@@ -72,7 +72,12 @@ string({_, String}) ->
var({_, Line, Var}) ->
- {var, Line, list_to_atom("A" ++ Var)}.
+ case string:tokens(Var, ".") of
+ [Namespace, Var1] ->
+ {var, Line, list_to_atom("A" ++ Namespace), list_to_atom(Var1)};
+ _ ->
+ {var, Line, list_to_atom("A" ++ Var)}
+ end.
extends({_, Line, [Name]}) ->
@@ -105,4 +110,4 @@ tag({_, Line, [TagName | Args]}) ->
for({_, Line, [Iterator, _, Var]}, Content) ->
- {for, Line, list_to_atom("A" ++ Iterator), list_to_atom("A" ++ Var), Content}.
+ {for, Line, list_to_atom("A" ++ Iterator), list_to_atom(Var), Content}.
125 src/erlydtl/erlydtl_server.erl
View
@@ -192,10 +192,10 @@ parse(File) ->
compile([H | T], ModuleName, FunctionName, RelDir, Ext) ->
- {List, Args} = case build_tree(H, T, [], [], RelDir, Ext, []) of
- {regular, List0, Args0} ->
+ {List, Args} = case build_tree(H, T, [], [], RelDir, Ext, [], []) of
+ {regular, List0, Args0, _} ->
{[parse_transform(X) || X <- List0], Args0};
- {inherited, List0, Arg0} ->
+ {inherited, List0, Arg0, _} ->
{List0, Arg0}
end,
{Args1, Body} = case Args of
@@ -219,6 +219,7 @@ compile([H | T], ModuleName, FunctionName, RelDir, Ext) ->
[Mod, Cmp] = [erl_syntax:attribute(erl_syntax:atom(X), [erl_syntax:atom(Y)]) ||
{X, Y} <- [{"module", ModuleName}, {"compile", "export_all"}]],
Forms = [erl_syntax:revert(X) || X <- [Mod, Cmp, Func]],
+io:format("TRACE ~p:~p Forms: ~p~n",[?MODULE, ?LINE, Forms]),
case compile:forms(Forms) of
{ok, Module, Bin} ->
erlydtl_tools:write_beam(Module, Bin, "ebin"),
@@ -228,38 +229,43 @@ compile([H | T], ModuleName, FunctionName, RelDir, Ext) ->
end.
-build_tree(nil, [{extends, _Line, Name}], Out, Args, RelDir, Ext, _) ->
+build_tree(nil, [{extends, _Line, Name}], Out, Args, RelDir, Ext, _, _) ->
case parse(filename:join([RelDir, Name])) of
{ok, ParentAst} ->
[H|T]=ParentAst,
- {_, List, Args1} = build_tree(H, T, [], [], RelDir, Ext, []),
+ {_, List, Args1, _} = build_tree(H, T, [], [], RelDir, Ext, [], []),
{List3, Args3} = lists:foldl(fun(X, {List2, Args2}) ->
- {List4, Args4} = parse_transform(X, Out, Args2, Ext, []),
+ {List4, Args4} = parse_transform(X, Out, Args2, Ext, [],[]),
{[List4 | List2], Args4}
end, {[], Args1}, List),
- {inherited, lists:reverse(lists:flatten([List3])), lists:flatten(Args3)};
+ {inherited, lists:reverse(lists:flatten([List3])), lists:flatten(Args3), []};
{error, Msg} ->
io:format("TRACE ~p:~p Parent Parser failure: ~p~n",[?MODULE, ?LINE, Name]),
- {regular, Out, Args}
+ {regular, Out, Args, []}
end;
-build_tree(nil, [{var, Line, Val}], Out, Args, DocRoot, Ext, Val) ->
- {regular, [erl_syntax:variable(Val) | Out], Args};
-
-build_tree(nil, [{var, Line, Var}], Out, Args, _, _, IgnoreVar) ->
+build_tree(nil, [{var, Line, Var}], Out, Args, DocRoot, Ext, Var, Rec) ->
+ {regular, [erl_syntax:variable(Var) | Out], Args, Rec};
+
+build_tree(nil, [{var, Line, Ns, Var}], Out, Args, DocRoot, Ext, Ns, Rec) ->
+ Var1 = lists:concat([Ns, ".", Var]),
+ Rec1 = [list_to_atom(Var1) | Rec],
+ {regular, [erl_syntax:variable(Var1) | Out], Args, Rec1};
+
+build_tree(nil, [{var, Line, Var}], Out, Args, _, _, _, Rec) ->
case lists:member(Var, Args) of
true ->
- {regular, [{var, Line, Var} | Out], Args};
+ {regular, [{var, Line, Var} | Out], Args, Rec};
_ ->
- {regular, [{var, Line, Var} | Out], [Var | Args]}
+ {regular, [{var, Line, Var} | Out], [Var | Args], Rec}
end;
-build_tree(nil, [{tag, _Line, TagName, TagArgs}], Out, Args, _, Ext, IgnoreVar) ->
- Out2 = load_tag(TagName, TagArgs, Out, default, Ext, IgnoreVar),
- {regular, Out2, Args};
+build_tree(nil, [{tag, _Line, TagName, TagArgs}], Out, Args, _, Ext, _, Rec) ->
+ Out2 = load_tag(TagName, TagArgs, Out, default, Ext),
+ {regular, Out2, Args, Rec};
-build_tree(nil, [{for, _Line, Iterator, Var, [HFor | TFor]}], Out, Args, _, Ext, _) ->
- {_, List1, Args1} = build_tree(HFor, TFor, [], Args, undefined, Ext, Iterator),
+build_tree(nil, [{for, _Line, Iterator, Var, [HFor | TFor]}], Out, Args, _, Ext, _, Rec) ->
+ {_, List1, Args1, TmpArgs1} = build_tree(HFor, TFor, [], Args, undefined, Ext, Iterator, []),
Args2 = case lists:member(Var, Args1) of
true ->
Args1;
@@ -268,51 +274,78 @@ build_tree(nil, [{for, _Line, Iterator, Var, [HFor | TFor]}], Out, Args, _, Ext,
end,
Body = erl_syntax:generator(erl_syntax:variable(Iterator), erl_syntax:variable(Var)),
Out1 = erl_syntax:list_comp(erl_syntax:list(List1), [Body]),
- {regular, Out1, Args2};
+ {regular, Out1, Args2, Rec};
-build_tree(nil, [Token], Out, Args, _, _, _) ->
- {regular, [Token | Out], Args};
+build_tree(nil, [Token], Out, Args, _, _, _, Rec) ->
+ {regular, [Token | Out], Args, Rec};
-build_tree([H | T], [{var, Line, Var}], Out, Args, DocRoot, Ext, Var) ->
- build_tree(H, T, [erl_syntax:variable(Var) | Out], Args, DocRoot, Ext, Var) ;
-
-build_tree([H | T], [{var, Line, Var}], Out, Args, DocRoot, Ext, IgnoreVar) ->
+build_tree([H | T], [{var, Line, Var}], Out, Args, DocRoot, Ext, Var, Rec) ->
+ build_tree(H, T, [erl_syntax:variable(Var) | Out], Args, DocRoot, Ext, Var, Rec);
+
+build_tree([H | T], [{var, Line, Ns, Var}], Out, Args, DocRoot, Ext, Ns, Rec) ->
+ Var1 = lists:concat([Ns, ".", Var]),
+ Rec1 = [list_to_atom(Var1) | Rec],
+ build_tree(H, T, [erl_syntax:variable(Var1) | Out], Args, DocRoot, Ext, Ns, Rec1);
+
+build_tree([H | T], [{var, Line, Var}], Out, Args, DocRoot, Ext, IgnoreVar, Rec) ->
case lists:member(Var, Args) of
true ->
- build_tree(H, T, [{var, Line, Var} | Out], Args, DocRoot, Ext, IgnoreVar);
+ build_tree(H, T, [{var, Line, Var} | Out], Args, DocRoot, Ext, IgnoreVar, Rec);
_ ->
- build_tree(H, T, [{var, Line, Var} | Out], [Var | Args], DocRoot, Ext, IgnoreVar)
+ build_tree(H, T, [{var, Line, Var} | Out], [Var | Args], DocRoot, Ext, IgnoreVar, Rec)
end;
-build_tree([H | T], [{tag, _Line, TagName, TagArgs}], Out, Args, DocRoot, Ext, IgnoreVar) ->
- Out2 = load_tag(TagName, TagArgs, Out, default, Ext, IgnoreVar),
- build_tree(H, T, Out2, Args, DocRoot, Ext, IgnoreVar);
+build_tree([H | T], [{tag, _Line, TagName, TagArgs}], Out, Args, DocRoot, Ext, IgnoreVar, Rec) ->
+ Out2 = load_tag(TagName, TagArgs, Out, default, Ext),
+ build_tree(H, T, Out2, Args, DocRoot, Ext, IgnoreVar, Rec);
-build_tree([H | T], [{for, _Line, Iterator, Var, [HFor | TFor]}], Out, Args, DocRoot, Ext, IgnoreVar) ->
- {_, List1, Args1} = build_tree(HFor, TFor, [], Args, undefined, Ext, Iterator),
+build_tree([H | T], [{for, _Line, Iterator, Var, [HFor | TFor]}], Out, Args, DocRoot, Ext, IgnoreVar, Rec) ->
+ {_, List1, Args1, Rec1} = build_tree(HFor, TFor, [], Args, undefined, Ext, Iterator, []),
Args2 = case lists:member(Var, Args1) of
true ->
Args1;
_ ->
[Var | Args1]
- end,
- Body = erl_syntax:generator(erl_syntax:variable(Iterator), erl_syntax:variable(Var)),
- Out1 = erl_syntax:list_comp(erl_syntax:list(List1), [Body]),
- build_tree(H, T, lists:flatten([Out1, Out]), Args2, DocRoot, Ext, IgnoreVar);
+ end,
+ Out1 = case Rec1 of
+ [] ->
+ Pattern = erl_syntax:variable(Iterator),
+ Body = erl_syntax:generator(Pattern, erl_syntax:variable(Var)),
+ erl_syntax:list_comp(erl_syntax:list(List1), [Body]);
+ _ ->
+ %%
+ %% Pattern = erl_syntax:variable('X'),
+ %% Vars = lists:foldl(fun(X, Acc) ->
+ %% A = erl_syntax:variable(X),
+ %% B = erl_syntax:application(erl_syntax:atom(proplists),
+ %% erl_syntax:atom(get_value), [erl_syntax:atom(X), Pattern]),
+ %% [erl_syntax:match_expr(A, B) | Acc]
+ %% end,
+ %% [],
+ %% Rec1),
+ %%
+ %% todo: create a function ..
+ Body = erl_syntax:generator(Pattern, erl_syntax:variable(Var)),
+ F = erl_syntax:application(erl_syntax:atom(erlydtl_base),
+ erl_syntax:atom(list_comp_helper),
+ [erl_syntax:list(List1), erl_syntax:list(Req1)]),
+ erl_syntax:list_comp(F, [Body])
+ end,
+ build_tree(H, T, lists:flatten([Out1, Out]), Args2, DocRoot, Ext, IgnoreVar, Rec);
-build_tree([H | T], [Token], Out, Args, DocRoot, Ext, IgnoreVar) ->
- build_tree(H, T, [Token | Out], Args, DocRoot, Ext, IgnoreVar).
+build_tree([H | T], [Token], Out, Args, DocRoot, Ext, IgnoreVar, Rec) ->
+ build_tree(H, T, [Token | Out], Args, DocRoot, Ext, IgnoreVar, Rec).
-parse_transform({block, _Line, Name, [nil, Val]}, List, Args, Ext, IgnoreVar) ->
+parse_transform({block, _Line, Name, [nil, Val]}, List, Args, Ext, IgnoreVar, Rec) ->
case lists:keysearch(Name, 3, List) of
false ->
- parse_transform(Val, List, Args, Ext, IgnoreVar);
+ parse_transform(Val, List, Args, Ext, IgnoreVar, Rec);
{value, {_, _, _, [H | T]}} ->
- {_, List2, Args2} = build_tree(H, T, [], Args, undefined, Ext, IgnoreVar),
- parse_transform(lists:reverse(List2), List, Args2, Ext, IgnoreVar)
+ {_, List2, Args2} = build_tree(H, T, [], Args, undefined, Ext, IgnoreVar, Rec),
+ parse_transform(lists:reverse(List2), List, Args2, Ext, IgnoreVar, Rec)
end;
-parse_transform(Other, _What, Args, _, _) ->
+parse_transform(Other, _What, Args, _, _, _) ->
{Other, Args}.
@@ -335,11 +368,11 @@ parse_transform(Other) ->
Other.
-load_tag(TagName, TagArgs, Acc0, default, Ext, IgnoreVar) ->
+load_tag(TagName, TagArgs, Acc0, default, Ext) ->
case parse(filename:join([erlydtl_deps:get_base_dir(), "priv", "tags", atom_to_list(TagName) ++ Ext])) of
{ok, ParentAst} ->
[H|T]=ParentAst,
- {_, List, _} = build_tree(H, T, [], [], undefined, Ext, IgnoreVar),
+ {_, List, _, _} = build_tree(H, T, [], [], undefined, Ext, [], []),
lists:foldl(fun(X, Acc) ->
[parse_transform(X, TagArgs) | Acc]
end,
106 src/erlydtl/erlydtl_tools.erl
View
@@ -1,106 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File: erlydtl_tools.erl
-%%% @author Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
-%%% @copyright 2007 Roberto Saccon
-%%% @doc
-%%% Utility for creating parser based on grammar
-%%% @end
-%%%
-%%% The MIT License
-%%%
-%%% Copyright (c) 2007 Roberto Saccon
-%%%
-%%% Permission is hereby granted, free of charge, to any person obtaining a copy
-%%% of this software and associated documentation files (the "Software"), to deal
-%%% in the Software without restriction, including without limitation the rights
-%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-%%% copies of the Software, and to permit persons to whom the Software is
-%%% furnished to do so, subject to the following conditions:
-%%%
-%%% The above copyright notice and this permission notice shall be included in
-%%% all copies or substantial portions of the Software.
-%%%
-%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-%%% THE SOFTWARE.
-%%%
-%%% @since 2007-11-17 by Roberto Saccon
-%%%-------------------------------------------------------------------
--module(erlydtl_tools).
--author('rsaccon@gmail.com').
-
-%% API
--export([create_parser/0, reload/2, write_beam/3]).
-
-%% --------------------------------------------------------------------
-%% Definitions
-%% --------------------------------------------------------------------
--ifdef(debug).
--define(PRINT_ERR_WARNS, [report_warnings, report_errors]).
--else.
--define(PRINT_ERR_WARNS, []).
--endif.
-
-
-%%====================================================================
-%% API
-%%====================================================================
-%%--------------------------------------------------------------------
-%% @spec
-%% @doc
-%% @end
-%%--------------------------------------------------------------------
-create_parser() ->
- create_parser("src/erlydtl/erlydtl_parser", "ebin").
-
-
-%%--------------------------------------------------------------------
-%% @spec (ModuleName::string(), Bin,::binary()) -> Ok::atom() | Error::atom()
-%% @doc reloads byte code
-%% @end
-%%--------------------------------------------------------------------
-reload(Module, Bin) ->
- code:purge(Module),
- SrcName = atom_to_list(Module) ++ ".erl",
- case code:load_binary(Module, SrcName, Bin) of
- {module, _} -> ok;
- _ -> error
- end.
-
-
-%%--------------------------------------------------------------------
-%% @spec (ModuleName::string(), Bin,::binary(), Dir::string()) -> any()
-%% @doc writes byte code to beam file
-%% @end
-%%--------------------------------------------------------------------
-write_beam(ModuleName, Bin, Dir) ->
- File = filename:join([Dir, atom_to_list(ModuleName) ++ ".beam"]),
- file:write_file(File, Bin).
-
-
-%%====================================================================
-%% Internal functions
-%%====================================================================
-
-create_parser(Path, Outdir) ->
- case yecc:file(Path) of
- {ok, _} ->
- compile_reload_parser(Path, Outdir);
- Err ->
- io:format("TRACE ~p:~p ~p~n",[?MODULE, ?LINE, Path ++ ": yecc failed"]),
- Err
- end.
-
-compile_reload_parser(Path, Outdir) ->
- case compile:file(Path, ?PRINT_ERR_WARNS ++ [{outdir, Outdir}]) of
- {ok, Bin} ->
- code:purge(Bin),
- code:load_file(Bin);
- Err ->
- io:format("TRACE ~p:~p ~p~n",[?MODULE, ?LINE, Path ++ ": compilation failed"]),
- Err
- end.
Please sign in to comment.
Something went wrong with that request. Please try again.