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(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
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.0.1.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file minilanguage-0.0.1.tar.gz
.
File metadata
- Download URL: minilanguage-0.0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | becc17412553c4957098cebff2590cdd294ea7df0dd3f2fa49c71096af1ca7f1 |
|
MD5 | 7bcf60fc0479a861e79bef538ee76863 |
|
BLAKE2b-256 | 85f5f3153554cf2a31002b2b94ce2f8f4d5f5f47401fe8b5c0ac366d2e40bf14 |
Provenance
File details
Details for the file minilanguage-0.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: minilanguage-0.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b97481ffd0290f0c68aeff727201b49a069fd931d2a907c4699ec981c8ff75a9 |
|
MD5 | 870928a87ed147869d70682d086fbd69 |
|
BLAKE2b-256 | c1cd771aa57b39082cfdd8f7d944cc58d3bc7f775a8c1ed68858fbbf998ad548 |