gavo.stc.stcs module¶
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:
After flavor, you can add an epoch using something like “Epoch J2000.0”.
- After the FK5, FK4 and ECLIPTIC frame specs, you can add an optional
astroYear (Bnnnn, Jnnnn) designating a custom equinox.
- There is a system subphrase that lets you specify a system from the
STC library (without the ivo:// decoration). It starts with System and is specified last. It will override all other system specifications.
- If enabled, you can use identifiers in double quotes wherever values
are allowed; this will generate column references.
- After the reference position, you can optionally mention the planetary
ephemeris used; currently, only JPL-DE200 and JPL-DE405 are allowed.
- gavo.stc.stcs.addDefaults(tree)[source]¶
adds defaults for missing values for a concrete syntax tree.
The tree is changed in place. For details, see stcsdefaults.
- gavo.stc.stcs.getCST(literal, grammarFactory=None)[source]¶
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.
- gavo.stc.stcs.getColrefSymbols()[source]¶
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.
- gavo.stc.stcs.getSymbols(_exportAll=False, _colrefLiteral=None, _addGeoReferences=False)[source]¶
returns an STC-S grammar with terminal values.
- gavo.stc.stcs.iterNodes(tree)[source]¶
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.
- gavo.stc.stcs.makeTree(parseResult)[source]¶
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.