The standardaction module

This module defines StandardAction.

A StandardAction is a singleton object. Acessing an attribute (without underscore) creates that attribute as a new instance, with the current instance as _parent.

This way a new action type can be created that shares its parent with other types, a concept borrowed from pygments. An example:

>>> Comment = StandardAction("Comment")
>>> Literal = StandardAction("Literal")
>>> String = Literal.String
>>> String.DoubleQuotedString
Literal.String.DoubleQuotedString
>>> String.SingleQuotedString
Literal.String.SingleQuotedString

StandardAction instances support iteration and membership methods. Iteration yields the instance ifself and then the parents:

>>> for i in String.DoubleQuoted:
...     print(i)
...
Literal.String.DoubleQuoted
Literal.String
Literal

And the in operator returns True when a standard action belongs to another one, i.e. the other one is one of the ancestors of the current action:

>>> String.DoubleQuotedString in String
True
>>> Literal in String
False

The in operator also works with a string:

>>> 'String' in Literal.String.DoubleQuoted
True
>>> 'Literal' in String
True

The last one could be surprising, but String is defined as Literal.String:

>>> String
Literal.String

Finally, the & operator returns the common ancestor, if any:

>>> String & Number
Literal
>>> String & Text
>>>

See for the full list of pre-defined standard actions Standard actions.

class StandardAction[source]

Bases: object

Factory for standard action singletons.