# LPL - Lotus Programming Language

Evaluation is build on top of Symfony Expression Language. Complete documentation of used syntax could be found here.

# Data types

  • strings - single or double quotes 'foo', "foo"
  • numbers - 1.2, 123
  • arrays - JSON like syntax [34, 44, 'bar']
  • hashes - associative arrays are defined as objects with JSON like syntax {foo: 'bar'}
  • bool - true and false
  • null - null

# Operators

# Arithmetic

  • + (addition)
  • - (subtraction)
  • * (multiplication)
  • / (division)
  • % (modulus)
  • ** (pow)

# Bitwise

  • & (and)
  • | (or)
  • ^ (xor)

# Comparison

  • == (equal)
  • === (identical)
  • != (not equal)
  • !== (not identical)
  • < (less than)
  • > (greater than)
  • <= (less than or equal to)
  • >= (greater than or equal to)
  • matches (regex match)

# Logical

  • not or !
  • and or &&
  • or or ||

# String

  • ~ (concatenation)

Variables name = 'Joe', expression: name~" Doe", result: Joe Doe Variables name = 'Joe', surname = 'Doe', expression: "Hello " ~name~" "~surname, result: Joe Doe

# Ternary

  • foo ? 'yes' : 'no'
  • foo ?: 'no' (equal to foo ? foo : 'no')
  • foo ? 'yes' (equal to foo ? 'yes' : '')

# Working with arrays

LPL allows us to access array fields by using [] syntax.

Variables: data = [1,2,3,4], expression: data[0] + data[3], result: 5

Variables: data = ['tree' => 15, 'flower' => 5], expression: data['tree'] - data['flower'], result: 10

# Array operators

  • in checks if array contains value
  • not in checks if array does not contain value
  • .. generates range

Variables: data = ['foo','bar','baz'], expression: 'foobar' in data, result: false

Variables: data = ['foo','bar','baz'], var = 'foobar'', expression: var not in data, result: true

Variables: person = {"age": 22}, expression: 'person.age in 18..45', result: true

# Working with objects

LPL allows us to access public fields or methods by using . syntax.

Variables: person = {"name": "Joe"}, expression: Hello person.name, result: Hello Joe

# Functions

Functions modify or evaluate input.

List of currently supported functions:

Function Description Usage Returns
empty Check if variable is empty. empty(customer) TRUE/FALSE
lowercase Convert uppercase letters to lowercase. lowercase("FOOBAR") foobar
uppercase Convert lowercase letters to uppercase. uppercase("foobar") FOOBAR
regex Check if input corresponds to regex. regex("foobar", "[a-zA-Z]+") FALSE/array
isEmail Check if input is valid email address. isEmail("foobar") TRUE/FALSE
isIP Check if input is valid IPv4 or IPv6. isIP("foobar") TRUE/FALSE
isIPv4 Check if input is valid IPv4. isIPv4("foobar") TRUE/FALSE
isIPv6 Check if input is valid IPv6. isIPv6("foobar") TRUE/FALSE
time Returns time in unix form. time(), time("+1 day") 123456789
timeCombine Adds two HH:MM strings. timeCombine("1:44","0:20") 02:04
map Maps values from array. map(readers, "fullname") ["FS", "MD"]
jmespath Filter structures http://jmespath.org. jmespath(data, "[2:5]") [2,3,4]
cast Cast variable to different type cast("1", "int") 1 (int)
implode Join array of items by glue. implode([1,2], ",") 1,2
explode Explode string to array by delimiter. explode("1,2", ",") [1,2]
dateDays Returns number of days between two dates dateDays("1.1.2019", "2.1.2019") 2 (int)
count Returns number items in array count([1,3,2]) 3 (int)
inArray Check if value is in array. inArray([1,3,2], 2, true) true (bool)

# map

Map function has 3 arguments. map(array, value, key)

  • array (required) - source array to map values from. Accepts array of arrays or objects
  • value (required) - name of mapped value property. Accepts field name/index or method name ('id', 4, 'getId')
  • key (optional) - name of mapped key property. Accepts field name/index or method name ('id', 4, 'getId')

# cast

Cast function cast($var, $type) accept these possible types $type:

  • boolean or bool
  • integer or int
  • float or double
  • string
  • array
  • object
  • null
Casting Result Result Type
cast("150", "int") 150 int
cast(99, "string") "99" string
cast("true", "bool") true boolean
cast("false", "bool") false boolean
cast("0", "bool") false boolean
cast(0, "null") null null

# dateDays

This function has this notation dateDays(date1, date2, mode) and returns number of days between two dates.

  • date1 (required) - first date
  • date2 (required) - second date
  • mode (optional) - all days / working days (default all days)
    • 0 number of all days
    • 1 number of working days

E.q. dateDays("20.12.2019", "30.12.2019") or dateDays("20.12.2019", "30.12.2019", 1).

# inArray

This function returns boolean value which indicate if value is in provided array.

  • data (required) - provided array
  • item (required) - check this item if is in the array
  • isStrict (optional) - parameter which allow to set strict looking in array
    • true same type of data(string|int|..) and same value -> default value
    • false only same value

E.q. inArray([1,3,2], 2, false) or inArray([1,3,2], 2, true) or inArray([1,3,2], 2).

# time

This function returns unix timestamp value.

  • time (required) - provided time string
  • now (optional) - base time

E.q. time("+1 day"), time("-5 months") or time("+1 day", $_process->createdAt->format('U').


# Examples

  • isEmail(email) && invoice.price > 10
  • (age === 20 && invoice.price > 10) || invoice.type in ["TV", "INTERNET"]
  • not (isIP(subject.ip))
  • not ("foo" matches "/bar/")
  • map(users, 'fullname', 'id') => [54 => 'First name', 77 => 'Second name']
  • jmespath([0,1,2,3,4,5,6,7,8,9,10], '[2:5]') => [2,3,4]]
  • time("+1 second") - time() => 1

# Expressions

expression: customer
1
Variable value Result
customer = null FALSE
customer = "" FALSE
customer = 0 FALSE
customer = false FALSE
customer = "hello" TRUE
customer = 1 TRUE
customer = true TRUE
expression: price > 10
1
Variable value Result
price = null FALSE
price = "" FALSE
price = false FALSE
price = true FALSE
price = 9 FALSE
price = 15 TRUE

# Complex Expressions

  • At the same time (AND) => a && b
  • At least one (OR) => a || b
expression: customer && manager
1
Variable value Result
customer = null && manager = 1 FALSE
customer = "" && manager = "John" FALSE
customer = 1 && manager = "John" TRUE
customer = 1 && manager = 1 TRUE
expression: customer || manager
1
Variable value Result
customer = null ⎮⎮ manager = 1 TRUE
customer = "" ⎮⎮ manager = "John" TRUE
customer = null ⎮⎮ manager = null FALSE
customer = 0 ⎮⎮ manager = 0 FALSE