This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

A minimal DSL for Python

Project Description

A minimal DSL for Python

Minilanguage is a minimal DSL for Python written with Ply.

Is it intended to be a starting point for writing more specific DSLs.

Currently, it only implements simple boolean logic and objects/strings evaluation.

Example

from minilanguage.grammar import FeatureParser

context = {
    'country': 'US',
    'user': {
        'username': 'regular_user',
        'data_bag': {
            "payload": 'abc',
        }
    }
}

parser = FeatureParser()
parser.build()

parser.evaluate("2 + 0.5", context)
# 2.5

parser.evaluate("12 + 12", context)
# 24

parser.evaluate("12 == 12", context)
# True

parser.evaluate("12 != 12", context)
# False

parser.evaluate("12 and False", context)
# False

parser.evaluate("12 or False", context)
# 12

parser.evaluate("12 > 10", context)
# True

parser.evaluate("12 < 10", context)
# False

parser.evaluate("12 <= 12", context)
# True

parser.evaluate("12 >= 12", context)
# True

parser.evaluate("country", context)
# 'US'

parser.evaluate("country == 'US'", context)
# True

parser.evaluate("user['username']", context)
# 'regular_user'

parser.evaluate("'a', 'b'", context)
# tuple('a', 'b')

parser.evaluate("user['data_bag']['payload']", context)
# 'abc'

parser.evaluate("user.get('missing_key', 'default')", context)
# 'default'

parser.evaluate("12 if False else 14", context)
# 14

License

This software is released under the MIT License.

Release History

Release History

This version
History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

0.3.1

History Node

0.3.0

History Node

0.2.0

History Node

0.1.0

History Node

0.0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
minilanguage-1.0.3-py2.py3-none-any.whl (7.1 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Dec 24, 2015
minilanguage-1.0.3.tar.gz (5.5 kB) Copy SHA256 Checksum SHA256 Source Dec 24, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting