Small and simple expression language
Project description
# aml Accounting Mini Language — Small and simple expression language running on Python.
aml is a very small programming language running on top of Python. aml is ideal for exposing a powerful but safe interface to users who need to define business rules but have no programming knowledge. In this respect aml is an alternative to cumbersome mouse-driven rule engine configurations.
The grammar and parser utilise the [pypeg2](http://fdik.org/pyPEG/) library which must be installed for aml to work.
To use aml the programmer creates a “language instace”. Calling the compile function yields an object (essentially an AST). This object can then be evaluated directly using the evaluate function or translated to Python or SQL using the respective functions.
Since the language is very simple, sufficient documentation can be given by example:
>>> lang_instance = create_lang_instance() >>> lang_instance.aml_evaluate(lang_instance.aml_compile('1 = 1')) True >>> li = create_lang_instance() >>> c = li.aml_compile >>> e = li.aml_evaluate >>> p = li.aml_translate_python >>> s = li.aml_translate_sql >>> u = li.aml_suggest >>> e(c('1 = 0')) False >>> e(c('"1" = "1"')) True >>> e(c('(1=1)')) True >>> e(c('1 > 1')) False >>> e(c('not 1 > 1')) True >>> e(c('1 != 1')) False >>> e(c('-2 = -2')) True >>> eval(p(c('-2 = -2'))) True >>> eval(p(c('null = null'))) True >>> eval(p(c('1 = null'))) False >>> e(c('"foo" = "foo"')) True >>> e(c('"foo" = \\'foo\\'')) True >>> e(c('"fo\\'o" = "fo\\'o"')) True >>> e(c("'foo'" + '=' + '"foo"')) True >>> li = create_lang_instance({'foo' : 1}); >>> c = li.aml_compile >>> e = li.aml_evaluate >>> e(c('foo = 1')) True >>> li = create_lang_instance({'foo' : 1.00}) >>> c = li.aml_compile >>> e = li.aml_evaluate >>> e(c('foo = 1')) True >>> li = create_lang_instance({'foo' : 2.24}) >>> c = li.aml_compile >>> e = li.aml_evaluate >>> e(c('foo = 2.24')) True >>> li = create_lang_instance({'foo' : 'foo'}) >>> c = li.aml_compile >>> e = li.aml_evaluate >>> e(c('foo = "foo"')) True >>> li = create_lang_instance() >>> c = li.aml_compile >>> p = li.aml_translate_python >>> s = li.aml_translate_sql >>> s(c('null = null')) u'null is null' >>> p(c('null = null')) u'None == None' >>> s(c('null != null')) u'null is not null' >>> p(c('null != null')) u'None != None' >>> s(c('5 != 3')) u'5 <> 3' >>> p(c('5 != 3')) u'5 != 3' >>> li = create_lang_instance({'foo' : 'bar', 'fo2' : 'ba2'}) >>> c = li.aml_compile >>> p = li.aml_translate_python >>> e = li.aml_evaluate >>> u = li.aml_suggest >>> u('1 = fo') [u'fo2', u'foo'] >>> u('1 = FO') [u'fo2', u'foo'] >>> p(c('null = null')) u'None == None' >>> e(c('foo = "bar"')) True >>> e(c('fo2 = "ba2"')) True
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 Distributions
File details
Details for the file amlang-1.0.0.zip
.
File metadata
- Download URL: amlang-1.0.0.zip
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f97a298c09de398af8a1a9af58642a05c96ec691826b0ea95743de3a5fcf4ddb |
|
MD5 | 6f4d5a733add33ea31c8d95d1fe65c44 |
|
BLAKE2b-256 | 34a21ea219e8b11d45477cdf16c75de826417125c0f548b506f083afc9bd5078 |
File details
Details for the file amlang-1.0.0.tar.gz
.
File metadata
- Download URL: amlang-1.0.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff2068028ea16e7ff98f64dd5554a533e3fd1f7815b116c3b0558f24e3a65e10 |
|
MD5 | 350947099a9fc1e7b2243d43320e61b4 |
|
BLAKE2b-256 | 9f881604cfe5b094274dd1840f28ff1e28576b29ea2f98d620ce577cc0b38268 |