Coder Social home page Coder Social logo

timofurrer / tag-expressions Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 37 KB

Python implementation of Shunting-yard Algorithm to evaluate logical tag expressions

License: MIT License

Python 100.00%
tags expression logic bool tree parse evaluate cucumber radish bdd

tag-expressions's Introduction

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

$ 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

tag-expressions's People

Contributors

inquisitev avatar timofurrer avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

inquisitev

tag-expressions's Issues

Credentials posted in .travis.yml

user: tuxtimo
password:
secure: g5RJCfDN7ApDkp4qLYdzLMvmYMNlu5oUoEQ3BFrujTKQWuGspJKfyT9rlY9wLspcxZVVSzcy3PQ4bEDrqCG55ms5lFTtFOyAseJgYDpX5BojqVKtp8XJpshnbZn4GT9/eEMLfRdz6uCWpNbsdFtnW+Bk+jFYeYf3Qvujub6aOLllQ064riveKL++OrJDdu+kM7xWeBey5j7g4givtId3XNFWG2lMveCyu3rHNFvz7TEPVvUIUceP1gXVylCUQutbp99uZRHSn6xZEOwGVtXPurHEEB8X+2UkRZPms9eVspcKvneGnjMW1CRW0+RT0quLS6QTptjjhuQgw1M9CEzzQX4eAb7srywIVxtADCmciwjAMi01C6P0oQBufY/+H/VtJCwIu43zLQLT7uyftIIDuEYj2ezCv+XltPbEKWfKMR46hfb5NayHRlchEgZus95VFuXHgAlVzA6PEQs3zazAu322DHD6EIo0elr0CgLixSDX/w2HDFysMpa+JJ32/0BHPT1+hktdqEytH3umiCU29yhWp3k4neEobJ+9UWlK1Hvu64UZ+aSTipE3AL2G1Xi3AL5N7avBdpexE/t952MlnpE07z0hMiFbPMgzBqMRuPc0Ny153zb1AIM5XkzKDAzMUCoRtuv9Ft2eCSfF70gM/5CkQuqEdzVnw9wMNQIB/jc=

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.