Package: are
Library for defining and working with abstract regular expressions that support strings/sequences with elements of any symbol type, with an emphasis on supporting scenarios in which it is necessary to work with regular expressions as abstract mathematical objects.PurposeThis library provides classes that enable concise construction of abstract regular expressions. In the case of this library, the termabstractrefers to the fact that the symbols that constitute the abstractstrings(i.e., iterable sequences) that satisfy an abstract regular expression can be values or objects of any immutable type. Thus, this library also makes it possible to determine whether an iterable containing zero or more objects satisfies a given abstract regular expression. Any abstract regular expression can also be converted into a nondeterministic finite automaton (as implemented withinanother package) that accepts exactly those iterables which satisfy that abstract regular expression.Installation and UsageThis library is available as apackage on PyPI:python -m pip install areThe library can be imported in the usual way:import are
from are import *ExamplesThis library makes it possible to construct abstract regular expressions (represented as instances of theareclass) that work with a chosen symbol type. In the example below, a regular expression is defined (using the literal operatorlitand concatenation operatorcon) in which symbols are integers. It is then applied to an iterable of integers. This returns the iterable’s length (as an integer) if that iterable satisfies the abstract regular expression:>>> from are import *
>>> a = con(lit(1), con(lit(2), lit(3)))
>>> a([1, 2, 3])
3If the longest prefix of an iterable that satisfies an abstract regular expression is desired, thefullparameter can be set toFalse:>>> a([1, 2, 3, 4, 5], full=False)
3Operators for alternation and repetition of abstract regular expressions are also available:>>> a = rep(con(lit(1), lit(2)))
>>> a([1, 2, 1, 2, 1, 2])
6
>>> a = alt(rep(lit(2)), rep(lit(3)))
>>> a([2, 2, 2, 2, 2])
5
>>> a([3, 3, 3, 3])
4Theempconstructor can be used to create an abstract regular expression that is satisfied by the empty iterable:>>> a = emp()
>>> a([])
0Thenulconstructor can be used to create an abstract regular expression that cannot be satisfied:>>> a = nul()
>>> a([]) is None
True
>>> a([1, 2, 3]) is None
TrueAn abstract regular expression that has only string symbols can be converted into a regular expression string that is compatible with the built-inrelibrary:>>> a = alt(lit('x'), rep(lit('y')))
>>> r = a.to_re()
>>> r
'(((x)*)|((y)*))'
>>> import re
>>> r = re.compile(a.to_re())
>>> r.fullmatch('yyy')
<re.Match object; span=(0, 3), match='yyy'>An abstract regular expression can also be converted into an NFA representation (as implemented within thePyPIpackage):>>> a = con(lit(1), con(lit(2), lit(3)))
>>> a.to_nfa()
nfa({1: nfa({2: nfa({3: nfa()})})})DevelopmentAll installation and development dependencies are fully specified inpyproject.toml. Theproject.optional-dependenciesobject is used tospecify optional requirementsfor various development tasks. This makes it possible to specify additional options (such asdocs,lint, and so on) when performing installation usingpip:python -m pip install .[docs,lint]DocumentationThe documentation can be generated automatically from the source files usingSphinx:python -m pip install .[docs]
cd docs
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make htmlTesting and ConventionsAll unit tests are executed and their coverage is measured when usingpytest(see thepyproject.tomlfile for configuration details):python -m pip install .[test]
python -m pytestThe subset of the unit tests included in the module itself can be executed usingdoctest:python src/are/are.py -vStyle conventions are enforced usingPylint:python -m pip install .[lint]
python -m pylint src/are test/test_are.pyContributionsIn order to contribute to the source code, open an issue or submit a pull request on theGitHub pagefor this library.VersioningBeginning with version 0.1.0, the version number format for this library and the changes to the library associated with version number increments conform withSemantic Versioning 2.0.0.PublishingThis library can be published as apackage on PyPIby a package maintainer. First, install the dependencies required for packaging and publishing:python -m pip install .[publish]Ensure that the correct version number appears inpyproject.toml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has anautomation rulethat activates and sets as the default all tagged versions. Create and push a tag for this version (replacing?.?.?with the version number):git tag ?.?.?
git push origin ?.?.?Remove any old build/distribution files. Then, package the source into a distribution archive:rm -rf build dist src/*.egg-info
python -m build --sdist --wheel .Finally, upload the package distribution archive toPyPI:python -m twine upload dist/*