Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added grammar for actions

...

Code Block
linenumberstrue
<rule>         ::= rule <ID> {
                    select when <eventex> [within <time expr>]
                    [foreach <EXPR> setting(<ID>[,<ID>])]
                    [pre { [<bindings>] }]
                    [[if <BOOL EXPR> then ]<ACTION><action>]
                    [<POSTLUDE>]
                  }
<time expr>   ::= <POS INT> <period>
<period>      ::= seconds | minutes | hours | days |weeks

...

The simplest form is simply two identifers, the event domain and the event type. Event attributes can be matched against regular expressions. All of the matches must succeed for the rule to be selected for evaluation. Portions of each attribute thus matched can be captured and named using setting. The number of identifiers given should match the total number of captures in all of the regular expressions for the simple event expression. If fewer are given, extra capture groups will not be retained. If more are given, the extra names will be bound to the null value.

A simple event expression can also use an escape into imperative programming, through the use of the optional where clause which will evaluate a Boolean expression.

Actions

The action taken by a rule is something which affects the world outside of the pico in which the rule is being evaluated. Actions can be simple or compound. The grammar is:

Code Block
<action>          ::= <simple action> | <compound action>
<compound action> ::= every { <action list> } | choose <EXPR> { <choice list> }
<actions list>    ::= <action> | <action list> ; <action> [;]
<choice list>     ::= <choice> | <choice list> ; <choice> [;]
<choice>          ::= <id> => <action>
<simple action>   ::= noop()
                    | <SEND DIRECTIVE>
                    | <HTTP POST>
                    | <DEFINED ACTION>
                    | <BUILT-IN ACTION>

noop() action

The grammar for the conditional action portion of a rule (repeated here for convenience> 

Code Block
[[if <BOOL EXPR> then ]<action>]

allows, in the syntax, three of the four possibilities that a KRL programmer might need: (0) neither condition nor action, (1) unconditional action, and (3) conditional action. But the syntax has no way of allowing (2) conditional but no action. The programmer can use the simple action noop() when this fourth possibility is needed.

The rule is considered to have "fired" if and only if the condition is missing (cases 0 and 1) or the condition expression evaluates to true (in cases 2 and 3).