IMPRAL is a command parsing and evaluation library for a LISP-ish dialect, intended for reasonably ergonomic and specialized command-line input within larger applications, games and frameworks.
A work-in-progress guide to the language itself, is included in the crate documentation; see [crate::guide]/https://docs.rs/impral/latest/impral/guide/index.html.
NOTICE:
Currently incomplete/still in development. Expect breaking changes.
Do not use in production code.
A very basic overview:
- Basic language similar to LISP/Scheme.
- Mostly safe
and panic-freeparser. - Conversion to an AST happens only once.
- AST is linearized; no tree visitor here!
- A small-ish set of literal types...
_null- Booleans (
true/false) - Characters
- Integers and floats (both 64-bit)
- Strings (compact at & below 24 bytes)
- Quoteless strings (barewords)!
Byte-Arrays- UUID's, prefixed with
U.
- Data structures:
- Lists (eg:
[ 1, 2, 3 ], commas optional) - Dicts (eg:
{ a=1, b=2, c=3 }, commas optional) - Radix number lists (
0x[C0 +FF -EE])
- Lists (eg:
- References!
- Result reference:
$ - Context reference:
$$ - Local references:
$my-ref - Global references:
@my-ref
- Result reference:
- Operators!
- Arithmetic (
+ - * / **) - Equality (
== != < > <= >=) - Misc. (
? ! ~ ^ ++ --)
- Arithmetic (
- Fields and indices!
- Named fields:
_.name - Indexed fields:
_.[index]
- Named fields:
- Ranges!
- Any two expressions, that are not themselves ranges, separated by two dots.
- Optional 'last-inclusive' flag can be set by adding a
=after the dots. - i.e.:
_ .. _and_ ..= _
- Pipes!
- First expression is the source
- Expressions separated by
| - Filters:
… |? bar | … - Folding:
… |! 0 min $ $acc | … - Collecting:
… |! - Chaining!
… | … |? … | …
- Fallible operations!
- Any expression followed by
?gets unwrapped to the default value. - Any expression followed by
?!will throw an error.
- Any expression followed by
- Conditional operations!
A && B:Bonly runs ifAsucceeds.A || B:Bonly runs ifAfails.
- Positional parameters:
foo _ _ - Named parameters:
foo bar=_ baz=_ - Subexpressions, enclosed by
(…) - Pratt/Infix expressions, via
= … - ...and other small things!
- Validation
- Interpreter