Module erlpipe

Authors: Serge Aleynikov (saleyn(at)gmail(dot)com).


Erlang pipeline parse transform

This transform implements a parser syntax extension that enables application of cascading function calls using the / operator.

In the LHS / RHS / ... Last. notation, the result of evaluation of the LHS expression is passed as an argument to the RHS expression. This process continues until the Last expression is evaluated. The head element of the pipeline must be either a term to which the arithmetic division /` operator cannot apply (i.e. not integers, floats, functions), or if you need to pass integer(s) or float(s), wrap them in a list brackets. This transfor is inspired by the similar functionality in Linux (i.e. `| pipe) and Elixir (|> pipe).

When using this as a parse transform, include the {parse_transform,erlpipe} compiler option.

The following examples illustrate the work of the transform, in which:
   test1(A)   -> [A]   / fun1 / mod:fun2 / fun3.
   test2(A,B) -> [A,B] / fun4 / fun5() / io:format("~p\n", [_]).
will be transformed to:
   test1(A)   -> fun3(mod:fun2(fun1(A))).
   test2(A,B) -> io:format("~p\n", [fun5(fun4(A,B))]).
For debugging the AST of the resulting transform, pass the following options to the erlc compiler:
  • -Derlpipe_orig - print the original AST before the transform
  • -Derlpipe_ast - print the transformed AST
  • -Derlpipe_src - print the resulting source code after the transform
  • Function Index

    parse_transform/2parse_transform entry point.

    Function Details


    parse_transform(AST, Options) -> any()

    parse_transform entry point