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.

class diffpy.srfit.equation.visitors.argfinder.ArgFinder(getconsts=True)[source]

Bases: Visitor

ArgFinder extracts Arguments from a Literal tree.

args

The list of collected Arguments

getconsts

Flag indicating whether to grab constant arguments.

onArgument(arg)[source]

Process an Argument node.

onOperator(op)[source]

Process an Operator node.

reset()[source]

Reset the argument set.

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.

onArgument(arg)[source]

Process an Argument node.

No assumption is made about the argument type.

onEquation(eq)[source]

Process an Equation node.

onOperator(op)[source]

Process an Operator node.

reset()[source]

Reset the out put string.

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.

onEquation(eq)[source]

Process an Equation node.

This looks at the equation itself as well as the root.

onOperator(op)[source]

Process an Operator node.

Tell the parent to swap the old Operator 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

onOperator(op)[source]

Process an Operator node.

The Operator must be an instance of OperatorABC from diffpy.srfit.equation.literals.abcs

reset()[source]

Click the clicker and reset non-public data.

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.

onArgument(arg)[source]

Process an Argument node.

onEquation(eq)[source]

Process an Equation node.

Equations are specialized Operators. They don’t need to be specifically supported by a Visitor.

onOperator(op)[source]

Process an Operator node.

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.
diffpy.srfit.equation.visitors.prettyPrint(literal)[source]

Print a Literal tree.

diffpy.srfit.equation.visitors.swap(literal, oldlit, newlit)[source]

Swap one literal for another in a Literal tree.

Corrections are done in-place unless literal is oldlit, in which case the return value is newlit.

Returns the literal tree with oldlit swapped for newlit.

diffpy.srfit.equation.visitors.validate(literal)[source]

Validate a Literal tree.

Raises ValueError if the tree contains errors.