Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

generated edown docs + added README

  • Loading branch information...
commit c0bfe0849b639a47d30900b4ccddd6d90d8ad5d2 1 parent 363c2ed
Ulf Wiger authored
16 README.md
Source Rendered
... ... @@ -0,0 +1,16 @@
  1 +Parse Transform Utility Library
  2 +===============================
  3 +
  4 +This application contains some utility functions that
  5 +make it easier to write maintainable parse transforms
  6 +for erlang. The library uses Syntax Tools, which may seem
  7 +unwieldy at first. However, I recommend getting acquainted
  8 +with Syntax Tools; it has many advantages in for parse
  9 +transforms.
  10 +
  11 +Documentation
  12 +-------------
  13 +The EDoc is generated using the EDown extension, in order
  14 +to make it easy to read online on Github. To generate
  15 +normal edoc, update `rebar.config` to remove the edown-
  16 +related dependencies and edoc options.
93 doc/README.md
Source Rendered
... ... @@ -0,0 +1,93 @@
  1 +
  2 +
  3 +#The parse_trans application#
  4 +The parse_trans application
  5 +===========================
  6 +A generic parse transform library
  7 +This library is intended to simplify the task of writing parse transform
  8 +modules for Erlang.
  9 +__Authors:__ Ulf Wiger ([`ulf.wiger@erlang-consulting.com`](mailto:ulf.wiger@erlang-consulting.com)).
  10 +A generic parse transform library
  11 +This library is intended to simplify the task of writing parse transform
  12 +modules for Erlang.
  13 +
  14 +
  15 +
  16 +#Introduction to parse transforms#
  17 +
  18 +
  19 +
  20 +
  21 +##The simplest transform##
  22 +
  23 +
  24 +
  25 +The very simplest transform we can make is one that doesn't
  26 +change a thing. For convenience, we will at least print the forms.
  27 +This will enlighten us as to what the forms actually look like.
  28 +
  29 +
  30 +<pre>
  31 +-module(test_pt).
  32 +
  33 +-export([parse_transform/2]).
  34 +
  35 +parse_transform(Forms, _Options) ->
  36 + io:fwrite("Forms = ~p~n", [Forms]),
  37 + Forms.
  38 +</pre>
  39 +
  40 +
  41 +
  42 +Trying this with a very simple module:
  43 +
  44 +
  45 +<pre>
  46 +-module(ex1).
  47 +-export([add/2]).
  48 +
  49 +add(X,Y) ->
  50 + X + Y.
  51 +</pre>
  52 +
  53 +
  54 +
  55 +<pre>
  56 +1> c(ex1, [{parse_transform,test_pt}]).
  57 +Forms = [{attribute,1,file,{"./ex1.erl",1}},
  58 + {attribute,1,module,ex1},
  59 + {attribute,2,export,[{add,2}]},
  60 + {function,4,add,2,
  61 + [{clause,4,
  62 + [{var,4,'X'},{var,4,'Y'}],
  63 + [],
  64 + [{op,5,'+',{var,5,'X'},{var,5,'Y'}}]}]},
  65 + {eof,6}]
  66 +{ok,ex1}
  67 +</pre>
  68 +
  69 +
  70 +
  71 +
  72 +##`transform/4`##
  73 +
  74 +
  75 +...
  76 +
  77 +
  78 +
  79 +
  80 +#Current limitations#
  81 +
  82 +
  83 +...
  84 +
  85 +
  86 +##Modules##
  87 +
  88 +<table width="100%" border="0" summary="list of modules">
  89 +<tr><td><a href="ct_expand.md" class="module">ct_expand</a></td></tr>
  90 +<tr><td><a href="exprecs.md" class="module">exprecs</a></td></tr>
  91 +<tr><td><a href="parse_trans.md" class="module">parse_trans</a></td></tr>
  92 +<tr><td><a href="parse_trans_codegen.md" class="module">parse_trans_codegen</a></td></tr>
  93 +<tr><td><a href="parse_trans_pp.md" class="module">parse_trans_pp</a></td></tr></table>
