S-expressions¶
Locations¶
-
class
binflakes.sexpr.location.TextLocationRange(filename, start_line, start_column, end_line, end_column)[source]¶ Bases:
objectRepresents a range of locations in one input file, with both endpoints included.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.location.TextLocationSingle(filename, line, column)[source]¶ Bases:
objectRepresents a single (filename, line, column) location in the input.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__sub__(other)[source]¶ Returns a TextLocationRange corresponding to the range starting from the first single location (included) until the second single location (excluded).
-
__weakref__¶ list of weak references to the object (if defined)
-
Strings¶
Symbols¶
-
class
binflakes.sexpr.symbol.Symbol(name)[source]¶ Bases:
objectRepresents an S-expression symbol.
-
__delattr__(name)¶ Attached to frozen classes as __delattr__.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setattr__(name, value)¶ Attached to frozen classes as __setattr__.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
Nodes¶
-
class
binflakes.sexpr.nodes.AlternativesNode[source]¶ Bases:
objectA base for making node pseudo-classes that, when “created”, match the passed value to one of a given list of node subclasses and call the constructor of the matching one, if any.
If all involved node types are already defined on subclass creation, the list of supported node types can be set through the
alternativesclass attribute:class MyAlternativesNode(AlternativesNode): alternatives = [ MyNode, AnotherNode, ]
If one of the node types isn’t yet defined when a subclass is constructed, the node types can be set later through the
set_alternativesclass method:class MyAlternativesNode(AlternativesNode): pass class MyNode(...): ... MyAlternativesNode.set_alternatives([ MyNode, AnotherNode, ])
The alternatives specified must be mutually exclusive, as follows:
- There must be at most one alternative for each atom type.
- There must be at most one of the following:
- A ListNode subtype.
- Any number of FormNode subtypes, with distinct symbols.
- If any AlternativeNode subclass is specified in alternatives, it’s as if all alternatives of that class were specified directly in its place.
-
__weakref__¶ list of weak references to the object (if defined)
-
class
binflakes.sexpr.nodes.ArrayNode(value, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.AtomNodeRepresents an array S-expression.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
value_type¶ alias of
BinArray
-
-
class
binflakes.sexpr.nodes.AtomNode(value, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.NodeRepresents a parsed atomic S-expression node (i.e. anything but a list). Abstract base class. Subclasses need to define
value_typeclass attribute. No new direct subclasses should be defined by the user (all types need direct support from the base machinery), but the derived types can be arbitrarily subclassed further for extra methods.-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.nodes.BoolNode(value, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.AtomNodeRepresents a bool S-expression.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
value_type¶ alias of
bool
-
-
exception
binflakes.sexpr.nodes.ConvertError[source]¶ Bases:
ExceptionRaised by Node subclass constructors when given value cannot be represented as an instance of a given class.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.nodes.FormNode(value=NOTHING, location=None, symbol_location=None, **kwargs)[source]¶ Bases:
binflakes.sexpr.nodes.NodeAn abstract base class for form nodes. Final subclasses need to set a
symbolclass attribute, define zero or more form arguments, and call the@form_nodedecorator on the class.Constructs a FormNode instance from a value and location (where value is a list node, or a plain list), or directly from argument values:
AbcNode([Symbol('abc'), 123, 'def'], TextLocationRange(...)) AbcNode(my_arg=123, my_other_arg='def', location=...)
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__init__(value=NOTHING, location=None, symbol_location=None, **kwargs)[source]¶ Constructs a FormNode instance from a value and location (where value is a list node, or a plain list), or directly from argument values:
AbcNode([Symbol('abc'), 123, 'def'], TextLocationRange(...)) AbcNode(my_arg=123, my_other_arg='def', location=...)
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.nodes.GenericListNode(value, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.ListNodeRepresents a generic list S-expression – items can be of any generic node type.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
item_type¶ alias of
GenericNode
-
-
class
binflakes.sexpr.nodes.GenericNode[source]¶ Bases:
binflakes.sexpr.nodes.AlternativesNodeA node pseudo-type representing any of the generic node types.
-
class
binflakes.sexpr.nodes.IntNode(value, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.AtomNodeRepresents an int S-expression.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
value_type¶ alias of
BinInt
-
-
class
binflakes.sexpr.nodes.ListNode(value, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.NodeRepresents a uniform list S-expression. Abstract base class – should be subclassed with
item_typeclass attribute set to the type of list items.-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.nodes.NilNode(value=None, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.AtomNodeRepresents a nil S-expression.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.nodes.Node(value, location=None)[source]¶ Bases:
objectRepresents a parsed S-expression node. Abstract base class. There are four immediately derived classes:
AtomNode: represents atomic value nodes (everything except lists).ListNode: represents lists of values of uniform type.FormNode: represents forms – compound nodes represented in S-expression files by a list starting from a preset symbol and followed by pre-defined arguments of possibly non-uniform types.AlternativesNode: a pseudo-class representing an alternative of several disjoint node types. Cannot be instantiated – when constructor is called, the value is matched to one of the contained node type and an instance of the found type is returned instead.
This module provides a base class for every supported atom type, as well as a generic list type and alternatives type. These classes can be used to represent any S-expression and are returned by the reader. To create an S-expression based language, one can create a hierarchy of custom node subclasses and call the top node constructor on the generic tree returned by the reader – it will be resursively converted to the custom node set.
Converts a value to an instance of this class, recursively converting subnodes as necessary. The input value can be another compatible Node instance, or a bare Python value of the corresponding type.
Can be used to convert a bare Python value to a node tree, a generic node tree to a specific node tree, or a specific node tree back to a generic node tree.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__init__(value, location=None)[source]¶ Converts a value to an instance of this class, recursively converting subnodes as necessary. The input value can be another compatible Node instance, or a bare Python value of the corresponding type.
Can be used to convert a bare Python value to a node tree, a generic node tree to a specific node tree, or a specific node tree back to a generic node tree.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
class
binflakes.sexpr.nodes.StringNode(value, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.AtomNodeRepresents a string S-expression.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
value_type¶ alias of
str
-
-
class
binflakes.sexpr.nodes.SymbolNode(value, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.AtomNodeRepresents a symbol S-expression.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
value_type¶ alias of
Symbol
-
-
class
binflakes.sexpr.nodes.WordNode(value, location=None)[source]¶ Bases:
binflakes.sexpr.nodes.AtomNodeRepresents a word S-expression.
-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
value_type¶ alias of
BinWord
-
-
binflakes.sexpr.nodes.form_arg(arg_type)[source]¶ Defines a required form argument of a given node type.
-
binflakes.sexpr.nodes.form_node(cls)[source]¶ A class decorator to finalize fully derived FormNode subclasses.
-
binflakes.sexpr.nodes.form_optional_arg(arg_type)[source]¶ Defines an optional form argument of a given node type. If not passed, it is set to None. All optional arguments must come after all required arguments.
-
binflakes.sexpr.nodes.form_rest_arg(arg_type)[source]¶ Defines a
restform argument. All form arguments not consumed by required and optional arguments will be converted to the given node type and gathered into a tuple. There can be at most one rest argument and it must be the last defined form argument.
Reader¶
-
exception
binflakes.sexpr.read.ReadError[source]¶ Bases:
ExceptionAn exception class used for all problems noticed by the reader.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.read.Reader(filename)[source]¶ Bases:
objectA class for reading S-expressions and converting them to a node tree. Accepts the input line-by-line, yielding top-level S-expressions as they are recognized.
Initializes internal state.
filenameaffects only the location tags that will be attached to nodes.-
__init__(filename)[source]¶ Initializes internal state.
filenameaffects only the location tags that will be attached to nodes.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.read.StackEntryComment(start)[source]¶ Bases:
objectA reader stack entry representing a commented-out S-expression currently being parsed.
startis the location of the opening comment sign.-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.read.StackEntryList(start, items)[source]¶ Bases:
objectA reader stack entry representing a list currently being parsed.
itemsare the items parsed so far,startis the location of the opening paren.-
__ge__(other)¶ Automatically created by attrs.
-
__getstate__()¶ Automatically created by attrs.
-
__gt__(other)¶ Automatically created by attrs.
-
__le__(other)¶ Automatically created by attrs.
-
__lt__(other)¶ Automatically created by attrs.
-
__ne__(other)¶ Check equality and either forward a NotImplemented or return the result negated.
-
__repr__()¶ Automatically created by attrs.
-
__setstate__(state)¶ Automatically created by attrs.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
binflakes.sexpr.read.State[source]¶ Bases:
enum.EnumRepresents the reader state (between tokens, inside a string token, inside a BinArray token.