Parse transform utilities for Erlang
Go to file
Ulf Wiger ae7163f3db For fun, implemented a 'pmod' parse transform.
See examples/pmod.erl and examples/ex_pmod.erl
This works similarly to OTP's parameterized modules, which they are
now saying that they will drop. Since they drop the compiler support,
a slightly different notation is needed.

-pmod_vars([V1, V2, ...]). % defines the 'global' variables.
-pmod_funs([F1/A1, ...]).  % defines which functions are to be exported.

The functions listed in -pmod_funs/1 are transformed to take an extra
argument, and a new(V1, V2, ...) function is added and exported.

Example:

Eshell V5.9  (abort with ^G)
1> c(ex_pmod).
{ok,ex_pmod}
2> M = ex_pmod:new(a,b).
{ex_pmod,{a,b}}
3> M:b(x,y).
{x,y,a,b}
2012-10-12 19:34:03 +02:00
doc corrected license texts (EPL 1.1) 2012-03-05 18:36:32 +01:00
ebin dialyzer warnings reported by Kostis 2011-01-13 18:07:27 +01:00
examples For fun, implemented a 'pmod' parse transform. 2012-10-12 19:34:03 +02:00
include corrected license texts (EPL 1.1) 2012-03-05 18:36:32 +01:00
src lists:concat() -> lists:append() 2012-08-16 13:55:14 +02:00
.gitignore cleanup, type fixes and new rebar 2011-04-18 15:16:54 +02:00
Makefile added codegen: gen_functions/1, expr/1 2010-09-05 14:32:59 +02:00
README.md parse_trans:plain_transform/2 and example 2011-12-01 13:32:26 +01:00
rebar cleanup, type fixes and new rebar 2011-04-18 15:16:54 +02:00
rebar.config types added in exprecs 2011-10-23 13:52:05 +02:00

#The parse_trans application#

Authors: Ulf Wiger (ulf.wiger@erlang-consulting.com).

A generic parse transform library This library is intended to simplify the task of writing parse transform modules for Erlang.

#Introduction to parse transforms#

##The simplest transform##

The very simplest transform we can make is one that doesn't change a thing. For convenience, we will at least print the forms. This will enlighten us as to what the forms actually look like.

-module(test_pt).

-export([parse_transform/2]).

parse_transform(Forms, _Options) ->
    io:fwrite("Forms = ~p~n", [Forms]),
    Forms.

Trying this with a very simple module:

-module(ex1).
-export([add/2]).

add(X,Y) ->
    X + Y.
1> c(ex1, [{parse_transform,test_pt}]).
Forms = [{attribute,1,file,{"./ex1.erl",1}},
         {attribute,1,module,ex1},
         {attribute,2,export,[{add,2}]},
         {function,4,add,2,
                   [{clause,4,
                            [{var,4,'X'},{var,4,'Y'}],
                            [],
                            [{op,5,'+',{var,5,'X'},{var,5,'Y'}}]}]},
         {eof,6}]
{ok,ex1}

##transform/4##

...

#Current limitations#

...

##Modules##

ct_expand
exprecs
parse_trans
parse_trans_codegen
parse_trans_mod
parse_trans_pp