Package gavo :: Package stc :: Module stcxast
[frames] | no frames]

Module stcxast

source code

Building ASTs from STC-X trees.

The idea here is run buildTree on an ElementTree of the STC-X input.

buildTree has a dictionary mapping element names to handlers. This dictionary is built with a modicum of metaprogramming within _getHandlers.

Each handler receives the ElementTree node it is to operate on, the current buildArgs (i.e., a dictionary containing for building instances collected by buildTree while walking the tree), and a context object.

Handlers yield keyword-value pairs that are added to the buildArgs. If the value is a tuple or list, it will be appended to the current value for that keyword, otherwise it will fill this keyword. Overwrites are not allowed.

Classes
  SIBLING_ASTRO_SYSTEM
A sentinel class to tell the id resolver to use the sibling AstroCoordSys element.
  ContextActions
A specification of context actions for certain elements.
  CooSysActions
Actions for containers of coordinates.
  BoxActions
Context actions for Boxes: register a special handler for Size.
  IdProxy
A stand-in for a coordinate system during parsing.
  STCXContext
A parse context containing handlers, stacks, etc.
Functions
 
STCElement(name) source code
 
resolveProxies(forest)
replaces IdProxies in the AST sequence forest with actual references.
source code
 
getVecTags()
returns a mapping from STC-X names to the number of dimensions child vectors should have.
source code
 
buildTree(csNode, context)
traverses the ElementTree cst, trying handler functions for each node.
source code
 
parseFromETree(eTree)
returns a sequence of pairs (root element, AST) for eTree containing parsed STC-X.
source code
 
parseSTCX(stcxLiteral)
returns a sequence of pairs (root element, AST) for the STC-X specifications in stcxLiteral.
source code
Variables
  WIGGLE_TYPES = ['error', 'resolution', 'size', 'pixSize']
  getHandlers = <gavo.utils.codetricks.CachedGetter object>
  getActiveTags = <gavo.utils.codetricks.CachedGetter object>
  __package__ = 'gavo.stc'
Function Details

buildTree(csNode, context)

source code 

traverses the ElementTree cst, trying handler functions for each node.

The handler functions are taken from the context.elementHandler dictionary that maps QNames to callables. These callables have the signature handle(STCNode, context) -> iterator, where the iterator returns key-value pairs for inclusion into the argument dictionaries for STCNodes.

Unknown nodes are simply ignored. If you need to bail out on certain nodes, raise explicit exceptions in handlers.

This also manages the expected number of dimensions in vectors by pushing and popping from the context's dimension stack. The actual wisdom on what elements set which dimensions is kept in the context object as well.