Skip to content

Commit

Permalink
Merge pull request ErlyORM#19 from inaka/elbrujohalcon.18.switch_buil…
Browse files Browse the repository at this point in the history
…d_tools_to_erlang_m

[Fix ErlyORM#18] Get it ready for republishing on hex.pm
  • Loading branch information
jfacorro committed Jan 14, 2016
2 parents 713f93a + 14b1ff1 commit 8259821
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 48 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
.awconfig
hexer.config
ebin
aleppo_parser.erl
aleppo_parser.erl
/.settings/
/.project
.rebar
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: erlang
sudo: false
otp_release:
# Test on all supported releases
- 18.2.1
- 18.1
- 18.0
- 17.5
- 17.4
- 17.3
- 17.1
- 17.0
- R16B03-1
- R16B03
- R16B02
- R16B01
- R16B
- R15B03
- R15B02
- R15B01
- R15B

script:
- make
- make plt
- make dialyze
notifications:
email: false
69 changes: 69 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Change Log

## [0.9.5](https://github.com/inaka/aleppo/tree/0.9.5) (2015-12-31)
[Full Changelog](https://github.com/inaka/aleppo/compare/0.9.4...0.9.5)

**Merged pull requests:**

- \[\#16\] Version bump 0.9.5 [\#17](https://github.com/inaka/aleppo/pull/17) ([davecaos](https://github.com/davecaos))

## [0.9.4](https://github.com/inaka/aleppo/tree/0.9.4) (2015-12-30)
[Full Changelog](https://github.com/inaka/aleppo/compare/0.9.3...0.9.4)

**Closed issues:**

- Hex Packages [\#13](https://github.com/inaka/aleppo/issues/13)

**Merged pull requests:**

- \[\#13\] Updated version to 0.9.4 in src/aleppo.app.src [\#15](https://github.com/inaka/aleppo/pull/15) ([davecaos](https://github.com/davecaos))

## [0.9.3](https://github.com/inaka/aleppo/tree/0.9.3) (2015-12-30)
[Full Changelog](https://github.com/inaka/aleppo/compare/0.9.2...0.9.3)

**Merged pull requests:**

- \[\#13\] Updated for hexer hex package tool [\#14](https://github.com/inaka/aleppo/pull/14) ([davecaos](https://github.com/davecaos))

## [0.9.2](https://github.com/inaka/aleppo/tree/0.9.2) (2015-09-04)
[Full Changelog](https://github.com/inaka/aleppo/compare/0.9.1...0.9.2)

**Fixed bugs:**

- Tokens that are replaced by a macro get the wrong location [\#7](https://github.com/inaka/aleppo/issues/7)

**Closed issues:**

- Remove OTP 18.0 warnings and fix location bug [\#11](https://github.com/inaka/aleppo/issues/11)
- maps's error not throw [\#9](https://github.com/inaka/aleppo/issues/9)

**Merged pull requests:**

- \[Closes \#11\] Remove warnings, handle new location token attribute [\#12](https://github.com/inaka/aleppo/pull/12) ([jfacorro](https://github.com/jfacorro))

## [0.9.1](https://github.com/inaka/aleppo/tree/0.9.1) (2014-11-11)
[Full Changelog](https://github.com/inaka/aleppo/compare/0.9.0...0.9.1)

**Fixed bugs:**

- .app file not being copied to ebin on compile [\#3](https://github.com/inaka/aleppo/issues/3)

**Merged pull requests:**

- \[\#7\] Assign the location of the macro to the tokens that replace it. [\#8](https://github.com/inaka/aleppo/pull/8) ([jfacorro](https://github.com/jfacorro))

## [0.9.0](https://github.com/inaka/aleppo/tree/0.9.0) (2014-08-08)
[Full Changelog](https://github.com/inaka/aleppo/compare/v0.8.9...0.9.0)

**Merged pull requests:**

- \[inaka/levis\#84\] Added elipsis and comment as tokens. [\#6](https://github.com/inaka/aleppo/pull/6) ([jfacorro](https://github.com/jfacorro))
- \[inaka/elvis\#76\] Best effort to include files. [\#5](https://github.com/inaka/aleppo/pull/5) ([jfacorro](https://github.com/jfacorro))
- \[\#3\] Copy src/aleppo.app.src to ebin/aleppo.app on compile [\#4](https://github.com/inaka/aleppo/pull/4) ([jfacorro](https://github.com/jfacorro))
- Support token attributes as proplists [\#2](https://github.com/inaka/aleppo/pull/2) ([jfacorro](https://github.com/jfacorro))
- Added terminals ':=' and '=\>'. [\#1](https://github.com/inaka/aleppo/pull/1) ([jfacorro](https://github.com/jfacorro))

## [v0.8.9](https://github.com/inaka/aleppo/tree/v0.8.9) (2012-07-26)


\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
1 change: 0 additions & 1 deletion Emakefile

This file was deleted.

50 changes: 37 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
ERL=erl
ERLC=erlc
REBAR=./rebar
GIT = git
REBAR_VER = 2.6.1

PARSER=src/aleppo_parser
## dialyzer
PLT_FILE = ~/aleppo.plt
PLT_APPS ?= kernel stdlib erts compiler crypto
DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions -Wunmatched_returns \
-Wunderspecs --verbose --fullpath -n

all: $(PARSER).erl
-mkdir -p ebin
$(ERL) -make
cp src/aleppo.app.src ebin/aleppo.app
all: compile

compile:
@$(REBAR) compile

$(PARSER).erl: $(PARSER).yrl
$(ERLC) -o src/ src/aleppo_parser.yrl

run:
$(ERL) -pa ebin
@$(REBAR) shell

rebar_src:
@rm -rf $(PWD)/rebar_src
@$(GIT) clone git://github.com/rebar/rebar.git rebar_src
@$(GIT) -C rebar_src checkout tags/$(REBAR_VER)
@cd $(PWD)/rebar_src/; ./bootstrap
@cp $(PWD)/rebar_src/rebar $(PWD)
@rm -rf $(PWD)/rebar_src

dialyze: all
@[ -f $(PLT_FILE) ] || $(MAKE) plt
@dialyzer --plt $(PLT_FILE) $(DIALYZER_OPTS) ebin || [ $$? -eq 2 ];

## In case you are missing a plt file for dialyzer,
## you can run/adapt this command
plt:
@echo "Building PLT, may take a few minutes"
@dialyzer --build_plt --output_plt $(PLT_FILE) --apps \
$(PLT_APPS) || [ $$? -eq 2 ];

clean:
rm -fv ebin/*.beam
rm -fv erl_crash.dump $(PARSER).erl
@rm -fv erl_crash.dump
@rm -f $(PLT_FILE)
@$(REBAR) clean

.PHONY: all compile run dialyze plt clean
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Aleppo: ALternative Erlang Pre-ProcessOr
========================================

[![Build Status](https://travis-ci.org/ErlyORM/aleppo.svg?branch=master)](https://travis-ci.org/ErlyORM/aleppo)

Aleppo is an alternative to `epp(3erl)`, and is mainly intended for Erlang compiler hackers. The problem with EPP is that it only operates on Erlang source files. Aleppo will operate directly on tokens returned by erl_scan.

erl_scan -> *aleppo* -> erl_parse -> compile
Expand Down
Binary file added rebar
Binary file not shown.
9 changes: 9 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%-*-Erlang-*-
% vim: ft=erlang
{erl_opts, [
debug_info,
warn_unused_vars,
warn_unused_import,
warn_exported_vars,
{platform_define, "^R|17", pre18}
]}.
6 changes: 3 additions & 3 deletions src/aleppo.app.src
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
%% -*- mode: erlang -*-
{application, aleppo,
[{description, "Aleppo: ALternative Erlang Pre-ProcessOr"},
{vsn, "0.9.5"},
{vsn, "0.9.6"},
{modules, [
]},
{applications, [kernel, stdlib]},
{registered, []},
{pkg_name, inaka_aleppo},
{maintainers, ["Inaka"]},
{maintainers, ["Inaka", "ErlyORM"]},
{licenses, []},
{links, [{"Github", "https://github.com/inaka/aleppo"}]},
{build_tools, ["make"]}
{build_tools, ["make", "rebar"]}
]}.
83 changes: 61 additions & 22 deletions src/aleppo.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
% Aleppo: ALternative Erlang Pre-ProcessOr
-module(aleppo).
-export([process_file/1, process_tokens/1, process_tokens/2, scan_file/1]).
-export([process_file/1, process_file/2, process_tokens/1, process_tokens/2,
scan_file/1]).

-record(ale_context, {
include_trail = [],
Expand All @@ -9,10 +10,14 @@
}).

process_file(FileName) ->
process_file(FileName, []).

process_file(FileName, Options) ->
ModuleName = list_to_atom(filename:rootname(filename:basename(FileName))),
case scan_file(FileName) of
{ok, Tokens} ->
process_tokens(Tokens, [{file, FileName}, {module, ModuleName}]);
process_tokens(
Tokens, [{file, FileName}, {module, ModuleName}|Options]);
Error ->
Error
end.
Expand All @@ -23,6 +28,7 @@ process_tokens(Tokens) ->
% Valid options:
% - file: The path of the file being processed
% - include: A list of directories to include in the .hrl search path
% - return_macros: return the macro dict in result if successful
process_tokens(Tokens, Options) ->
{Tokens1, Module} = mark_keywords(Tokens),
case aleppo_parser:parse(Tokens1) of
Expand Down Expand Up @@ -63,8 +69,12 @@ process_tree(ParseTree, Options) ->
macro_dict = Dict2 },

try process_tree(ParseTree, TokenAcc, Context) of
{_MacroDict, RevTokens} when is_list(RevTokens) ->
{ok, lists:reverse(RevTokens)}
{MacroDict, RevTokens} when is_list(RevTokens) ->
FinalTokens = reverse_and_normalize_token_locations(RevTokens),
case proplists:get_value(return_macros, Options, false) of
true -> {ok, FinalTokens, MacroDict};
_ -> {ok, FinalTokens}
end
catch
_:Reason ->
{error, Reason}
Expand Down Expand Up @@ -346,17 +356,17 @@ stringify_tokens(TokenList) ->
stringify_tokens1([], Acc) ->
lists:concat(lists:reverse(Acc));
stringify_tokens1([Token|Rest], []) ->
Symbol = symbol(Token),
Symbol = get_symbol(Token),
stringify_tokens1(Rest, [Symbol]);
stringify_tokens1([Token|Rest], Acc) ->
Symbol = symbol(Token),
Symbol = get_symbol(Token),
stringify_tokens1(Rest, [Symbol, " "|Acc]).

insert_comma_tokens(Args, Loc) ->
lists:foldr(fun
(Arg, []) -> Arg;
(Arg, Acc) -> Arg ++ [{',', Loc}|Acc]
end, [], Args).
(Arg, []) -> Arg;
(Arg, Acc) -> Arg ++ [{',', Loc}|Acc]
end, [], Args).

mark_keywords(Tokens) ->
mark_keywords(Tokens, undefined, []).
Expand Down Expand Up @@ -403,26 +413,55 @@ mark_keywords([{'-', DashAttrs} = Dash,
end,
mark_keywords(Rest, Mod, [MarkedToken, Dash|Acc]);
_ ->
mark_keywords(Rest, Mod, [Token |Acc])
mark_keywords(Rest, Mod, [Token, Dash|Acc])
end;
mark_keywords([Other|Rest], Mod, Acc) ->
mark_keywords(Rest, Mod, [Other|Acc]).

location(Location = {_Line, _Column}) ->
Location;
location(Attrs) when is_list(Attrs) ->
Line = proplists:get_value(line, Attrs, undefined),
Column = proplists:get_value(column, Attrs, undefined),
case {Line, Column} of
{undefined, undefined} -> proplists:get_value(location, Attrs);
Loc -> Loc
end.
location(Attrs) ->
location_helper(Attrs).

-ifdef(pre18).
location_helper(Attrs) ->
legacy_location(Attrs).

symbol(Token) ->
case erlang:function_exported(erl_scan, symbol, 1) of
get_symbol(Token) ->
{symbol, Symbol} = erl_scan:token_info(Token, symbol),
Symbol.
-else.
location_helper(Attrs) ->
case erl_anno:is_anno(Attrs) of
true ->
erl_scan:symbol(Token);
erl_anno:location(Attrs);
false ->
{symbol, Symbol} = erl_scan:token_info(Token, symbol),
Symbol
legacy_location(Attrs)
end.

get_symbol(Token) ->
erl_scan:symbol(Token).
-endif.

legacy_location(Attrs) when is_list(Attrs) ->
Line = proplists:get_value(line, Attrs),
Column = proplists:get_value(column, Attrs),
{Line, Column}.

reverse_and_normalize_token_locations(RevTokens) ->
reverse_and_normalize_token_locations_helper(RevTokens, []).

reverse_and_normalize_token_locations_helper([], Acc) ->
Acc;
reverse_and_normalize_token_locations_helper(
[{Type, MaybeLocation} | Rest], Acc)
when is_tuple(MaybeLocation) orelse is_list(MaybeLocation) ->
reverse_and_normalize_token_locations_helper(
Rest, [{Type, location(MaybeLocation)}|Acc]);
reverse_and_normalize_token_locations_helper(
[{Type, MaybeLocation, Extra} | Rest], Acc)
when is_tuple(MaybeLocation) orelse is_list(MaybeLocation) ->
reverse_and_normalize_token_locations_helper(
Rest, [{Type, location(MaybeLocation), Extra}|Acc]);
reverse_and_normalize_token_locations_helper([Other | Rest], Acc) ->
reverse_and_normalize_token_locations_helper(Rest, [Other | Acc]).
19 changes: 11 additions & 8 deletions src/aleppo_parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,25 @@ Terminals
'?'

char integer float atom string var
'(' ')' ',' '-'
'->' ':-' '{' '}' '[' ']' '|' '||' '<-' ';' ':' '#' '.' ':=' '=>'

'(' ')' ',' '->' '{' '}' '[' ']' '|' '||' '<-' ';' ':' '#' '.'
'after' 'begin' 'case' 'try' 'catch' 'end' 'fun' 'if' 'of' 'receive' 'when'
'andalso' 'orelse' 'query' 'spec'
'andalso' 'orelse'
'bnot' 'not'
'*' '/' 'div' 'rem' 'band' 'and'
'+' 'bor' 'bxor' 'bsl' 'bsr' 'or' 'xor'
'+' '-' 'bor' 'bxor' 'bsl' 'bsr' 'or' 'xor'
'++' '--'
'==' '/=' '=<' '<' '>=' '>' '=:=' '=/=' '<='
'==' '/=' '=<' '<' '>=' '>' '=:=' '=/=' '<=' '=>' ':='
'<<' '>>'
'!' '=' '::' '..' '...'
comment dot.
'spec' 'callback' % helper
comment
dot.

Rootsymbol File.

Unary 200 '('.

File -> Elements eof : '$1' ++ ['$2'].
File -> Elements : '$1' ++ [{eof, 0}].

Expand Down Expand Up @@ -145,7 +149,6 @@ ExpressionToken -> atom : '$1'.
ExpressionToken -> string : '$1'.
ExpressionToken -> var : '$1'.
ExpressionToken -> '->' : '$1'.
ExpressionToken -> ':-' : '$1'.
ExpressionToken -> '|' : '$1'.
ExpressionToken -> '||' : '$1'.
ExpressionToken -> '<-' : '$1'.
Expand All @@ -168,8 +171,8 @@ ExpressionToken -> 'receive' : '$1'.
ExpressionToken -> 'when' : '$1'.
ExpressionToken -> 'andalso' : '$1'.
ExpressionToken -> 'orelse' : '$1'.
ExpressionToken -> 'query' : '$1'.
ExpressionToken -> 'spec' : '$1'.
ExpressionToken -> 'callback' : '$1'.
ExpressionToken -> 'bnot' : '$1'.
ExpressionToken -> 'not' : '$1'.
ExpressionToken -> '*' : '$1'.
Expand Down

0 comments on commit 8259821

Please sign in to comment.