diffpy.srfit.equation.visitors package
Submodules
diffpy.srfit.equation.visitors.argfinder module
Visitor for extracting the Argument entries in a Literal tree.
ArgFinder extracts all Arguments from a literal true.
diffpy.srfit.equation.visitors.printer module
Printer visitor for printing the equation represented by a Literal tree.
The Printer visitor creates a one-line representation of the Literal tree, which is valid as a string equivalent of the equation.
- class diffpy.srfit.equation.visitors.printer.Printer[source]
Bases:
Visitor
Printer for printing a Literal tree.
Attributes:
- eqskip
regular expression pattern for Equation objects that should not be expanded, but printed under their own name. Expand all equations when None.
- output
The output generated by the printer.
- property eqskip
Pattern for equation objects to be skipped.
Expand all equations when None.
diffpy.srfit.equation.visitors.swapper module
Swapper for replacing a Literal in an equation with another Literals.
- class diffpy.srfit.equation.visitors.swapper.Swapper(oldlit, newlit)[source]
Bases:
Visitor
Swapper for swapping out one literal for another in a literal tree.
Note that this cannot swap out a root node of a literal tree. This case must be tested for explicitly.
- newlit
The literal to be placed into the literal tree.
- oldlit
The literal to be replaced.
- onArgument(arg)[source]
Process an Argument node.
Tell the parent to swap the old Argument with the replacement Literal.
diffpy.srfit.equation.visitors.validator module
Validator visitor for validating a tree of Literals.
The Validator walks an equation tree composed of Literals and checks the validity of each equation as much as possible without evaluating it. It collects errors in a list.
The Validator checks that the input count of each Operator is equal to the output count of its arguments. It also checks that each object has the proper interface.
- class diffpy.srfit.equation.visitors.validator.Validator[source]
Bases:
Visitor
Validator error for checking validity of an equation tree.
- errors
List of strings describing errors.
- _nin
Variable for counting the number input arguments for an operator.
- onArgument(arg)[source]
Process an Argument node.
The Argument must be an instance of ArgumentABC from diffpy.srfit.equation.literals.abcs
diffpy.srfit.equation.visitors.visitor module
Base visitor class.
Visitors work with Literal trees to perform a specified action. They are designed according to the visitor pattern ( http://en.wikipedia.org/wiki/Visitor_pattern).
Visitors work with the following Literal classes (diffpy.srfit.equation.literals): Argument Operator
See the Visitor class for the required methods that each Visitor must overload.
- class diffpy.srfit.equation.visitors.visitor.Visitor[source]
Bases:
object
Abstract class for all visitors to a Literal tree.
See implemented visitors for examples of use.
Module contents
Visitors that perform on Literal networks.
Visitors are designed to traverse and extract information from Literal networks (diffpy.srfit.equation.literals). Visitors are used to validate, print and extracting Arguments from Literal networks.
The Literal-Visitor relationship is that described by the Visitor pattern (
http://en.wikipedia.org/wiki/Visitor_pattern).
- diffpy.srfit.equation.visitors.getArgs(literal, getconsts=True)[source]
Get the Arguments of a Literal tree.
- diffpy.srfit.equation.visitors.getconsts
If True (default), then Arguments designated as constant are also retrieved.
- Returns a list of Arguments searched for depth-first.
- diffpy.srfit.equation.visitors.getExpression(literal, eqskip=None)[source]
Get math expression string from the Literal tree object.
- diffpy.srfit.equation.visitors.eqskip
regular expression pattern for Equation objects that should be printed under their own name. Expand all Equation objects when None.
- Return string.