Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timofurrer/tag-expressions
Python implementation of Shunting-yard Algorithm to evaluate logical tag expressions
https://github.com/timofurrer/tag-expressions
bdd bool cucumber evaluate expression logic parse radish shunting-yard-algorithm tags tree
Last synced: 25 days ago
JSON representation
Python implementation of Shunting-yard Algorithm to evaluate logical tag expressions
- Host: GitHub
- URL: https://github.com/timofurrer/tag-expressions
- Owner: timofurrer
- License: mit
- Created: 2017-02-25T13:22:00.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-11-23T15:47:31.000Z (about 2 months ago)
- Last Synced: 2024-12-15T08:04:03.527Z (29 days ago)
- Topics: bdd, bool, cucumber, evaluate, expression, logic, parse, radish, shunting-yard-algorithm, tags, tree
- Language: Python
- Size: 39.1 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
tag-expressions
===============Package to evaluate logical tag expressions by using a modified version of the `Shunting Yard algorithm `_.
This package is a Python port of cucumbers tag expression.It's also used by `radish `_.
|Build Status| |PyPI package version| |PyPI python versions|
Installing
----------.. code:: bash
$ pip install tag-expressions
Here is a tease
---------------.. code:: python
>>> from tagexpressions import parse
>>>
>>> expression = '( a and b ) or ( c and d )'
>>> compiled_expression = parse(expression)
>>> print(compiled_expression)
( ( a and b ) or ( c and d ) )
>>>
>>> data = ['a', 'b', 'c', 'd']
>>> assert compiled_expression.evaluate(data) == True
>>>
>>> data = ['a', 'c']
>>> assert compiled_expression.evaluate(data) == False
>>>
>>>
>>> expression = 'not a or b and not c or not d or e and f'
>>> compiled_expression = parse(expression)
>>> print(compiled_expression)
( ( ( not ( a ) or ( b and not ( c ) ) ) or not ( d ) ) or ( e and f ) )
>>>
>>> data = ['b', 'e', 'f']
>>> assert compiled_expression.evaluate(data) == True
>>>
>>> data = ['a', 'c', 'd']
>>> assert compiled_expression.evaluate(data) == FalseUsage
-----Available operators
~~~~~~~~~~~~~~~~~~~* **or** - "or" conjunction of two given variables
* **and** - "and" conjunction of two given variables
* **not** - negation of a single variableEvery other token given in an *infix* is considered a variable.
Operator precedence
~~~~~~~~~~~~~~~~~~~From high to low:
* ()
* or
* and
* not.. |Build Status| image:: https://github.com/timofurrer/tag-expressions/actions/workflows/build.yml/badge.svg
:target: https://github.com/timofurrer/tag-expressions/actions/workflows/build.yml
.. |PyPI package version| image:: https://badge.fury.io/py/tag-expressions.svg
:target: https://badge.fury.io/py/tag-expressions
.. |PyPI python versions| image:: https://img.shields.io/pypi/pyversions/tag-expressions.svg
:target: https://pypi.python.org/pypi/tag-expressions