45 doc/ct_expand.html
... ... @@ -1,45 +0,0 @@
1   -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2   -<html>
3   -<head>
4   -<title>Module ct_expand</title>
5   -<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
6   -</head>
7   -<body bgcolor="white">
8   -<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
9   -<hr>
10   -
11   -<h1>Module ct_expand</h1>
12   -<ul class="index"><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>Compile-time expansion utility.
13   -
14   -<p><b>Authors:</b> : Ulf Wiger (<a href="mailto:ulf.wiger@erlang-solutions.com"><tt>ulf.wiger@erlang-solutions.com</tt></a>).</p>
15   -
16   -<h2><a name="description">Description</a></h2><p>Compile-time expansion utility</p>
17   -
18   - <p>This module serves as an example of parse_trans-based transforms,
19   - but might also be a useful utility in its own right.
20   - The transform searches for calls to the pseudo-function
21   - <code>ct_expand:term(Expr)</code>, and then replaces the call site with the
22   - result of evaluating <code>Expr</code> at compile-time.</p>
23   -
24   - <p>For example, the line</p>
25   -
26   - <p><code>ct_expand:term(lists:sort([3,5,2,1,4]))</code></p>
27   -
28   - would be expanded at compile-time to <code>[1,2,3,4,5]</code>.
29   -
30   -<h2><a name="index">Function Index</a></h2>
31   -<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#parse_transform-2">parse_transform/2</a></td><td></td></tr>
32   -</table>
33   -
34   -<h2><a name="functions">Function Details</a></h2>
35   -
36   -<h3 class="function"><a name="parse_transform-2">parse_transform/2</a></h3>
37   -<div class="spec">
38   -<p><tt>parse_transform(Forms, Options) -&gt; any()</tt></p>
39   -</div>
40   -<hr>
41   -
42   -<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
43   -<p><i>Generated by EDoc, Sep 5 2010, 14:28:44.</i></p>
44   -</body>
45   -</html>
49 doc/ct_expand.md
Source Rendered
... ... @@ -0,0 +1,49 @@
  1 +Module ct_expand
  2 +================
  3 +
  4 +
  5 +#Module ct_expand#
  6 +* [Description](#description)
  7 +* [Function Index](#index)
  8 +* [Function Details](#functions)
  9 +Compile-time expansion utility.
  10 +__Authors:__ : Ulf Wiger ([`ulf.wiger@erlang-solutions.com`](mailto:ulf.wiger@erlang-solutions.com)).
  11 +
  12 +##<a name="description">Description</a>##
  13 +
  14 +Compile-time expansion utility
  15 +
  16 +
  17 +This module serves as an example of parse_trans-based transforms,
  18 + but might also be a useful utility in its own right.
  19 + The transform searches for calls to the pseudo-function
  20 + `ct_expand:term(Expr)`, and then replaces the call site with the
  21 + result of evaluating `Expr` at compile-time.
  22 +
  23 +
  24 +For example, the line
  25 +
  26 +
  27 +`ct_expand:term(lists:sort([3,5,2,1,4]))`
  28 +
  29 + would be expanded at compile-time to `[1,2,3,4,5]`.
  30 +
  31 +
  32 +##<a name="index">Function Index</a>##
  33 +
  34 +<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#parse_transform-2">parse_transform/2</a></td><td></td></tr></table>
  35 +
  36 +<a name="functions"></a>
  37 +
  38 +
  39 +##Function Details##
  40 +
  41 +<a name="parse_transform-2"></a>
  42 +
  43 +
  44 +###parse_transform/2##
  45 +
  46 +
  47 +`parse_transform(Forms, Options) -> any()`
  48 +
  49 +_Generated by EDoc, Oct 23 2010, 21:00:45._
122 doc/exprecs.html
... ... @@ -1,122 +0,0 @@
1   -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2   -<html>
3   -<head>
4   -<title>Module exprecs</title>
5   -<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
6   -</head>
7   -<body bgcolor="white">
8   -<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
9   -<hr>
10   -
11   -<h1>Module exprecs</h1>
12   -<ul class="index"><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>Parse transform for generating record access functions.
13   -
14   -<p><b>Authors:</b> : Ulf Wiger (<a href="mailto:ulf.wiger@ericsson.com"><tt>ulf.wiger@ericsson.com</tt></a>).</p>
15   -
16   -<h2><a name="description">Description</a></h2>Parse transform for generating record access functions.
17   - <p>This parse transform can be used to reduce compile-time
18   - dependencies in large systems.</p>
19   - <p>In the old days, before records, Erlang programmers often wrote
20   - access functions for tuple data. This was tedious and error-prone.
21   - The record syntax made this easier, but since records were implemented
22   - fully in the pre-processor, a nasty compile-time dependency was
23   - introduced.</p>
24   - <p>This module automates the generation of access functions for
25   - records. While this method cannot fully replace the utility of
26   - pattern matching, it does allow a fair bit of functionality on
27   - records without the need for compile-time dependencies.</p>
28   - <p>Whenever record definitions need to be exported from a module,
29   - inserting a compiler attribute,
30   - <code>export_records([RecName|...])</code> causes this transform
31   - to lay out access functions for the exported records:</p>
32   -
33   - <pre>
34   - -module(test_exprecs).
35   -
36   - -record(r, {a, b, c}).
37   - -export_records([r]).
38   -
39   - -export(['#new-'/1, '#info-'/1, '#info-'/2, '#pos-'/2,
40   - '#is_record-'/2, '#get-'/2, '#set-'/2, '#fromlist-'/2,
41   - '#new-r'/0, '#new-r'/1, '#get-r'/2, '#set-r'/2,
42   - '#pos-r'/1, '#fromlist-r'/2, '#info-r'/1]).
43   -
44   - '#new-'(r) -&gt; '#new-r'().
45   -
46   - '#info-'(RecName) -&gt; '#info-'(RecName, fields).
47   -
48   - '#info-'(r, Info) -&gt; '#info-r'(Info).
49   -
50   - '#pos-'(r, Attr) -&gt; '#pos-r'(Attr).
51   -
52   - '#is_record-'(r, Rec)
53   - when tuple_size(Rec) == 3, element(1, Rec) == r -&gt;
54   - true;
55   - '#is_record-'(_, _) -&gt; false.
56   -
57   - '#get-'(Attrs, Rec) when is_record(Rec, r) -&gt;
58   - '#get-r'(Attrs, Rec).
59   -
60   - '#set-'(Vals, Rec) when is_record(Rec, r) -&gt;
61   - '#set-r'(Vals, Rec).
62   -
63   - '#fromlist-'(Vals, Rec) when is_record(Rec, r) -&gt;
64   - '#fromlist-r'(Vals, Rec).
65   -
66   - '#new-r'() -&gt; #r{}.
67   -
68   - '#new-r'(Vals) -&gt; '#set-r'(Vals, #r{}).
69   -
70   - '#get-r'(Attrs, R) when is_list(Attrs) -&gt;
71   - ['#get-r'(A, R) || A &lt;- Attrs];
72   - '#get-r'(a, R) -&gt; R#r.a;
73   - '#get-r'(b, R) -&gt; R#r.b;
74   - '#get-r'(c, R) -&gt; R#r.c;
75   - '#get-r'(Attr, R) -&gt;
76   - erlang:error(bad_record_op, ['#get-r', Attr, R]).
77   -
78   - '#set-r'(Vals, Rec) -&gt;
79   - F = fun ([], R, _F1) -&gt; R;
80   - ([{a, V} | T], R, F1) -&gt; F1(T, R#r{a = V}, F1);
81   - ([{b, V} | T], R, F1) -&gt; F1(T, R#r{b = V}, F1);
82   - ([{c, V} | T], R, F1) -&gt; F1(T, R#r{c = V}, F1);
83   - (Vs, R, _) -&gt;
84   - erlang:error(bad_record_op, ['#set-r', Vs, R])
85   - end,
86   - F(Vals, Rec, F).
87   -
88   - '#fromlist-r'(Vals, Rec) -&gt;
89   - AttrNames = [{a, 2}, {b, 3}, {c, 4}],
90   - F = fun ([], R, _F1) -&gt; R;
91   - ([{H, Pos} | T], R, F1) -&gt;
92   - case lists:keyfind(H, 1, Vals) of
93   - false -&gt; F1(T, R, F1);
94   - {_, Val} -&gt; F1(T, setelement(Pos, R, Val), F1)
95   - end
96   - end,
97   - F(AttrNames, Rec, F).
98   -
99   - '#pos-r'(a) -&gt; 2;
100   - '#pos-r'(b) -&gt; 3;
101   - '#pos-r'(c) -&gt; 4;
102   - '#pos-r'(_) -&gt; 0.
103   -
104   - '#info-r'(fields) -&gt; record_info(fields, r);
105   - '#info-r'(size) -&gt; record_info(size, r).
106   - </pre>
107   -<h2><a name="index">Function Index</a></h2>
108   -<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#parse_transform-2">parse_transform/2</a></td><td></td></tr>
109   -</table>
110   -
111   -<h2><a name="functions">Function Details</a></h2>
112   -
113   -<h3 class="function"><a name="parse_transform-2">parse_transform/2</a></h3>
114   -<div class="spec">
115   -<p><tt>parse_transform(Forms, Options) -&gt; any()</tt></p>
116   -</div>
117   -<hr>
118   -
119   -<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
120   -<p><i>Generated by EDoc, Sep 5 2010, 14:28:44.</i></p>
121   -</body>
122   -</html>
128 doc/exprecs.md
Source Rendered
... ... @@ -0,0 +1,128 @@
  1 +Module exprecs
  2 +==============
  3 +
  4 +
  5 +#Module exprecs#
  6 +* [Description](#description)
  7 +* [Function Index](#index)
  8 +* [Function Details](#functions)
  9 +Parse transform for generating record access functions.
  10 +__Authors:__ : Ulf Wiger ([`ulf.wiger@ericsson.com`](mailto:ulf.wiger@ericsson.com)).
  11 +
  12 +##<a name="description">Description</a>##
  13 +Parse transform for generating record access functions.
  14 +
  15 +This parse transform can be used to reduce compile-time
  16 + dependencies in large systems.
  17 +
  18 +In the old days, before records, Erlang programmers often wrote
  19 + access functions for tuple data. This was tedious and error-prone.
  20 + The record syntax made this easier, but since records were implemented
  21 + fully in the pre-processor, a nasty compile-time dependency was
  22 + introduced.
  23 +
  24 +This module automates the generation of access functions for
  25 + records. While this method cannot fully replace the utility of
  26 + pattern matching, it does allow a fair bit of functionality on
  27 + records without the need for compile-time dependencies.
  28 +
  29 +Whenever record definitions need to be exported from a module,
  30 + inserting a compiler attribute,
  31 + `export_records([RecName|...])` causes this transform
  32 + to lay out access functions for the exported records:
  33 +
  34 +
  35 +<pre>
  36 + -module(test_exprecs).
  37 +
  38 + -record(r, {a, b, c}).
  39 + -export_records([r]).
  40 +
  41 + -export(['#new-'/1, '#info-'/1, '#info-'/2, '#pos-'/2,
  42 + '#is_record-'/2, '#get-'/2, '#set-'/2, '#fromlist-'/2,
  43 + '#new-r'/0, '#new-r'/1, '#get-r'/2, '#set-r'/2,
  44 + '#pos-r'/1, '#fromlist-r'/2, '#info-r'/1]).
  45 +
  46 + '#new-'(r) -> '#new-r'().
  47 +
  48 + '#info-'(RecName) -> '#info-'(RecName, fields).
  49 +
  50 + '#info-'(r, Info) -> '#info-r'(Info).
  51 +
  52 + '#pos-'(r, Attr) -> '#pos-r'(Attr).
  53 +
  54 + '#is_record-'(r, Rec)
  55 + when tuple_size(Rec) == 3, element(1, Rec) == r ->
  56 + true;
  57 + '#is_record-'(_, _) -> false.
  58 +
  59 + '#get-'(Attrs, Rec) when is_record(Rec, r) ->
  60 + '#get-r'(Attrs, Rec).
  61 +
  62 + '#set-'(Vals, Rec) when is_record(Rec, r) ->
  63 + '#set-r'(Vals, Rec).
  64 +
  65 + '#fromlist-'(Vals, Rec) when is_record(Rec, r) ->
  66 + '#fromlist-r'(Vals, Rec).
  67 +
  68 + '#new-r'() -> #r{}.
  69 +
  70 + '#new-r'(Vals) -> '#set-r'(Vals, #r{}).
  71 +
  72 + '#get-r'(Attrs, R) when is_list(Attrs) ->
  73 + ['#get-r'(A, R) || A <- Attrs];
  74 + '#get-r'(a, R) -> R#r.a;
  75 + '#get-r'(b, R) -> R#r.b;
  76 + '#get-r'(c, R) -> R#r.c;
  77 + '#get-r'(Attr, R) ->
  78 + erlang:error(bad_record_op, ['#get-r', Attr, R]).
  79 +
  80 + '#set-r'(Vals, Rec) ->
  81 + F = fun ([], R, _F1) -> R;
  82 + ([{a, V} | T], R, F1) -> F1(T, R#r{a = V}, F1);
  83 + ([{b, V} | T], R, F1) -> F1(T, R#r{b = V}, F1);
  84 + ([{c, V} | T], R, F1) -> F1(T, R#r{c = V}, F1);
  85 + (Vs, R, _) ->
  86 + erlang:error(bad_record_op, ['#set-r', Vs, R])
  87 + end,
  88 + F(Vals, Rec, F).
  89 +
  90 + '#fromlist-r'(Vals, Rec) ->
  91 + AttrNames = [{a, 2}, {b, 3}, {c, 4}],
  92 + F = fun ([], R, _F1) -> R;
  93 + ([{H, Pos} | T], R, F1) ->
  94 + case lists:keyfind(H, 1, Vals) of
  95 + false -> F1(T, R, F1);
  96 + {_, Val} -> F1(T, setelement(Pos, R, Val), F1)
  97 + end
  98 + end,
  99 + F(AttrNames, Rec, F).
  100 +
  101 + '#pos-r'(a) -> 2;
  102 + '#pos-r'(b) -> 3;
  103 + '#pos-r'(c) -> 4;
  104 + '#pos-r'(_) -> 0.
  105 +
  106 + '#info-r'(fields) -> record_info(fields, r);
  107 + '#info-r'(size) -> record_info(size, r).
  108 + </pre>
  109 +
  110 +
  111 +##<a name="index">Function Index</a>##
  112 +
  113 +<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#parse_transform-2">parse_transform/2</a></td><td></td></tr></table>
  114 +
  115 +<a name="functions"></a>
  116 +
  117 +
  118 +##Function Details##
  119 +
  120 +<a name="parse_transform-2"></a>
  121 +
  122 +
  123 +###parse_transform/2##
  124 +
  125 +
  126 +`parse_transform(Forms, Options) -> any()`
  127 +
  128 +_Generated by EDoc, Oct 23 2010, 21:00:45._
17 doc/index.html
... ... @@ -1,17 +0,0 @@
1   -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2   -<html>
3   -<head>
4   -<title>The parse_trans application</title>
5   -</head>
6   -<frameset cols="20%,80%">
7   -<frame src="modules-frame.html" name="modulesFrame" title="">
8   -
9   -<frame src="overview-summary.html" name="overviewFrame" title="">
10   -<noframes>
11   -<h2>This page uses frames</h2>
12   -<p>Your browser does not accept frames.
13   -<br>You should go to the <a href="overview-summary.html">non-frame version</a> instead.
14   -</p>
15   -</noframes>
16   -</frameset>
17   -</html>
16 doc/modules-frame.html
... ... @@ -1,16 +0,0 @@
1   -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2   -<html>
3   -<head>
4   -<title>The parse_trans application</title>
5   -<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
6   -</head>
7   -<body bgcolor="white">
8   -<h2 class="indextitle">Modules</h2>
9   -<table width="100%" border="0" summary="list of modules">
10   -<tr><td><a href="ct_expand.html" target="overviewFrame" class="module">ct_expand</a></td></tr>
11   -<tr><td><a href="exprecs.html" target="overviewFrame" class="module">exprecs</a></td></tr>
12   -<tr><td><a href="parse_trans.html" target="overviewFrame" class="module">parse_trans</a></td></tr>
13   -<tr><td><a href="parse_trans_codegen.html" target="overviewFrame" class="module">parse_trans_codegen</a></td></tr>
14   -<tr><td><a href="parse_trans_pp.html" target="overviewFrame" class="module">parse_trans_pp</a></td></tr></table>
15   -</body>
16   -</html>
68 doc/overview-summary.html
... ... @@ -1,68 +0,0 @@
1   -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2   -<html>
3   -<head>
4   -<title>The parse_trans application</title>
5   -<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
6   -</head>
7   -<body bgcolor="white">
8   -<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
9   -<h1>The parse_trans application</h1>
10   -<p><b>Authors:</b> Ulf Wiger (<a href="mailto:ulf.wiger@erlang-consulting.com"><tt>ulf.wiger@erlang-consulting.com</tt></a>).</p>
11   -<p>A generic parse transform library
12   -This library is intended to simplify the task of writing parse transform
13   -modules for Erlang.</p>
14   -
15   -<h1>Introduction to parse transforms</h1>
16   -
17   -<h2>The simplest transform</h2>
18   -
19   -<p>The very simplest transform we can make is one that doesn't
20   -change a thing. For convenience, we will at least print the forms.
21   -This will enlighten us as to what the forms actually look like.</p>
22   -
23   -<pre>
24   --module(test_pt).
25   -
26   --export([parse_transform/2]).
27   -
28   -parse_transform(Forms, _Options) -&gt;
29   - io:fwrite("Forms = ~p~n", [Forms]),
30   - Forms.
31   -</pre>
32   -
33   -<p>Trying this with a very simple module:</p>
34   -
35   -<pre>
36   --module(ex1).
37   --export([add/2]).
38   -
39   -add(X,Y) -&gt;
40   - X + Y.
41   -</pre>
42   -
43   -<pre>
44   -1&gt; c(ex1, [{parse_transform,test_pt}]).
45   -Forms = [{attribute,1,file,{"./ex1.erl",1}},
46   - {attribute,1,module,ex1},
47   - {attribute,2,export,[{add,2}]},
48   - {function,4,add,2,
49   - [{clause,4,
50   - [{var,4,'X'},{var,4,'Y'}],
51   - [],
52   - [{op,5,'+',{var,5,'X'},{var,5,'Y'}}]}]},
53   - {eof,6}]
54   -{ok,ex1}
55   -</pre>
56   -
57   -<h2><code>transform/4</code></h2>
58   -<p>...</p>
59   -
60   -
61   -<h1>Current limitations</h1>
62   -<p>...</p>
63   -
64   -<hr>
65   -<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
66   -<p><i>Generated by EDoc, Sep 5 2010, 14:28:44.</i></p>
67   -</body>
68   -</html>
11 doc/packages-frame.html
... ... @@ -1,11 +0,0 @@
1   -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2   -<html>
3   -<head>
4   -<title>The parse_trans application</title>
5   -<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
6   -</head>
7   -<body bgcolor="white">
8   -<h2 class="indextitle">Packages</h2>
9   -<table width="100%" border="0" summary="list of packages"></table>
10   -</body>
11   -</html>
217 doc/parse_trans.html
... ... @@ -1,217 +0,0 @@
1   -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2   -<html>
3   -<head>
4   -<title>Module parse_trans</title>
5   -<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
6   -</head>
7   -<body bgcolor="white">
8   -<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
9   -<hr>
10   -
11   -<h1>Module parse_trans</h1>
12   -<ul class="index"><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>Generic parse transform library for Erlang.
13   -
14   -<p><b>Authors:</b> : Ulf Wiger (<a href="mailto:ulf.wiger@erlang-consulting.com"><tt>ulf.wiger@erlang-consulting.com</tt></a>).</p>
15   -
16   -<h2><a name="description">Description</a></h2><p>Generic parse transform library for Erlang.</p>
17   -
18   - <p>...</p>
19   -
20   -<h2><a name="index">Function Index</a></h2>
21   -<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#context-2">context/2</a></td><td>
22   - Accessor function for the Context record.</td></tr>
23   -<tr><td valign="top"><a href="#depth_first-4">depth_first/4</a></td><td></td></tr>
24   -<tr><td valign="top"><a href="#do_depth_first-4">do_depth_first/4</a></td><td></td></tr>
25   -<tr><td valign="top"><a href="#do_insert_forms-4">do_insert_forms/4</a></td><td></td></tr>
26   -<tr><td valign="top"><a href="#do_inspect-4">do_inspect/4</a></td><td></td></tr>
27   -<tr><td valign="top"><a href="#do_transform-4">do_transform/4</a></td><td></td></tr>
28   -<tr><td valign="top"><a href="#error-3">error/3</a></td><td>.</td></tr>
29   -<tr><td valign="top"><a href="#format_error-1">format_error/1</a></td><td></td></tr>
30   -<tr><td valign="top"><a href="#function_exists-3">function_exists/3</a></td><td>
31   - Checks whether the given function is defined in Forms.</td></tr>
32   -<tr><td valign="top"><a href="#get_attribute-2">get_attribute/2</a></td><td>
33   - Returns the value of the first occurence of attribute A.</td></tr>
34   -<tr><td valign="top"><a href="#get_file-1">get_file/1</a></td><td>
35   - Returns the name of the file being compiled.</td></tr>
36   -<tr><td valign="top"><a href="#get_module-1">get_module/1</a></td><td>
37   - Returns the name of the module being compiled.</td></tr>
38   -<tr><td valign="top"><a href="#get_orig_syntax_tree-1">get_orig_syntax_tree/1</a></td><td>.</td></tr>
39   -<tr><td valign="top"><a href="#get_pos-1">get_pos/1</a></td><td>
40   - Tries to retrieve the line number from an erl_syntax form.</td></tr>
41   -<tr><td valign="top"><a href="#initial_context-2">initial_context/2</a></td><td>
42   - Initializes a context record.</td></tr>
43   -<tr><td valign="top"><a href="#inspect-4">inspect/4</a></td><td>
44   - Equvalent to do_inspect(Fun,Acc,Forms,initial_context(Forms,Options)).</td></tr>
45   -<tr><td valign="top"><a href="#optionally_pretty_print-3">optionally_pretty_print/3</a></td><td></td></tr>
46   -<tr><td valign="top"><a href="#pp_beam-1">pp_beam/1</a></td><td>
47   - Reads debug_info from the beam file Beam and returns a string containing
48   - the pretty-printed corresponding erlang source code.</td></tr>
49   -<tr><td valign="top"><a href="#pp_beam-2">pp_beam/2</a></td><td>
50   - Reads debug_info from the beam file Beam and pretty-prints it as
51   - Erlang source code, storing it in the file Out.</td></tr>
52   -<tr><td valign="top"><a href="#pp_src-2">pp_src/2</a></td><td>Pretty-prints the erlang source code corresponding to Forms into Out.</td></tr>
53   -<tr><td valign="top"><a href="#revert-1">revert/1</a></td><td>Reverts back from Syntax Tools format to Erlang forms.</td></tr>
54   -<tr><td valign="top"><a href="#top-3">top/3</a></td><td></td></tr>
55   -<tr><td valign="top"><a href="#transform-4">transform/4</a></td><td>
56   - Makes one pass.</td></tr>
57   -</table>
58   -
59   -<h2><a name="functions">Function Details</a></h2>
60   -
61   -<h3 class="function"><a name="context-2">context/2</a></h3>
62   -<div class="spec">
63   -<p><tt>context(X1::Attr, Context) -&gt; any()</tt>
64   -<ul class="definitions"><li><tt>Attr = module | function | arity | options</tt></li>
65   -</ul></p>
66   -</div><p>
67   - Accessor function for the Context record.</p>
68   -
69   -<h3 class="function"><a name="depth_first-4">depth_first/4</a></h3>
70   -<div class="spec">
71   -<p><tt>depth_first(Fun, Acc, Forms, Options) -&gt; any()</tt></p>
72   -</div>
73   -
74   -<h3 class="function"><a name="do_depth_first-4">do_depth_first/4</a></h3>
75   -<div class="spec">
76   -<p><tt>do_depth_first(F, Acc, Forms, Context) -&gt; any()</tt></p>
77   -</div>
78   -
79   -<h3 class="function"><a name="do_insert_forms-4">do_insert_forms/4</a></h3>
80   -<div class="spec">
81   -<p><tt>do_insert_forms(X1, Insert, Forms, Context) -&gt; any()</tt></p>
82   -</div>
83   -
84   -<h3 class="function"><a name="do_inspect-4">do_inspect/4</a></h3>
85   -<div class="spec">
86   -<p><tt>do_inspect(F, Acc, Forms, Context) -&gt; any()</tt></p>
87   -</div>
88   -
89   -<h3 class="function"><a name="do_transform-4">do_transform/4</a></h3>
90   -<div class="spec">
91   -<p><tt>do_transform(F, Acc, Forms, Context) -&gt; any()</tt></p>
92   -</div>
93   -
94   -<h3 class="function"><a name="error-3">error/3</a></h3>
95   -<div class="spec">
96   -<p><tt>error(R::Reason, F::Form, I::Info) -&gt; <a href="#type-throw">throw()</a></tt>
97   -<ul class="definitions"><li><tt>Info = [{Key, Value}]</tt></li>
98   -</ul></p>
99   -</div><p>
100   - <p>Used to report errors detected during the parse transform.</p></p>
101   -
102   -<h3 class="function"><a name="format_error-1">format_error/1</a></h3>
103   -<div class="spec">
104   -<p><tt>format_error(X1) -&gt; any()</tt></p>
105   -</div>
106   -
107   -<h3 class="function"><a name="function_exists-3">function_exists/3</a></h3>
108   -<div class="spec">
109   -<p><tt>function_exists(Fname::atom(), Arity::integer(), Forms) -&gt; <a href="#type-boolean">boolean()</a></tt></p>
110   -</div><p>
111   - Checks whether the given function is defined in Forms.</p>
112   -
113   -<h3 class="function"><a name="get_attribute-2">get_attribute/2</a></h3>
114   -<div class="spec">
115   -<p><tt>get_attribute(A, Forms) -&gt; any()</tt>
116   -<ul class="definitions"><li><tt>A = atom()</tt></li>
117   -</ul></p>
118   -</div><p>
119   - Returns the value of the first occurence of attribute A.</p>
120   -
121   -<h3 class="function"><a name="get_file-1">get_file/1</a></h3>
122   -<div class="spec">
123   -<p><tt>get_file(Forms) -&gt; string()</tt></p>
124   -</div><p>
125   - Returns the name of the file being compiled.</p>
126   -
127   -<h3 class="function"><a name="get_module-1">get_module/1</a></h3>
128   -<div class="spec">
129   -<p><tt>get_module(Forms) -&gt; atom()</tt></p>
130   -</div><p>
131   - Returns the name of the module being compiled.</p>
132   -
133   -<h3 class="function"><a name="get_orig_syntax_tree-1">get_orig_syntax_tree/1</a></h3>
134   -<div class="spec">
135   -<p><tt>get_orig_syntax_tree(File) -&gt; Forms</tt></p>
136   -</div><p>
137   - <p>Fetches a Syntax Tree representing the code before pre-processing,
138   - that is, including record and macro definitions. Note that macro
139   - definitions must be syntactically complete forms (this function
140   - uses epp_dodger).</p></p>
141   -
142   -<h3 class="function"><a name="get_pos-1">get_pos/1</a></h3>
143   -<div class="spec">
144   -<p><tt>get_pos(I::list()) -&gt; integer()</tt></p>
145   -</div><p>
146   - Tries to retrieve the line number from an erl_syntax form. Returns a
147   - (very high) dummy number if not successful.</p>
148   -
149   -<h3 class="function"><a name="initial_context-2">initial_context/2</a></h3>
150   -<div class="spec">
151   -<p><tt>initial_context(Forms, Options) -&gt; #context{}</tt></p>
152   -</div><p>
153   - Initializes a context record. When traversing through the form
154   - list, the context is updated to reflect the current function and
155   - arity. Static elements in the context are the file name, the module
156   - name and the options passed to the transform function.</p>
157   -
158   -<h3 class="function"><a name="inspect-4">inspect/4</a></h3>
159   -<div class="spec">
160   -<p><tt>inspect(F::Fun, Acc::Forms, Forms::Acc, Options) -&gt; NewAcc</tt>
161   -<ul class="definitions"><li><tt>Fun = function()</tt></li>
162   -</ul></p>
163   -</div><p>
164   - Equvalent to do_inspect(Fun,Acc,Forms,initial_context(Forms,Options)).</p>
165   -
166   -<h3 class="function"><a name="optionally_pretty_print-3">optionally_pretty_print/3</a></h3>
167   -<div class="spec">
168   -<p><tt>optionally_pretty_print(Result, Options, Context) -&gt; any()</tt></p>
169   -</div>
170   -
171   -<h3 class="function"><a name="pp_beam-1">pp_beam/1</a></h3>
172   -<div class="spec">
173   -<p><tt>pp_beam(Beam::<a href="#type-filename">filename()</a>) -&gt; string() | {error, Reason}</tt></p>
174   -</div><p>
175   - Reads debug_info from the beam file Beam and returns a string containing
176   - the pretty-printed corresponding erlang source code.</p>
177   -
178   -<h3 class="function"><a name="pp_beam-2">pp_beam/2</a></h3>
179   -<div class="spec">
180   -<p><tt>pp_beam(Beam::<a href="#type-filename">filename()</a>, Out::<a href="#type-filename">filename()</a>) -&gt; ok | {error, Reason}</tt></p>
181   -</div><p>
182   - Reads debug_info from the beam file Beam and pretty-prints it as
183   - Erlang source code, storing it in the file Out.</p>
184   -
185   -<h3 class="function"><a name="pp_src-2">pp_src/2</a></h3>
186   -<div class="spec">
187   -<p><tt>pp_src(Res::Forms, Out::<a href="#type-filename">filename()</a>) -&gt; ok</tt></p>
188   -</div><p>Pretty-prints the erlang source code corresponding to Forms into Out
189   - </p>
190   -
191   -<h3 class="function"><a name="revert-1">revert/1</a></h3>
192   -<div class="spec">
193   -<p><tt>revert(Tree) -&gt; Forms</tt></p>
194   -</div><p>Reverts back from Syntax Tools format to Erlang forms.
195   - <p>Note that the Erlang forms are a subset of the Syntax Tools
196   - syntax tree, so this function is safe to call even on a list of
197   - regular Erlang forms.</p></p>
198   -
199   -<h3 class="function"><a name="top-3">top/3</a></h3>
200   -<div class="spec">
201   -<p><tt>top(F, Forms, Options) -&gt; any()</tt></p>
202   -</div>
203   -
204   -<h3 class="function"><a name="transform-4">transform/4</a></h3>
205   -<div class="spec">
206   -<p><tt>transform(Fun, Acc, Forms, Options) -&gt; {TransformedForms, NewAcc}</tt>
207   -<ul class="definitions"><li><tt>Fun = function()</tt></li>
208   -<li><tt>Options = [{Key, Value}]</tt></li>
209   -</ul></p>
210   -</div><p>
211   - Makes one pass</p>
212   -<hr>
213   -
214   -<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
215   -<p><i>Generated by EDoc, Sep 5 2010, 14:28:44.</i></p>
216   -</body>
217   -</html>
276 doc/parse_trans.md
Source Rendered
... ... @@ -0,0 +1,276 @@
  1 +Module parse_trans
  2 +==================
  3 +
  4 +
  5 +#Module parse_trans#
  6 +* [Description](#description)
  7 +* [Function Index](#index)
  8 +* [Function Details](#functions)
  9 +Generic parse transform library for Erlang.
  10 +__Authors:__ : Ulf Wiger ([`ulf.wiger@erlang-consulting.com`](mailto:ulf.wiger@erlang-consulting.com)).
  11 +
  12 +##<a name="description">Description</a>##
  13 +
  14 +Generic parse transform library for Erlang.
  15 +
  16 +
  17 +...
  18 +
  19 +
  20 +##<a name="index">Function Index</a>##
  21 +
  22 +<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#context-2">context/2</a></td><td>
  23 + Accessor function for the Context record.</td></tr><tr><td valign="top"><a href="#depth_first-4">depth_first/4</a></td><td></td></tr><tr><td valign="top"><a href="#do_depth_first-4">do_depth_first/4</a></td><td></td></tr><tr><td valign="top"><a href="#do_insert_forms-4">do_insert_forms/4</a></td><td></td></tr><tr><td valign="top"><a href="#do_inspect-4">do_inspect/4</a></td><td></td></tr><tr><td valign="top"><a href="#do_transform-4">do_transform/4</a></td><td></td></tr><tr><td valign="top"><a href="#error-3">error/3</a></td><td>.</td></tr><tr><td valign="top"><a href="#format_error-1">format_error/1</a></td><td></td></tr><tr><td valign="top"><a href="#function_exists-3">function_exists/3</a></td><td>
  24 + Checks whether the given function is defined in Forms.</td></tr><tr><td valign="top"><a href="#get_attribute-2">get_attribute/2</a></td><td>
  25 + Returns the value of the first occurence of attribute A.</td></tr><tr><td valign="top"><a href="#get_file-1">get_file/1</a></td><td>
  26 + Returns the name of the file being compiled.</td></tr><tr><td valign="top"><a href="#get_module-1">get_module/1</a></td><td>
  27 + Returns the name of the module being compiled.</td></tr><tr><td valign="top"><a href="#get_orig_syntax_tree-1">get_orig_syntax_tree/1</a></td><td>.</td></tr><tr><td valign="top"><a href="#get_pos-1">get_pos/1</a></td><td>
  28 + Tries to retrieve the line number from an erl_syntax form.</td></tr><tr><td valign="top"><a href="#initial_context-2">initial_context/2</a></td><td>
  29 + Initializes a context record.</td></tr><tr><td valign="top"><a href="#inspect-4">inspect/4</a></td><td>
  30 + Equvalent to do_inspect(Fun,Acc,Forms,initial_context(Forms,Options)).</td></tr><tr><td valign="top"><a href="#optionally_pretty_print-3">optionally_pretty_print/3</a></td><td></td></tr><tr><td valign="top"><a href="#pp_beam-1">pp_beam/1</a></td><td>
  31 + Reads debug_info from the beam file Beam and returns a string containing
  32 + the pretty-printed corresponding erlang source code.</td></tr><tr><td valign="top"><a href="#pp_beam-2">pp_beam/2</a></td><td>
  33 + Reads debug_info from the beam file Beam and pretty-prints it as
  34 + Erlang source code, storing it in the file Out.</td></tr><tr><td valign="top"><a href="#pp_src-2">pp_src/2</a></td><td>Pretty-prints the erlang source code corresponding to Forms into Out.</td></tr><tr><td valign="top"><a href="#revert-1">revert/1</a></td><td>Reverts back from Syntax Tools format to Erlang forms.</td></tr><tr><td valign="top"><a href="#top-3">top/3</a></td><td></td></tr><tr><td valign="top"><a href="#transform-4">transform/4</a></td><td>
  35 + Makes one pass.</td></tr></table>
  36 +
  37 +<a name="functions"></a>
  38 +
  39 +
  40 +##Function Details##
  41 +
  42 +<a name="context-2"></a>
  43 +
  44 +
  45 +###context/2##
  46 +
  47 +
  48 +`context(X1::Attr, Context) -> any()`* `Attr = module | function | arity | options`
  49 +
  50 +
  51 +
  52 + Accessor function for the Context record.
  53 +<a name="depth_first-4"></a>
  54 +
  55 +
  56 +###depth_first/4##
  57 +
  58 +
  59 +`depth_first(Fun, Acc, Forms, Options) -> any()`
  60 +
  61 +<a name="do_depth_first-4"></a>
  62 +
  63 +
  64 +###do_depth_first/4##
  65 +
  66 +
  67 +`do_depth_first(F, Acc, Forms, Context) -> any()`
  68 +
  69 +<a name="do_insert_forms-4"></a>
  70 +
  71 +
  72 +###do_insert_forms/4##
  73 +
  74 +
  75 +`do_insert_forms(X1, Insert, Forms, Context) -> any()`
  76 +
  77 +<a name="do_inspect-4"></a>
  78 +
  79 +
  80 +###do_inspect/4##
  81 +
  82 +
  83 +`do_inspect(F, Acc, Forms, Context) -> any()`
  84 +
  85 +<a name="do_transform-4"></a>
  86 +
  87 +
  88 +###do_transform/4##
  89 +
  90 +
  91 +`do_transform(F, Acc, Forms, Context) -> any()`
  92 +
  93 +<a name="error-3"></a>
  94 +
  95 +
  96 +###error/3##
  97 +
  98 +
  99 +`error(R::Reason, F::Form, I::Info) -> [throw()](#type-throw)`* `Info = [{Key, Value}]`
  100 +
  101 +
  102 +
  103 +
  104 +Used to report errors detected during the parse transform.
  105 +<a name="format_error-1"></a>
  106 +
  107 +
  108 +###format_error/1##
  109 +
  110 +
  111 +`format_error(X1) -> any()`
  112 +
  113 +<a name="function_exists-3"></a>
  114 +
  115 +
  116 +###function_exists/3##
  117 +
  118 +
  119 +`function_exists(Fname::atom(), Arity::integer(), Forms) -> [boolean()](#type-boolean)`
  120 +
  121 +
  122 + Checks whether the given function is defined in Forms.
  123 +<a name="get_attribute-2"></a>
  124 +
  125 +
  126 +###get_attribute/2##
  127 +
  128 +
  129 +`get_attribute(A, Forms) -> any()`* `A = atom()`
  130 +
  131 +
  132 +
  133 + Returns the value of the first occurence of attribute A.
  134 +<a name="get_file-1"></a>
  135 +
  136 +
  137 +###get_file/1##
  138 +
  139 +
  140 +`get_file(Forms) -> string()`
  141 +
  142 +
  143 + Returns the name of the file being compiled.
  144 +<a name="get_module-1"></a>
  145 +
  146 +
  147 +###get_module/1##
  148 +
  149 +
  150 +`get_module(Forms) -> atom()`
  151 +
  152 +
  153 + Returns the name of the module being compiled.
  154 +<a name="get_orig_syntax_tree-1"></a>
  155 +
  156 +
  157 +###get_orig_syntax_tree/1##
  158 +
  159 +
  160 +`get_orig_syntax_tree(File) -> Forms`
  161 +
  162 +
  163 +
  164 +Fetches a Syntax Tree representing the code before pre-processing,
  165 + that is, including record and macro definitions. Note that macro
  166 + definitions must be syntactically complete forms (this function
  167 + uses epp_dodger).
  168 +<a name="get_pos-1"></a>
  169 +
  170 +
  171 +###get_pos/1##
  172 +
  173 +
  174 +`get_pos(I::list()) -> integer()`
  175 +
  176 +
  177 + Tries to retrieve the line number from an erl_syntax form. Returns a
  178 + (very high) dummy number if not successful.
  179 +<a name="initial_context-2"></a>
  180 +
  181 +
  182 +###initial_context/2##
  183 +
  184 +
  185 +`initial_context(Forms, Options) -> #context{}`
  186 +
  187 +
  188 + Initializes a context record. When traversing through the form
  189 + list, the context is updated to reflect the current function and
  190 + arity. Static elements in the context are the file name, the module
  191 + name and the options passed to the transform function.
  192 +<a name="inspect-4"></a>
  193 +
  194 +
  195 +###inspect/4##
  196 +
  197 +
  198 +`inspect(F::Fun, Acc::Forms, Forms::Acc, Options) -> NewAcc`* `Fun = function()`
  199 +
  200 +
  201 +
  202 + Equvalent to do_inspect(Fun,Acc,Forms,initial_context(Forms,Options)).
  203 +<a name="optionally_pretty_print-3"></a>
  204 +
  205 +
  206 +###optionally_pretty_print/3##
  207 +
  208 +
  209 +`optionally_pretty_print(Result, Options, Context) -> any()`
  210 +
  211 +<a name="pp_beam-1"></a>
  212 +
  213 +
  214 +###pp_beam/1##
  215 +
  216 +
  217 +`pp_beam(Beam::[filename()](#type-filename)) -> string() | {error, Reason}`
  218 +
  219 +
  220 + Reads debug_info from the beam file Beam and returns a string containing
  221 + the pretty-printed corresponding erlang source code.
  222 +<a name="pp_beam-2"></a>
  223 +
  224 +
  225 +###pp_beam/2##
  226 +
  227 +
  228 +`pp_beam(Beam::[filename()](#type-filename), Out::[filename()](#type-filename)) -> ok | {error, Reason}`
  229 +
  230 +
  231 + Reads debug_info from the beam file Beam and pretty-prints it as
  232 + Erlang source code, storing it in the file Out.
  233 +<a name="pp_src-2"></a>
  234 +
  235 +
  236 +###pp_src/2##
  237 +
  238 +
  239 +`pp_src(Res::Forms, Out::[filename()](#type-filename)) -> ok`
  240 +
  241 +Pretty-prints the erlang source code corresponding to Forms into Out
  242 +
  243 +<a name="revert-1"></a>
  244 +
  245 +
  246 +###revert/1##
  247 +
  248 +
  249 +`revert(Tree) -> Forms`
  250 +
  251 +Reverts back from Syntax Tools format to Erlang forms.
  252 +
  253 +Note that the Erlang forms are a subset of the Syntax Tools
  254 + syntax tree, so this function is safe to call even on a list of
  255 + regular Erlang forms.
  256 +<a name="top-3"></a>
  257 +
  258 +
  259 +###top/3##
  260 +
  261 +
  262 +`top(F, Forms, Options) -> any()`
  263 +
  264 +<a name="transform-4"></a>
  265 +
  266 +
  267 +###transform/4##
  268 +
  269 +
  270 +`transform(Fun, Acc, Forms, Options) -> {TransformedForms, NewAcc}`* `Fun = function()`
  271 +* `Options = [{Key, Value}]`
  272 +
  273 +
  274 +
  275 + Makes one pass
  276 +_Generated by EDoc, Oct 23 2010, 21:00:44._
96 doc/parse_trans_codegen.html
... ... @@ -1,96 +0,0 @@
1   -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2   -<html>
3   -<head>
4   -<title>Module parse_trans_codegen</title>
5   -<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
6   -</head>
7   -<body bgcolor="white">
8   -<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
9   -<hr>
10   -
11   -<h1>Module parse_trans_codegen</h1>
12   -<ul class="index"><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>Parse transform for code generation pseduo functions.
13   -
14   -<p><b>Authors:</b> : Ulf Wiger (<a href="mailto:ulf.wiger@erlang-solutions.com"><tt>ulf.wiger@erlang-solutions.com</tt></a>).</p>
15   -
16   -<h2><a name="description">Description</a></h2><p>Parse transform for code generation pseduo functions</p>
17   -
18   - <p>...</p>
19   -
20   -<h2><a name="index">Function Index</a></h2>
21   -<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#parse_transform-2">parse_transform/2</a></td><td>
22   - Searches for calls to pseudo functions in the module <code>codegen</code>,
23   -and converts the corresponding erlang code to a data structure
24   -representing the abstract form of that code.</td></tr>
25   -</table>
26   -
27   -<h2><a name="functions">Function Details</a></h2>
28   -
29   -<h3 class="function"><a name="parse_transform-2">parse_transform/2</a></h3>
30   -<div class="spec">
31   -<p><tt>parse_transform(Forms, Options) -&gt; NewForms</tt></p>
32   -</div><p><p>
33   - Searches for calls to pseudo functions in the module <code>codegen</code>,
34   -and converts the corresponding erlang code to a data structure
35   -representing the abstract form of that code.</p>
36   -
37   - <p>The purpose of these functions is to let the programmer write
38   -the actual code that is to be generated, rather than manually
39   -writing abstract forms, which is more error prone and cannot be
40   -checked by the compiler until the generated module is compiled.</p>
41   -
42   - <p>Supported functions:</p>
43   -
44   - <h2>gen_function/2</h2>
45   -
46   - <p>Usage: <code>codegen:gen_function(Name, Fun)</code></p>
47   -
48   - <p>Substitutes the abstract code for a function with name <code>Name</code>
49   - and the same behaviour as <code>Fntun</code>.</p>
50   -
51   - <p><code>Fun</code> can either be a anonymous <code>fun</code>, which is then converted to
52   - a named function. It can also be an <code>implicit fun</code>, e.g.
53   - <code>fun is_member/2</code>. In this case, the referenced function is fetched
54   - and converted to an abstract form representation. It is also renamed
55   - so that the generated function has the name <code>Name</code>.</p>
56   -
57   - <h2>gen_functions/1</h2>
58   -
59   - <p>Takes a list of <code>{Name, Fun}</code> tuples and produces a list of abstract
60   - data objects, just as if one had written
61   - <code>[codegen:gen_function(N1,F1),codegen:gen_function(N2,F2),...]</code>.</p>
62   -
63   - <h2>exprs/1</h2>
64   -
65   - <p>Usage: <code>codegen:exprs(Fun)</code></p>
66   -
67   - <p><code>Fun</code> is either an anonymous function, or an implicit fun with only one
68   -function clause. This "function" takes the body of the fun and produces
69   -a data type representing the abstract form of the list of expressions in
70   -the body. The arguments of the function clause are ignored, but can be
71   -used to ensure that all necessary variables are known to the compiler.</p>
72   -
73   - <h2>Variable substitution</h2>
74   -
75   - <p>It is possible to do some limited expansion (importing a value
76   - bound at compile-time), using the construct <code>{'$var', V}</code>, where
77   - <code>V</code> is a bound variable in the scope of the call to <code>gen_function/2</code>.</p>
78   -
79   - Example:
80   - <pre>
81   - gen(Name, X) -&gt;
82   - codegen:gen_function(Name, fun(L) -&gt; lists:member({'$var',X}, L) end).
83   - </pre>
84   -
85   - After transformation, calling <code>gen(contains_17, 17)</code> will yield the
86   - abstract form corresponding to:
87   - <pre>
88   - contains_17(L) -&gt;
89   - lists:member(17, L).
90   - </pre></p>
91   -<hr>
92   -
93   -<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
94   -<p><i>Generated by EDoc, Sep 5 2010, 14:28:44.</i></p>
95   -</body>
96   -</html>
125 doc/parse_trans_codegen.md
Source Rendered
... ... @@ -0,0 +1,125 @@
  1 +Module parse_trans_codegen
  2 +==========================
  3 +
  4 +
  5 +#Module parse_trans_codegen#
  6 +* [Description](#description)
  7 +* [Function Index](#index)
  8 +* [Function Details](#functions)
  9 +Parse transform for code generation pseduo functions.
  10 +__Authors:__ : Ulf Wiger ([`ulf.wiger@erlang-solutions.com`](mailto:ulf.wiger@erlang-solutions.com)).
  11 +
  12 +##<a name="description">Description</a>##
  13 +
  14 +Parse transform for code generation pseduo functions
  15 +
  16 +
  17 +...
  18 +
  19 +
  20 +##<a name="index">Function Index</a>##