krl-parser
Advanced tools
Changelog
0.12.1 - May 26, 2017
random:uuid()
- return a globally unique id (using cuid)
random:word()
- return a random english word
random:integer(lower = 0, upper = 1)
- return a random integer between lower
and upper
random:number(lower = 0, upper = 1)
- return a random number (float) between lower
and upper
if event.eid == "none" or is not given, it will default to a uuid
event:send(event, host = null)
- now when given a host
string, it will send an async http sky/event request to that engine
better syntax for choose
making the action block syntax consistent.
ActionBlock ->
(if <expr> then)? <Actions>
Actions ->
<action> ;
| every { <action 0> ; <action 1> ; ... }
| sample { <action 0> ; <action 1> ; ... }
| choose <expr> { <action 0> ; <action 1> ; ... }
event:attr(name)
- see issue #179Changelog
0.12.0 - May 25, 2017
setting(..)
)<name> = defaction(<params...>){
<declaration 0>
<declaration 1>
...
<action block (i.e. anything you would put in a rule action)>
returns <expr 0>, <expr 1>, ...
}
NOTE: returns
is optional
For example
global {
foo = defaction(){
send_directive("foobar")
returns 1, 2, 3
}
}
rule bar {
select when ...
foo() setting(a, b, c)
fired {
//a = 1, b = 2, c = 3
}
}
Another example
global {
foo = defaction(){
every {
http:get(...) setting(resp)
}
return resp["content"].decode()["msg"]
}
}
rule bar {
select when ...
foo() setting(message)
}
sample
This will randomly select an action to run.rule bar {
select when ...
//randomly pick one of these 3 actions to run
sample {
send_directive("foo")
send_directive("bar")
send_directive("baz")
}
}
ActionBlock ->
<action> ;
| if <expr> then <action> ;
| if <expr> then every { <action 0> ; <action 1> ; ... }
| if <expr> then sample { <action 0> ; <action 1> ; ... }
| every { <action 0> ; <action 1> ; ... }
| sample { <action 0> ; <action 1> ; ... }
| choose <expr> { <action 0> ; <action 1> ; ... }
with
is no longer used for named arguments. Both for functions and actions.//OLD WAY
foo(1, 2) with a = 3 and b = 4
//NEW WAY
foo(1, 2, a = 3, b = 4)
with
is no longer used on raise
/schedule
//OLD WAY
raise domain event "type" with foo = 1 and bar = 2
//NEW WAY
raise domain event "type" attributes {"foo": 1, "bar": 2}
send_directive
no longer uses with
it's now send_directive(name, options = {})
//OLD WAY
send_directive("name") with foo = x and bar = y
//NEW WAY
send_directive("name", {"foo": x, "bar": y})
select when ...
//OLD WAY
select when foo bar;
//NEW WAY
select when foo bar
with
Changelog
0.11.0 - May 20, 2017
<name> = defaction(<params...>){
<declaration 0>
<declaration 1>
...
<action block (i.e. anything you would put in a rule action)>
}
For example
chooser = defaction(val){
baz = "hello"
qux = "bye"
choose val {
asdf =>
foo(val)
fdsa =>
bar(val, "ok", "done")
}
}
configure using
)foo = function(bar = 2, baz = bar + 3){
bar + baz
}
//-or- when it gets too long
foo = function(
bar = 2,
baz = bar + 3,
qux = 4,
quux = blah(qux),
){
...
}
//defaction parameters work the same way as functions
//the following are now actions and cannot be used as a function
engine:newPico
engine:removePico
engine:newChannel
engine:removeChannel
engine:registerRuleset
engine:unregisterRuleset
engine:installRuleset
engine:uninstallRuleset
event:send
schedule:remove