Skip to content

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExprML Language

ExprML is a programming language for representing and evaluating expressions in JSON format.

The language specification is defined by a JSON Schema, available here:

Concept

ExprML realizes the following concepts to make it suitable as an expression language used in configuration files:

  • JSON-based:
    • ExprML can represent expressions in JSON (and JSON-compatible YAML).
    • ExprML expressions can be evaluated as JSON values.
    • ExprML expressions can be checked and auto-completed statically using the JSON Schema.
  • Embeddable:
    • Interpleters implementing ExprML are available as libraries.
    • JSON Schema of ExpreML can be referenced from exsisting tools and other JSON Schemas.
  • Multi-language support
    • Libraries implementing the interpreters are provided in various programming languages.

Interpreters

Libraries

Console application

https://github.com/exprml/exprml-cli

Syntax

Literals

Boolean

true
# => true

Number

1089
# => 1089

String

'`ExprML`'
# => "ExprML"

Composite values

Array

arr: [1, 2, 3]
# => [1, 2, 3]

Object

obj:
  id: 1234567
  name: "`ExprML`"
# => {"id": 1234567, "name": "ExprML"}

Functions and variables

eval:
  $hello_func:
    $target: $name_var
where:
  - $name_var: "`ExprML`"
  - $hello_func($target):
      cat: ["`Hello, `", $target, "`!`"]
# => "Hello, ExprML!"

Operations

Unary operations

not: true
# => false
operator operand result
len string, array, object length of the collection
not boolean negation of the operand
flat array of array flattened array
floor number maximum integer which is less than or equal to the operand
ceil number minimum integer which is greater than or equal to the operand
abort string It fails the evaluation with a given message.

Binary operations

gte: [ 1234, 567 ]
# => true
operator operands result
sub number subtraction of the operands
div number division of the operands
eq number, boolean, string, array, object equality of the operands
neq number, boolean, string, array, object negation of the equality of the operands
lt comparable values, which are numbers, strings, booleans, or arrays of comparable values whether the left operand is less than the right operand
lte comparable values whether the left operand is less than or equal to the right operand
gt comparable values whether the left operand is greater than the right operand
gte comparable values whether the left operand is greater than or equal to the right operand

Variadic operations

add: [ 1, 2, 3 ]
# => 6
operator operands result
add number sum of the operands
mul number product of the operands
and boolean logical conjunction of operands
or boolean logical disjunction of the operands
cat string concatenation of the operands
min number minimum number in the operands
max number maximum number is the operands
merge object merged object of the operands

Conditional branches

cases:
  - when: false
    then: 1
  - when: true
    then: 2
  - otherwise: 3
# => 2

Collection

Collection is one of string, array, and object.

Iteration

String
for($idx, $elem): "`abc`"
do: $idx
if:
  neq: [$elem, "`b`"]
# => [0, 2]
Array
for($idx, $elem):
  arr: [5, 6, 7]
do: $idx
if:
  neq: [$elem, 6]
# => [0, 2]
Object
for($key, $val):
  obj:
    id: 123
    name: "`ExprML`"
do: $key
if:
  neq: [$val, 123]
# => {"name": "ExprML"}

Element extraction

String
get: 1
from: "`abc`"
# => "b"
Array
get: 1
from: 
  arr: [1, 2, 3]
# => 2
Object
get: "`name`"
from:
  obj:
    id: 123
    name: "`ExprML`"
# => "ExprML"

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages