An interpreter for a basic logic language, inspired by two-element boolean algebra.
Project description
lla
Interpreter for a basic logic language, inspired by two-element boolean algebra.
Demo
Here's a quick demo, based on the example that prompted its creation:
>>> from lla.interpreter import Interpreter
>>> variables = {
... 'ssh': True,
... 'website_up': True,
... 'search_up': False,
... 'elasticsearch.http': False,
... 'elasticsearch.process': True,
... }
>>> interpreter = Interpreter(variables)
>>> interpreter.run('ssh & website_up')
True
>>> interpreter.run('ssh & website_up & search_up')
False
>>> interpreter.run('!search_up & !elasticsearch.http & elasticsearch.process')
True
>>> interpreter.run('undefined_variable')
Traceback (most recent call last):
...
lla.interpreter.UndefinedVariableException: Undefined variable: undefined_variable
By replacing the variables dict with a class implementing __getitem__,
it becomes incredibly flexible.
Overview
Here's the gist of it:
- All variables are booleans.
- You can't define variables in the language itself, but it be provided a
dictor any object implementing__getitem__. - Only fully-resolvable statements are supported. a. Anything else raises a Python exception.
- You provide the interpreter a single statement and it gets simplified to a single boolean value, which is then returned.
Dependencies
In theory, all you need is Python 3.6+.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/duckinator/lla.
The code for lla is available 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lla-0.0.6.tar.gz.
File metadata
- Download URL: lla-0.0.6.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26ed85cb54a91e14c1c80ff72cf2f6378b09d9ccf4c3f125ebcffb862d53d886
|
|
| MD5 |
cd0715372a6bd6eef671e4b75d85ad74
|
|
| BLAKE2b-256 |
bd0bd47047cf9c1a84fbb289dd3055a9f889fb5ff7f4318c3094414d5a63e170
|
File details
Details for the file lla-0.0.6-py3-none-any.whl.
File metadata
- Download URL: lla-0.0.6-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f649fd46b934debc6b10cb798d73df40fdd8f1447fdaf362ffe987a1f032aa7
|
|
| MD5 |
7a4d2417143e82e7740fe6db4666b2f6
|
|
| BLAKE2b-256 |
9980858e5a4db380774f4472f591aba0c53b39b6ee721ea4d7134530278e7964
|