Event Expression Language
EEL recognizes event sequences in Raku Supplys. The slang compiles event and
pattern declarations into definitions executed by a runner with in-memory state.
Requires Rakudo with the RakuAST frontend, on macOS or Linux. Enable it with
RAKUDO_RAKUAST=1 when it is not the default frontend. The distribution is named
EEL, and the public API is imported with use EEL.
zef install .
# After installing, the CLI command is eel; in the checkout use bin/eel.raku.
raku -Ilib examples/login
raku tools/test.raku
use EEL;
event Session {
has $.id;
pattern TOP {
:partition{ .<id> }
:!ignore-unexpected
<start=.event: :type<start>>
<finish=.event: :type<finish>>
{ $!id = $<start>.id }
}
}
({type=>'start', id=>42}, {type=>'finish', id=>42}).Supply.match(Session).tap:
-> $session { say $session.id };
Stream API
$input.match(EventType, OtherType, :rule<TOP>, :reemit, :lateness(0), :actions($actions)) returns a Supply with
instances of the recognized events. Processing starts at subscription; each
subscription has its own runner. Inputs can be Hash/Map or defined objects.
:type(Temperature) accepts the class and its subclasses; an explicit type field
can classify objects or hashes by name. The remaining fields accept equality,
operator maps (==, !=, >, >=, <, <=) or callables, such as
:value(* > 40) and :value{ $_ > 40 }. Predicates receive the field value.
Without :reemit, the output contains only derived events. :reemit preserves all
inputs; :reemit(Login, Temperature) or :reemit<info warning> preserve only
selected types. Each input is re-emitted at most once, before the results it
completes. Selecting the output does not filter the matcher's input.
Derived events are not re-inserted automatically; chain .match calls to
recognize events derived by other stages.
Input or action errors end the subscription through the quit callback. Closing the
tap cancels the runner without finalizing incomplete matches. EOF finishes
recognition, including || results that were waiting for higher-priority
alternatives. use EEL installs .match on the shared Supply class via augment; the
slang is lexical. For direct control use EEL::Runner.new(:patterns[Type]), .process,
.finish, .pending and .close. .process and .finish return lists of results.
Patterns and operators
| Syntax |
Execution |
A B, A && B |
Sequence |
A &&& B |
Interleaved branches, with internal order preserved |
A & B |
Both branches whole, in any order |
A | B |
Independent paths, possibly producing several matches |
A || B |
Priority to the left, with alternatives kept for later failures |
[ ... ] |
Group with lexical scope |
( ... ) |
Group with positional capture |
?, *, +, ** 2, ** 1..3, ** 2..* |
Largest complete match per event |
??, *?, +?, ** 1..3? |
Smallest complete match per event (including zero) |
?!, *!, +!, ** 1..3! |
Every complete match per event |
:5min, [ :5min ... ] |
Window in event time, until the end of the scope |
OPEN ~ CLOSE BODY |
Recognizes OPEN, BODY and requires CLOSE; accepts recursion |
<name>, <alias=.name> |
Captured call |
<.name> |
Silent call |
<name(:flag)>, <name: :flag> |
Equivalent Raku argument forms |
<?{ ... }>, <!{ ... }> |
Zero-consumption boolean code assertion |
ITEM+ % SEP, ITEM+ %% SEP |
Separated repetition; %% permits a trailing separator |
$<name> = [ ... ] |
Named capture of an expression |
^ |
In a window, select a recognition start for emission; otherwise subscription start |
$ |
Wait for window closure or EOF; otherwise subscription EOF |
^^, $$ |
Absolute subscription start and EOF |
::, ::> |
Cut saved choices in the active ` |
:::, <commit>, <commit('name')> |
Cut saved choices in this pattern, the whole match, or a named caller |
:my $value = ...; |
Local initializer deferred to execution |
{ ... } |
Raku action |
:partition{ ... } |
Switches the partition context |
:ignore-unexpected, :!ignore-unexpected |
Ignore noise or invalidate the relevant path |
Precedence, from highest to lowest: sequence, &&&, &&, &, |, ||. Alternatives
and conjunctions also accept the operator before the first operand, without adding
an empty operand: | A | B, || A || B, & A & B, && A && B, &&& A &&& B.
[A B] & [C D] allows A B C D and C D A B, but not A C B D. Each occurrence
belongs to a single branch per path. This is a conjunction of event sequences,
with no internal interleaving between operands. The runner explores order choices
without materializing all permutations in advance.
In A || B, results from B are held back while A could still complete the whole
input pattern, including the suffix after the operator. If that path fails or
expires, B can win. Commitment happens at the first complete published result of
that choice. EOF eliminates incomplete paths and releases valid alternatives;
cancellation discards held results. Without EOF, failure or window, waiting and
memory consumption can be unbounded. Held results keep the original
timestamp and may be emitted after more recent results.
[A B] &&& [C D] also allows A C B D, A C D B, C A B D and C A D B.
An event only advances one branch per path; ambiguous assignments create
independent paths. Each branch keeps its own subpatterns, partitions and windows.
Repeated captures are combined in the global consumption order. Variables external
to the branches are preserved across switches; each branch's local variables keep
their own state.
The quantifier policies select complete results from the current event,
across overlapping recognition starts of the same repeat and partition.
Without a suffix, publish the match consuming the most events; suffix ?
publishes the match consuming the fewest, including zero when permitted;
suffix ! publishes every completion. Repetition bounds still apply.
Ties for largest or smallest use stable path order. Combined policies have
left-to-right priority. All live starts keep growing independently even when
their current result is not published. Expiring a winner lets another valid
start win, even with the same size. EOF does not flush losing candidates,
but can resolve assertions and ordered alternatives that require end of input.
Actions run on speculative paths, as in |; external effects are not
transactional. Forks preserve variables, container aliases and multi
candidates without re-running actions or subscription defaults. Entry rules with no consuming path, recursion without consumption and unbounded nullable repetitions are
rejected during validation.
Dynamic repetition bounds
ITEM ** { expression } evaluates the block once when that path enters the
repetition. It accepts a non-negative Int for an exact count or an inclusive
Range with non-negative integer endpoints; the upper endpoint may be Inf.
Invalid, inverted or exclusive bounds fail the subscription. Unbounded repetition
of a nullable item is rejected, including through nullable subpatterns.
<header=.event(:type<header>)>
<item=.event(:type<item>)> ** { $<header>.count }
# A calculated interval, exhaustive selection and separators:
<item=.event(:type<item>)> ** { 1..$<header>.count }! % <.event(:type<separator>)>
Blocks can read captures, pattern parameters and lexical variables. Evaluated
bounds survive forks without re-running the block; a new entry into the
repetition evaluates it again. Selection suffixes and %/%% work as with
literal bounds. Static recursion checks conservatively treat dynamic bounds as
possibly zero and possibly unbounded.
Boolean code assertions
<?{ expression }> succeeds when the block returns a true value;
<!{ expression }> succeeds when it returns a false value. Neither consumes
an event. A false assertion rejects only its path; a thrown exception fails the
subscription, like an action error. Blocks can read captures, lexical variables
and domain attributes in the current pattern context.
<request> <response>
<?{ $<response>.timestamp - $<request>.timestamp < 2 }>
These blocks are evaluated when recognition reaches them, including on
speculative paths. Returning False from an ordinary { ... } action still
does not reject a path. Like trailing actions, code assertions following a
terminal negative recognizer are deferred until its absence is confirmed.
Separated repetitions
ITEM+ % SEP recognizes one or more items with a separator between consecutive
items. ITEM+ %% SEP also permits one final separator. SEP is an atom; use
[ ... ] for a separator sequence or alternative. Bounds and selection suffixes
belong to the item quantifier:
<chunk> ** 2..4 % <separator>
<chunk>+! %% [ <separator> <checksum> ]
The bounds count items; result selection counts all consumed events, including
separators. Item and separator captures accumulate as arrays. A zero-item match
never consumes a separator. Noise, partitions and windows obey the usual rules:
use :!ignore-unexpected when adjacent input occurrences are required.
Stream and window anchors
| Anchor |
Meaning |
^^ |
Before the subscription's first processed input |
$$ |
Actual subscription EOF |
^ |
Select a recognition start in the innermost active window; otherwise ^^ |
$ |
End of the innermost active window or EOF; otherwise $$ |
Declare a window before its anchors: :1h ^ ... $. Each recognition candidate
starts its own window at its first consumed event. These are overlapping windows,
not fixed hourly buckets. Within a window, ^ does not require the subscription's
first event: unrelated input can precede the recognition. It must appear before
consumption in that same window.
^^ cannot move to the first matching event or the first event of a partition.
The subscription start follows processed temporal order after lateness buffering;
discarded late inputs do not establish a boundary.
Window ^ also gives emission priority to the oldest completed recognition,
by its first event's timestamp, with stable input order breaking ties. Priority
is independent for each derived event type, anchor occurrence and partition key.
Incomplete older candidates do not block the first emission. Once a candidate
emits, older starts are discarded. Later starts keep evolving, but their results
are suppressed until the winner's effective window expires. The winner retains
priority even after reaching a repetition bound or failing a later assertion.
Expiration does not replay suppressed results: a successor needs a new complete
match to emit. Without window ^, repetition selection keeps its usual behavior.
pattern TOP {
:1h ^ :partition{ .<distro> }
[ <item=.event(:distro(*.defined))> { ++$!count } ] ** 1..4
}
With a has UInt $.count = 0 attribute, four or more matching inputs for a distro
within the winning window emit snapshots with counts 1, 2, 3, 4, all
sharing one event-id. The first item starts that candidate's hour and is already
counted. Reaching four does not release ownership: further inputs cannot make a
different start emit until the winner's window expires. Later starts continue
recognizing independently. Expiration itself emits nothing; a later start must
complete again to publish. Use $ after the repetition to require a final match
at closure instead of incremental snapshots.
Both end anchors suspend recognition. Another input in the current partition
invalidates that end wait, even when unexpected events are ignored; other
partitions do not. Repetition growth can consume the next event and create a
new end wait. $ resumes its suffix when the window closes or EOF arrives;
$$ resumes only at EOF and fails if its window expires first. Closing a window
can confirm a new match, unlike merely promoting a suppressed candidate.
Results retain the timestamp of their last consumed event. Window closure uses
the existing event-time watermark, not a wall-clock timer.
pattern TOP {
^^ :!ignore-unexpected <request> <response> $$
{ # runs only after EOF confirms the end anchor
}
}
Cancellation confirms neither end anchor. An enclosing window that expires
before the selected inner window invalidates its end wait. An entry pattern
must still have a consuming path; a lookbehind's historical boundary is not EOF.
Code requiring absolute subscription boundaries should use ^^ and $$.
Explicit commitment
Cuts discard saved recognition choices without consuming an event: