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-1.1.1.tar.gz
(5.6 kB
view hashes)
Built Distribution
Close
Hashes for tag_expressions-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f75b1b0b7e5d6006db80afa23bef9835df25c177337a4f3a5673be4f51a36149 |
|
MD5 | 0e6b4b07550a6b0594e3585b7b4b94b1 |
|
BLAKE2b-256 | 629100970d123de2306f8dc60e92c7341fdecf9c52b1316247b86c3744839fba |