Module eqc_ag

This module provides an attribute grammar system for Erlang.

Copyright © Quviq AB, 2014-2015

Version: 2.01.0

Description

This module provides an attribute grammar system for Erlang. Attribute grammars provide a modular way of defining functions over tree-shaped data, allowing each aspect of the computation to be defined as a separate attribute. Attributes are defined using a special purpose syntax. For example, calculating the height of a tree:

 -type tree() :: {leaf, integer()} | {node, tree(), tree()}.

 height({leaf, _})  :- 0;
 height(X)          :- 1 + lists:max(height(X, list)).

 > eqc_ag:compute([examples:height()], {node,{node,{leaf,3},{node,{leaf,2},{leaf,1}}},
                                                            {node,{leaf,4},{leaf,6}}}).
 > 3
 
A detailed description of the attribute grammar system can be found here.

Function Index

compute/2Equivalent to compute(Attrs, tuple_traversal(), [], T).
compute/3Equivalent to compute(Attrs, Pat, [], T) or compute(Attrs, tuple_traversal(), In, T) depending on the type of the second argument, which may either be a pattern function or a list of initial values.
compute/4This function is a wrapper around the traverse/4 function.
compute_gen/3Equivalent to compute_m(mondad_gen(), Attrs, Pattern, In).
compute_m/4A wrapper around the unfold/4 function.
compute_pure/3Equivalent to compute_m(mondad_id(), Attrs, Pattern, In).
global/1This function declares a constant inherited attribute.
global/2A constant inherited attribute with a given value.
monad_gen/0The eqc_gen generator monad.
monad_id/0The identity monad.
rename/2Rename an existing attribute to another given attribute.
term/0The identity attribute which simply returns the traversed term.
term_traversal/0A pattern function that adds a placeholder for every subterm.
traverse/2Equivalent to traverse(Attrs, tuple_traversal(), [], T).
traverse/3Equivalent to traverse(Attrs, Pat, [], T) or traverse(Attrs, tuple_traversal(), In, T) depending on the type of the second argument, which may either be a pattern function or a list of initial values.
traverse/4This function takes a list of attributes, a list of initial values of inherited attributes, a pattern function, and a term to traverse.
traverse_m/5A monadic variant of traverse/4.
tuple_traversal/0This pattern function looks at the input tree and produces the corresponding term pattern, inserting placeholders for any non-simple subterms.
unfold/4The monadic unfold function.
unfold_gen/3Equivalent to unfold(monad_gen(), AttrFuns, Pattern, InAttrs).
unfold_pure/3Equivalent to unfold(monad_id(), AttrFuns, Pattern, InAttrs).

Function Details

compute/2

compute(Attrs, T) -> any()

Equivalent to compute(Attrs, tuple_traversal(), [], T).

compute/3

compute(Attrs, In, T) -> any()

Equivalent to compute(Attrs, Pat, [], T) or compute(Attrs, tuple_traversal(), In, T) depending on the type of the second argument, which may either be a pattern function or a list of initial values.

compute/4

compute(Attrs, Pat, In, T) -> any()

This function is a wrapper around the traverse/4 function. It returns only the result of the first synthesized attribute, instead of all synthesized attributes.

compute_gen/3

compute_gen(Attrs, Pattern, In) -> any()

Equivalent to compute_m(mondad_gen(), Attrs, Pattern, In).

compute_m/4

compute_m(Monad, Attrs, Pattern, In) -> any()

A wrapper around the unfold/4 function. It returns only the result of the first synthesized attribute, instead of all synthesized attributes.

compute_pure/3

compute_pure(Attrs, Pattern, In) -> any()

Equivalent to compute_m(mondad_id(), Attrs, Pattern, In).

global/1

global(Name) -> any()

This function declares a constant inherited attribute. The value of the attribute can be given as an argument to the traverse/4 function. Alternatively, the global/2 function can be used to initialise the attribute immediately.

global/2

global(Name, Val) -> any()

A constant inherited attribute with a given value.

monad_gen/0

monad_gen() -> any()

The eqc_gen generator monad.

monad_id/0

monad_id() -> any()

The identity monad.

rename/2

rename(Name, A) -> any()

Rename an existing attribute to another given attribute.

term/0

term() -> any()

The identity attribute which simply returns the traversed term.

term_traversal/0

term_traversal() -> any()

A pattern function that adds a placeholder for every subterm.

traverse/2

traverse(Attrs, T) -> any()

Equivalent to traverse(Attrs, tuple_traversal(), [], T).

traverse/3

traverse(Attrs, Pat, T) -> any()

Equivalent to traverse(Attrs, Pat, [], T) or traverse(Attrs, tuple_traversal(), In, T) depending on the type of the second argument, which may either be a pattern function or a list of initial values.

traverse/4

traverse(Attrs, Pattern, In, T) -> any()

This function takes a list of attributes, a list of initial values of inherited attributes, a pattern function, and a term to traverse. The return value is the values of the synthesized attributes (in a tuple, if more than one).

traverse_m/5

traverse_m(Monad, Attrs, Pattern, In, T) -> any()

A monadic variant of traverse/4.

tuple_traversal/0

tuple_traversal() -> any()

This pattern function looks at the input tree and produces the corresponding term pattern, inserting placeholders for any non-simple subterms. A term is considered simple if it is either a literal or a list of simple terms. This pattern function is useful in the majority of cases, but for the cases when it is not there is a traverse/4 function that takes the pattern function as an argument.

unfold/4

unfold(Monad, Attrs, Pattern, In) -> any()

The monadic unfold function. It takes a monad, a list of attributes, a pattern function, and a list of initial values as argument.

unfold_gen/3

unfold_gen(AttrFuns, Pattern, InAttrs) -> any()

Equivalent to unfold(monad_gen(), AttrFuns, Pattern, InAttrs).

unfold_pure/3

unfold_pure(AttrFuns, Pattern, InAttrs) -> any()

Equivalent to unfold(monad_id(), AttrFuns, Pattern, InAttrs).


Generated by EDoc, Sep 2 2015, 11:03:37.