Built-in functions, types, exceptions, and other objects.
Project description
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.
Installing
$ pip install tag-expressions
Here is a tease
>>> 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) == False
Usage
Available operators
or - “or” conjunction of two given variables
and - “and” conjunction of two given variables
not - negation of a single variable
Every other token given in an infix is considered a variable.
Operator precedence
From high to low:
()
or
and
not
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tag-expressions-2.0.0.tar.gz
(6.1 kB
view details)
Built Distribution
File details
Details for the file tag-expressions-2.0.0.tar.gz
.
File metadata
- Download URL: tag-expressions-2.0.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffa626ef68e58157697a5e15d96d9a08a36d2120d3f72e6acfbfa04e5954b8f8 |
|
MD5 | 894c2f4a267b59baf04589f99062c8bc |
|
BLAKE2b-256 | e4208395065c523ce9f6030d93c1c7f564e684b2c3d0098cb34ee49160ee9332 |
File details
Details for the file tag_expressions-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: tag_expressions-2.0.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87f04c141f14ee70ec2cfa8a16409acf5e1e0e5cfed859c68533803343eb1eb9 |
|
MD5 | 35737dea11eb365e4ca581a6cd9837af |
|
BLAKE2b-256 | d7008900a6569172a4c177f4449725c5e149fa9140c757f760bcedfb3ff24c36 |