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

Module stcs

source code

Parsing and generating STC-S

The general plan is to parse STC-S into some sort of tree (dictionaries with list values, possibly containing more such dictionaries). These trees can then be processed into something roughly resembling the data model, furnished with defaults, and processed by what essentially is user code.

Extensions to what the note says:

Classes
  AComputedDefault
A sentinel for computed default values.
Functions
 
iterNodes(tree)
traverses the concrete syntax tree in postorder, returning pairs of paths and nodes.
source code
 
addDefaults(tree)
adds defaults for missing values for a concrete syntax tree.
source code
 
removeDefaults(tree)
removes defaults from a concrete syntax tree.
source code
 
makeTree(parseResult)
returns the pyparsing parseResult as a data structure consisting of simple python dicts and lists.
source code
 
getSymbols(_exportAll=False, _colrefLiteral=None, _addGeoReferences=False)
returns an STC-S grammar with terminal values.
source code
 
getColrefSymbols()
returns an STC-S grammar with column references as values.
source code
 
enableDebug(syms, debugNames=None) source code
 
getCST(literal, grammarFactory=None)
returns a CST for an STC-S expression.
source code
Variables
  stcsFlavors = {'CART1': (1, 'CARTESIAN'), 'CART2': (2, 'CARTES...
  spatialUnits = set(['AU', 'Mpc', 'arcmin', 'arcsec', 'deg', 'k...
  temporalUnits = set(['a', 'cy', 'd', 's', 'yr'])
  spectralUnits = set(['Angstrom', 'GHz', 'Hz', 'MHz', 'MeV', 'e...
  getGrammar = <gavo.utils.codetricks.CachedGetter object>
  getColrefGrammar = <gavo.utils.codetricks.CachedGetter object>
  __package__ = 'gavo.stc'
Function Details

iterNodes(tree)

source code 

traverses the concrete syntax tree in postorder, returning pairs of paths and nodes.

A node returned here is always a dictionary. The path consists of the keys leading to the node in a tuple.

addDefaults(tree)

source code 

adds defaults for missing values for a concrete syntax tree.

The tree is changed in place. For details, see stcsdefaults.

removeDefaults(tree)

source code 

removes defaults from a concrete syntax tree.

The tree is changed in place. For details, see stcsdefaults.

makeTree(parseResult)

source code 

returns the pyparsing parseResult as a data structure consisting of simple python dicts and lists.

The "tree" has two kinds of nodes: Dictionaries having lists as values, and lists containing (as a rule) literals or (for more deeply nested constructs, which are rare in STC-S) other dictionaries of this kind.

A parse node becomes a dict node if it has named children. The root always is a dict.

Note that unnamed children of nodes becoming dicts will be lost in the result.

getColrefSymbols()

source code 

returns an STC-S grammar with column references as values.

The column references used here have the form "<colref>" to cut down on ambiguities. We only accept simple identifiers (i.e., not quoted in the SQL sense), though.

getCST(literal, grammarFactory=None)

source code 

returns a CST for an STC-S expression.

grammarFactory is a function returning the grammar, in this case either getGrammar (which gets used if the argument is left out) or getColrefGrammar.


Variables Details

stcsFlavors

Value:
{'CART1': (1, 'CARTESIAN'),
 'CART2': (2, 'CARTESIAN'),
 'CART3': (3, 'CARTESIAN'),
 'SPHER2': (2, 'SPHERICAL'),
 'SPHER3': (3, 'SPHERICAL'),
 'UNITSPHER': (3, 'UNITSPHERE')}

spatialUnits

Value:
set(['AU',
     'Mpc',
     'arcmin',
     'arcsec',
     'deg',
     'km',
     'kpc',
     'm',
...

spectralUnits

Value:
set(['Angstrom',
     'GHz',
     'Hz',
     'MHz',
     'MeV',
     'eV',
     'keV',
     'm',
...