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("12 if False else 14", context) # 14
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.3.1.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for minilanguage-0.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cf06d56a4c3f95d13e06e645df605b91df8b5e0af091b69de95de398eddf702 |
|
MD5 | 049b34ec9b94332bbdd43482c76c01b6 |
|
BLAKE2b-256 | 0b5789e8efa28c825a31c4650bd29f1ef8506a6ed4842a04af35bdeebbda4fa2 |