titus.pfaast.Foreach

class titus.pfaast.Foreach(name, array, body, seq, pos=None)[source]

Bases: titus.pfaast.Expression

Abstract syntax tree for a foreach loop.

class Context(retType, calls, symbols, objType, objExpr, itemType, name, loopBody)

Bases: titus.pfaast.ExpressionContext

__init__(retType, calls, symbols, objType, objExpr, itemType, name, loopBody)
Foreach.__init__(name, array, body, seq, pos=None)
Foreach.collect(pf)

Walk over tree applying a partial function, returning a list of results in its domain.

Parameters:
  • pf (callable with isDefinedAt method) – partial function that takes any titus.pfaast.Ast as an argument, returning anything
  • pf.isDefinedAt (callable) – domain that takes any titus.pfaast.Ast as an argument, returning True if this item is in the domain, False otherwise
Return type:

list of function results

Returns:

a result for each abstract syntax tree node in the pf function’s domain

Foreach.desc = 'foreach'
Foreach.jsonNode(lineNumbers, memo)

Convert this abstract syntax tree to Pythonized JSON.

Parameters:
  • lineNumbers (bool) – if True, include locator marks in each JSON object
  • memo (set of string) – used to avoid recursion; provide an empty set if unsure
Return type:

Pythonized JSON

Returns:

JSON representation

Foreach.replace(pf)

Walk over tree applying a partial function, returning a transformed copy of the tree.

Parameters:
  • pf (callable with isDefinedAt method) – partial function that takes any titus.pfaast.Ast as an argument, returning a replacement titus.pfaast.Ast
  • pf.isDefinedAt (callable) – domain that takes any titus.pfaast.Ast as an argument, returning True if this item is in the domain, False otherwise
Return type:

new titus.pfaast.Ast tree

Returns:

tree with nodes in the pf function’s domain transformed; everything else left as-is

Foreach.walk(task, symbolTable, functionTable, engineOptions, version)

Walk over tree applying a titus.pfaast.Task while checking for semantic errors.

This is how Python is generated from an abstract syntax tree: the titus.pfaast.Task in that case is titus.genpy.GeneratePython.

Parameters:
Return type:

(titus.pfaast.AstContext, titus.pfaast.TaskResult)

Returns:

(information about this abstract syntax tree node after type-checking, result of the generic task)