gavo.adql.bindinggrammar module

Helpers for making the definition of grammars of the complexity of our ADQL grammar a bit easier.

Here, we define the AutoBindingGrammar, which is used in adql.grammar to build a grammar with parseActions defined in adql.nodes, where the node classes say which symbols they are responsible for.

class gavo.adql.bindinggrammar.AutoBindingGrammar(binders)[source]

Bases: object

A container for pyparsing symbols that receive their parse actions from a sequence of “binders”

The binders are passed into the constructor. Most of these will be derived from nodes.ADQLNode; but they can also be callables with parseActionFor set (see the nodes.symbolAction decorator). Making this more generic would take quite a bit of extra thought. Anyway, what I’m looking at here on whatever is in nodes:

  • type: a name of a symbol that should have nodeClass.fromParseResult as a parse action.

  • bindings: as type, but a list of symbol names; when bindings is present, type is ignored.

  • parseActionFor: that’s a list of symbol names the “node” (which more likely is just some function) must be called for as a parse action.

  • collapsible: if set on a node class, the parse action will be nodes.autocollapse (that’s for transparent nodes I’m eliding out of the tree unless they’re more than just a single token).

bind_(symName, nodeClass)[source]

enters nodeClass as a handler for symName.

This also deals with autocollapsining single nodes.

getSymbols_()[source]

returns a dict of all symbols defined.

class gavo.adql.bindinggrammar.SingleBindingDict[source]

Bases: dict

A dictionary that lets you assign each key just once.