gavo.dm.sil module

SIL, the Simple Instance Language, is an attempt to allow data model instances written in a simple, JSON-like language.

class gavo.dm.sil.AnnotationBuilder(annotationFactory)[source]

Bases: object

A class to build the table annotation.

It is constructed with an iterator over the annotation events (from sil.iterparse), and an annotationFactory, which is a callable taking an attribute name and an attribute value, producing an Annotation instance. There, the value will be either an Atom or a Reference.

Internally, the AnnotationBuilder works with an object stack, onto which built annotations are pushed. They are taken off as annotations get built.

After construction, use the feed method to feed the parser events into the builder. When self.result becomes non-None, the Builder considers its job done and will AttributeError on further feed attempts.

feed(evType, arg1, arg2)[source]
classmethod fromSILLiteral(silLiteral, annotationFactory)[source]

builds annotation using annotationFactory from a SIL literal.

This adds a few sanity checks; fetch the annotation result (which you may not actually care about a lot) from the result’s result attribute.

class gavo.dm.sil.Atom[source]

Bases: str

a sentinel class for atomic values of roles

asSIL()[source]
noQuotesOkRE = re.compile('[\\w_.]+$')
class gavo.dm.sil.Reference[source]

Bases: str

a sentinel class for roles referencing something else.

asSIL()[source]
gavo.dm.sil.getAnnotation(silLiteral, annotationFactory)[source]

returns an annotation object parsed from silLiteral.

This is a shallow wrapper around AnnotationBuilder.fromSILLiteral, which you should probably directly use in new code.

gavo.dm.sil.getGrammar(debug=False)[source]

returns a grammar for parsing a SIL object description.

gavo.dm.sil.iterparse(silLiteral)[source]

yields parse events for a SIL literal in a string.

The parse events are triples of one of the forms:

  • (‘attr’, roleName, value) add an attribute to the current annotation; value can be a “value” (as in object, reference,…) or an Alternative instance from fallbacks.

  • (‘obj’, roleName, type) create a new object object of type

  • (‘coll’, type, None) create a new collection annotation (type can be None)

  • (‘item’, val, None) add an atomic value to the current collection

  • (‘pop’, None, None) finish current annotation and add it to its container

These events are generated from the tree that the grammar produces by logic in _parseTreeToEvents.