titus.pfaast.Ast

class titus.pfaast.Ast[source]

Bases: object

Abstract base class for a PFA abstract syntax tree.

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

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

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

startDict(lineNumbers)

Helper function to build a Pythonized JSON object.

Parameters:lineNumbers (bool) – if True, include the locator mark
Return type:OrderedDict
Returns:an empty Pythonized JSON object or one containing only the locator mark
toJson(lineNumbers=True)

Serialize this abstract syntax tree as a JSON string.

Parameters:lineNumbers (bool) – if True, include locator marks at the beginning of each JSON object
Return type:string
Returns:JSON string
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)