gavo.stc.stcsast module

Transformation of STC-S CSTs to STC ASTs.

The central function here is buildTree; the rest of the module basically provides the handler functions. All this is tied together in parseSTCS.

class gavo.stc.stcsast.GenericContext(**kwargs)[source]

Bases: object

is an object that can be used for context.

It simply exposes all its constructor arguments as attributes.

gavo.stc.stcsast.buildTree(tree, context, pathFunctions={}, nameFunctions={}, typeFunctions={})[source]

traverses tree, calling functions on nodes.

pathFunctions is a dictionary mapping complete paths (i.e., tuples of node labels) to handler functions, nameFunctions name a single label and are called for nodes that don’t match a pathFunction if the last item of their paths is the label. Both of these currently are not used. Instead, everything hinges on the fallback, which is a node’s type value (generated from the key words), matched against typeFunctions.

The handler functions must be iterators. If they yield anything, it must be key-value pairs.

All key-value pairs are collected in a dictionary that is then returned. If value is a tuple, it is appended to the current value for the key.

Context is an arbitrary object containing ancillary information for building nodes. What’s in there and what’s not is up to the functions and their callers.

gavo.stc.stcsast.getCoordSys(cst)[source]

returns constructor arguments for a CoordSys from an STC-S CST.

gavo.stc.stcsast.getCoords(cst, system)[source]

returns an argument dict for constructing STCSpecs for plain coordinates.

gavo.stc.stcsast.iterVectors(values, dim, spatial)[source]

iterates over dim-dimensional vectors made of values.

The function does not check if the last vector is actually complete.

gavo.stc.stcsast.parseQSTCS(literal)[source]

returns an STC AST for an STC-S expression with identifiers instead of values.

The identifiers are denoted in double-quoted strings. Legal identifiers follow the python syntax (i.e., these are not SQL quoted identifiers).

gavo.stc.stcsast.parseSTCS(literal, grammarFactory=None)[source]

returns an STC AST for an STC-S expression.