Copyright © Quviq AB, 2014-2015
Version: 2.01.0
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}}}). > 3A detailed description of the attribute grammar system can be found here.
compute/2 | Equivalent to compute(Attrs, tuple_traversal(), [], T). |
compute/3 | 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 | This function is a wrapper around the traverse/4 function. |
compute_gen/3 | Equivalent to compute_m(mondad_gen(), Attrs, Pattern, In). |
compute_m/4 | A wrapper around the unfold/4 function. |
compute_pure/3 | Equivalent to compute_m(mondad_id(), Attrs, Pattern, In). |
global/1 | This function declares a constant inherited attribute. |
global/2 | A constant inherited attribute with a given value. |
monad_gen/0 | The eqc_gen generator monad. |
monad_id/0 | The identity monad. |
rename/2 | Rename an existing attribute to another given attribute. |
term/0 | The identity attribute which simply returns the traversed term. |
term_traversal/0 | A pattern function that adds a placeholder for every subterm. |
traverse/2 | Equivalent to traverse(Attrs, tuple_traversal(), [], T). |
traverse/3 | 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 | This function takes a list of attributes, a list of initial values of inherited attributes, a pattern function, and a term to traverse. |
traverse_m/5 | A monadic variant of traverse/4 . |
tuple_traversal/0 | This pattern function looks at the input tree and produces the corresponding term pattern, inserting placeholders for any non-simple subterms. |
unfold/4 | The monadic unfold function. |
unfold_gen/3 | Equivalent to unfold(monad_gen(), AttrFuns, Pattern, InAttrs). |
unfold_pure/3 | Equivalent to unfold(monad_id(), AttrFuns, Pattern, InAttrs). |
compute(Attrs, T) -> any()
Equivalent to compute(Attrs, tuple_traversal(), [], T).
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(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(Attrs, Pattern, In) -> any()
Equivalent to compute_m(mondad_gen(), Attrs, Pattern, In).
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(Attrs, Pattern, In) -> any()
Equivalent to compute_m(mondad_id(), Attrs, Pattern, In).
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(Name, Val) -> any()
A constant inherited attribute with a given value.
monad_gen() -> any()
The eqc_gen
generator monad.
monad_id() -> any()
The identity monad.
rename(Name, A) -> any()
Rename an existing attribute to another given attribute.
term() -> any()
The identity attribute which simply returns the traversed term.
term_traversal() -> any()
A pattern function that adds a placeholder for every subterm.
traverse(Attrs, T) -> any()
Equivalent to traverse(Attrs, tuple_traversal(), [], T).
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(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(Monad, Attrs, Pattern, In, T) -> any()
A monadic variant of traverse/4
.
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(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(AttrFuns, Pattern, InAttrs) -> any()
Equivalent to unfold(monad_gen(), AttrFuns, Pattern, InAttrs).
unfold_pure(AttrFuns, Pattern, InAttrs) -> any()
Equivalent to unfold(monad_id(), AttrFuns, Pattern, InAttrs).
Generated by EDoc, Sep 2 2015, 11:03:37.