Skip to main content

A minimal DSL for Python

Project description

A minimal DSL for Python

https://travis-ci.org/fcurella/minilanguage.svg

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(context)
parser.build()

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

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

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

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

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

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

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

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

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

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

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

parser.evaluate("user.username")
# 'regular_user'

parser.evaluate("user.data_bag.payload")
# 'abc'

License

This software is released under the MIT License.

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

minilanguage-0.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

minilanguage-0.0.1-py2.py3-none-any.whl (5.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file minilanguage-0.0.1.tar.gz.

File metadata

File hashes

Hashes for minilanguage-0.0.1.tar.gz
Algorithm Hash digest
SHA256 becc17412553c4957098cebff2590cdd294ea7df0dd3f2fa49c71096af1ca7f1
MD5 7bcf60fc0479a861e79bef538ee76863
BLAKE2b-256 85f5f3153554cf2a31002b2b94ce2f8f4d5f5f47401fe8b5c0ac366d2e40bf14

See more details on using hashes here.

Provenance

File details

Details for the file minilanguage-0.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for minilanguage-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b97481ffd0290f0c68aeff727201b49a069fd931d2a907c4699ec981c8ff75a9
MD5 870928a87ed147869d70682d086fbd69
BLAKE2b-256 c1cd771aa57b39082cfdd8f7d944cc58d3bc7f775a8c1ed68858fbbf998ad548

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page