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("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("user.data_bag.payload", context) # 'abc'
License
This software is released under the MIT License.
Project details
Release history Release notifications | RSS feed
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.1.0.tar.gz
(4.6 kB
view details)
Built Distribution
File details
Details for the file minilanguage-0.1.0.tar.gz
.
File metadata
- Download URL: minilanguage-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 635a455dda65b7b1520c41fb3d680ce18f2468752f33b5bce06733bc6b32d9cc |
|
MD5 | 1e3965abcf3e88d5f0f92891fe9c53e2 |
|
BLAKE2b-256 | 0f8677a40b16c83160f64653fe94b3ed0e1341ff67cc3eb3957d1cb2158bb1c7 |
Provenance
File details
Details for the file minilanguage-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: minilanguage-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73424b442c2d9fb2d947ae0ee509c6f389e158a16232fa1321c179693dc5c104 |
|
MD5 | 8a41d9cf02c9a1f161eb609463e97aa5 |
|
BLAKE2b-256 | d0d02be0d95248e250ecc1af2939ba855ddc553e6c74c0f9ca661d9622889e71 |