zookd
An expression language that is compiled to JavaScript.
The lexer and parser are greatly inspired by CoffeeScript.
Syntax
Null
Represents null
in JavaScript.
zookd; // => null
Identifier
- Identifiers may only include the following characters: letters (
'a'..'z'
,'A'..'Z'
), digits ('0'..'9'
), underscores ('_'
) and dollar signs ('$'
). - The first character must not be a digit.
- The identifier must not be one of the keywords (such as
null
).
All the identifiers should be declared in the context.
zookdeval; // => 'bar'zookdeval; // => 42
Literal
In zookd, there are 5 types of literals: Numbers, Booleans, Strings, Lists and Maps.
Number Literal
Number literals are decimal numbers.
zookd; // => 1zookd; // => 2zookd; // => -0.5zookd; // => -0zookd; // => 0.5zookd; // => 27zookd; // => -Infinityzookd; // => 0zookd; // => 1zookd; // => 2zookd; // => 3
Boolean Literal
Boolean literals represent true or false.
zookd; // => truezookd; // => false
String Literal
String literals represent strings.
zookd; // => 'zookd'
List Literal
List literals represent arrays in JavaScript.
Note that trailing comma and empty element are not allowed in zookd.
zookd; // => [ [ 1, 2 ], 'foobar' ]
Map Literal
List literals represent plain objects in JavaScripts.
zookd; // => { foo: { "bar": [ "baz" ] } }
Lambda Expression
Lambda expressions are anonymous functions that transform some values to another ones.
let ctx = target ;zookdeval;// => [ 2, 4, 6 ]
Property Accessors
Properties can be accessed with dot notations or bracket notations.
let ctx = foo: bar: baz: 10 42 ;zookdeval; // => 42
Function Call
A function in the top level of the context can be called.
let ctx = numbers;zookdeval; // => 6
API Reference
compile(expression)
Compile an expression to a JavaScript function which returns its value.
let fn = zookd;fn; // => 'function anonymous() {\nreturn 1 + 2.5;\n}'; // => '3.5'
eval(expression)
Compile and evaluate the expression.
zookd; // => 'Hello zookd!'