空值
Python 类型:None
null
布尔值
Python 类型:bool
true
false
字符串
Python 类型:str
"hello"
数值
Python 类型:int/float
2
1.2
-2
列表
Python 类型:list
[]
[1, 2, 3]
["abc", "efg"]
上下文,可以用于存储对象和属性
Python 类型:dict
{}
{a: 1, b: 2}
{"a": 1, "b": 2}
日期
格式:YYYY-MM-DD
Python 类型:datetime.date
date("2020-01-01")
时间
格式:HH:MM:SS
Python 类型:datetime.time
time("00:00:00")
日期时间
格式:YYYY-MM-DDTHH:MM:SS [ @timezone / timezone_offset ]
Python 类型: datetime.datetime
date and time("2017-03-10T00:00:00") // datetime.datetime(year=2017, month=3, day=10, hour=0, minute=0, second=0)
date and time("2017-03-10T00:00:00 +08:00") // datetime.datetime(year=2017, month=3, day=10, hour=0, minute=0, second=0, tzinfo=pytz.FixedOffset(480))
date and time("2021-01-01T00:00:00@America/Los_Angeles") // datetime.datetime(year=2021, month=1, day=1, hour=0, minute=0, second=0, tzinfo=pytz.timezone("America/Los_Angeles"))
支持常见的比较运算
| 运算符 | 说明 | 支持类型 | | --- | --- | --- | --- | | = | 等于 | any | | != | 不等于 | any | | > | 大于 | number, date, time, date-time | | < | 小于 | number, date, time, date-time | | >= | 大于等于 | number, date, time, date-time | | <= | 小于等于 | number, date, time, date-time | | a between [b] and [c] | a介于b和c之间 | number, date, time, date-time |
1 = 1 // True
1 != 2 // True
1 > 2 // False
5 between 1 and 6 // True
支持 与/或 运算
true and true // True
true and false // False
true or true // True
true or false // True
支持字符串拼接
"hello" + "world" // "helloworld"
支持 string() 转换
string(123) // "123"
支持 加减乘除 和 幂 运算
1 + 2 // 3
1 - 2 // -1
1 * 2 // 2
1 / 2 // 0.5
2 ** 3 // 8
下标取值
[1, 2, 3][1] // 1
[1, 2, 3][-1] // 3
元素过滤
[1, 2, 3][item < 3] // [1, 2]
Some 操作
some x in [1,2,3] satisfies x > 2 // True
Every 操作
every x in [1,2,3] satisfies x > 2 // False
{a: 1, b: 2} // {a:1, b:2}
{"a": 1, "b": 2} // {a:1, b:2}
取值
{a: 1, b: 2}.a // 1
元素过滤
[{a: 1, b: 2},{a: 2,b: 10}][b<7] // [{a:1,b:2}]
对输入值取反,返回 bool
not(true) // False
not(false) // True
not(null) // True
将输入值转换为字符串,返回 string
string(123) // "123"
string(true) // "True"
判断字符串中是否包含输入值,返回 bool
contains("abc", "b") // True
contains("abc", "d") // False
判断字符串是否以输入值开头,返回 bool
starts with("abc", "a") // True
starts with("abc", "b") // False
判断字符串是否以输入值结尾,返回 bool
ends with("abc", "c") // True
ends with("abc", "b") // False
判断字符串是否匹配输入正则表达式,返回 bool
matches("foobar", "^fo*bar") // True
判断列表中是否包含输入值,返回 bool
list contains([1, 2, 3], 2) // True
计算列表中元素个数
count([1, 2, 3]) // 3
判断列表中所有元素是否都满足真值判断,返回 bool
all([true, true, true]) // True
all([true, true, true, false]) // False
判断列表中是否有满足真值判断的元素,返回 bool
any([true, true, true]) // True
any([true, true, true, false]) // True
any([false, false, false]) // False
获取当前时间,返回 datetime.datetime.now() 结果
now() // datetime.datetime.now()
获取当前日期,返回 datetime.date.today() 结果
today() // datetime.date.today()
根据输入的时间类型获取当前月份,返回 string
month of year(date("2023-09-01")) // "September"
month of year(date and time("2019-08-17T00:00:00")) // "August"
根据输入的时间类型获取当前日期,返回 string
day of week(date("2023-09-01")) // "Friday"
day of week(date and time("2019-08-17T00:00:00")) // "Saturday"
判断【参数1】是否在【参数2】之前,返回 bool
before(date and time("2023-09-01T00:00:00"), date and time("2019-08-17T00:00:00")) // False
before([1..4], 5) // True
before(1, 5) // True
判断【参数1】是否在【参数2】之后,返回 bool
after(date and time("2023-09-01T00:00:00"), date and time("2019-08-17T00:00:00")) // True
after([1..4], 0) // True
after(1, 5) // False
判断【参数1】是否包含【参数2】,返回 bool
includes([1..4], 1) // True
includes([1..5], 6) // False
如果【参数1】为 null,则返回【参数2】,否则返回【参数1】
get or else(null, 1) // 1
get or else(1, 2) // 1
判断【参数】是否为 null,返回 bool
is defined(1) // True
is defined(null) // False
开发者可以注册自定义函数并进行调用,注册方式请参考README.md。
hello world(1, 2, 3) // 6
hello world(a:1, b:2) // 3