Skip to content

Commit

Permalink
Use merl [1] for compiling the erlang AST tree (fixes #123).
Browse files Browse the repository at this point in the history
Also, `number_literals` are now converted to erlang integers in the scanner.

[1] https://github.com/richcarl/merl
  • Loading branch information
kaos committed Feb 22, 2014
1 parent 8c876fd commit a1c9198
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 498 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
@@ -1,7 +1,11 @@
language: erlang
otp_release:
# - R16B03 (not yet available on travis)
# - 17.0-rc1
- R16B03-1
- R16B02
- R15B03
# - R14B04 (seems lists:concat/1 is broken on R14B04..)
script: "make test"

# since Travis is naughty and calls rebar get-deps behind our backs,
# we'll have to clean it up and build merl our selves..
script: "make -C deps/merl && make test"
13 changes: 11 additions & 2 deletions Makefile
Expand Up @@ -4,20 +4,28 @@ REBAR=./rebar $(REBAR_ARGS)

all: compile

compile: check-slex
compile: check-slex deps/merl
@$(REBAR) compile

check-slex: src/erlydtl_scanner.erl
src/erlydtl_scanner.erl: src/erlydtl_scanner.slex
@echo Notice: $@ is outdated by $<, consider running "'make slex'".

deps/merl:
@$(REBAR) get-deps
@echo "Make merl..." ; $(MAKE) -C deps/merl

update:
@$(REBAR) update-deps
@echo "Make merl..." ; $(MAKE) -C deps/merl

compile_test:
-mkdir -p ebintest
$(ERLC) -o tests/src -I include/erlydtl_preparser.hrl tests/src/erlydtl_extension_testparser.yrl
$(ERL) -make

test: compile compile_test
$(ERL) -noshell -pa ebin -pa ebintest \
$(ERL) -noshell -pa ebin -pa ebintest -pa deps/merl/ebin \
-eval \
"try \
erlydtl_functional_tests:run_tests(), \
Expand All @@ -43,6 +51,7 @@ plt:
tools webtool hipe inets eunit

clean:
@echo "Clean merl..." ; $(MAKE) -C deps/merl clean
@$(REBAR) clean
rm -fv ebintest/*
rm -fv erl_crash.dump
Expand Down
5 changes: 5 additions & 0 deletions rebar.config
Expand Up @@ -2,3 +2,8 @@

{erl_opts, [debug_info]}.
{yrl_opts, [{includefile, "include/erlydtl_preparser.hrl"}]}.
{deps,
[{merl, ".*",
{git, "git://github.com/erlydtl/merl.git", {branch, "erlydtl"}},
[raw]}
]}.
727 changes: 237 additions & 490 deletions src/erlydtl_compiler.erl

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/erlydtl_scanner.erl
Expand Up @@ -36,7 +36,7 @@
%%%-------------------------------------------------------------------
-module(erlydtl_scanner).

%% This file was generated 2014-02-17 11:20:49 UTC by slex 0.2.1.
%% This file was generated 2014-02-21 13:38:27 UTC by slex 0.2.1.
%% http://github.com/erlydtl/slex
-slex_source(["src/erlydtl_scanner.slex"]).

Expand Down Expand Up @@ -532,7 +532,10 @@ post_process(_, {string, _, L} = T, _) ->
post_process(_, {string_literal, _, L} = T, _) ->
setelement(3, T, begin L1 = lists:reverse(L), L1 end);
post_process(_, {number_literal, _, L} = T, _) ->
setelement(3, T, begin L1 = lists:reverse(L), L1 end);
setelement(3, T,
begin
L1 = lists:reverse(L), L2 = list_to_integer(L1), L2
end);
post_process(_, {open_var, _, L} = T, _) ->
setelement(3, T, begin L1 = to_atom(L), L1 end);
post_process(_, {close_var, _, L} = T, _) ->
Expand Down
2 changes: 1 addition & 1 deletion src/erlydtl_scanner.slex
Expand Up @@ -257,7 +257,7 @@ end.

string: lists reverse.
string_literal: lists reverse.
number_literal: lists reverse.
number_literal: lists reverse, list_to_integer.
open_var: to_atom.
close_var: to_atom.
open_tag: to_atom.
Expand Down
2 changes: 1 addition & 1 deletion tests/src/erlydtl_functional_tests.erl
Expand Up @@ -256,7 +256,7 @@ test_compile_render(Name) ->
force_recompile,
return_errors,
return_warnings,
%% debug_compiler,
%% debug_info,
{custom_tags_modules, [erlydtl_custom_tags]}],
io:format("compiling ... "),
case erlydtl:compile(File, Module, Options) of
Expand Down

0 comments on commit a1c9198

Please sign in to comment.