Skip to content

Commit

Permalink
First end to end workflow working storing the right properties
Browse files Browse the repository at this point in the history
for i in '{ "type" : "bla", "a" : 42 }' '{ "type" : "bla", "a" : 13 }'; do echo $i; done | bin/eel -e='event ble { has $a1 = #1.a; has $a2 = #2.a; match { bla(#1, a == 42) bla(#2, a == 13) } }'
{"type":"ble","a1":42,"timestamp":"2020-02-19T14:18:53.986815Z","a2":13}
  • Loading branch information
FCO committed Feb 19, 2020
1 parent 40c2711 commit 1ab36f4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
8 changes: 6 additions & 2 deletions bin/eel
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ use JSON::Fast;
subset File of Str where .IO.f;

multi MAIN(File $file) {
eel($*IN.Supply.lines.map({ .&from-json }), :$file).tap: *.say;
my Supplier $s .= new;
eel($s.Supply.map({ .&from-json }), :$file).tap: *.&to-json(:!pretty).say;
lines.map: { $s.emit: $_ }
}

multi MAIN(Str :e(:eval(:evaluate(:$code)))!) {
eel($*IN.Supply.lines.map({ .&from-json }), :$code).tap: *.say;
my Supplier $s .= new;
eel($s.Supply.map({ .&from-json }), :$code).tap: *.&to-json(:!pretty).say;
lines.map: { $s.emit: $_ }
}
3 changes: 2 additions & 1 deletion lib/Event/AST/EventDeclaration.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ use Event::AST;
unit class Event::AST::EventDeclaration does Event::AST;
has Str $.name is required;
has %.attrs;
has $.body;
has $.body;
has %.store;
4 changes: 2 additions & 2 deletions lib/Event/Runner.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ multi method exec(|c) { die "unrecognised: { c.perl }" }

proto method init-event(% --> Hash()) {*}
multi method init-event(%event (:$timestamp where *.defined, |)) { %event }
multi method init-event(%event) { { |%event, :timestamp(now) } }
multi method init-event(%event) { %( |%event, :timestamp(now) ) }

method run() {
dd @!rules;
# dd @!rules;
for @!rules -> %cmd {
self.exec: %cmd
}
Expand Down
3 changes: 2 additions & 1 deletion lib/EventAction.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ method TOP($/) { make $<declarator>>>.made.grep: *.defined }

method name($/) { make ~$/ }
method mp-name($/) {
%*store.push: ~$<local-var> => $<term>.head.made;
make Event::AST::LocalVar.new:
:var-id(~$<local-var>),
:path($<term>>>.made)
Expand All @@ -33,6 +34,7 @@ method declarator:sym<event>($/) {
:$name,
:%attrs,
:@body,
:%*store,
;
}

Expand Down Expand Up @@ -63,7 +65,6 @@ method statement-time-mod($/) {
}

method statement:sym<event-match>($/) {
say $<st-infix-op>;
make $<st-infix-op>
?? Event::AST::Infix.new:
:left($<event-match>.made),
Expand Down
1 change: 1 addition & 0 deletions lib/EventGrammar.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ proto rule declarator {*}
rule declarator:sym<event> {
:my %*local-vars := SetHash.new;
:my $*event-name;
:my %*store;
<sym> <name>
{
$*event-name = ~$<name>;
Expand Down
57 changes: 42 additions & 15 deletions lib/EventTranslator.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,63 @@ use Event::AST;
use Event::AST::EventDeclaration;
use Event::AST::EventMatcher;
use Event::AST::Condition;
use Event::AST::LocalVar;
use Event::AST::Group;
use Event::AST::Infix;
use Event::AST::Value;
unit class EventTranslator;

multi method translate(Event::AST @ast --> Array()) {
say $?LINE;
dd @ast;
# say $?LINE;
# dd @ast;
@ = @ast.map: { self.translate: $_ }
}

multi method translate(Event::AST::LocalVar $ast) {
-> %state {
# dd [:%state, :$ast];
my $root = %state{ $ast.var-id };
for $ast.path -> $next {
$root = $root{ $next } // Nil
}
$root<>
}
}

multi method translate(%attrs) {
say $?LINE;
# say $?LINE;
my %attrs-callable = %attrs.kv.map: -> $key, $value {
$key => self.translate: $value
}
%(
:cmd<dispatch>,
:data(-> %state { %() })
:data(-> %state {
%attrs-callable.kv.map(-> $key, $value {
$key => do given $value {
when Callable {
.(%state)
}
default {
.self
}
}
}).Hash
})
)
}

multi method translate(Event::AST::EventDeclaration $_ where not .body) {
say $?LINE;
# say $?LINE;
}

multi method translate(Event::AST::EventDeclaration $_ --> Hash()) {
say $?LINE;
self.translate: .body, (self.translate: $_ with .attrs)
multi method translate(Event::AST::EventDeclaration $ast --> Hash()) {
# say $?LINE;
my %*store = $ast.store;
self.translate: $ast.body, (self.translate: %( :type(ast $ast.name), |$_ ) with $ast.attrs)
}

multi method translate([Event::AST::EventMatcher $_, *@next ($)], %disp?) {
say $?LINE;
# say $?LINE;
%(
|self.translate($_),
:next(self.translate: @next, %disp)
Expand All @@ -41,11 +68,11 @@ multi method translate([Event::AST::EventMatcher $_, *@next ($)], %disp?) {
multi method translate([Event::AST::EventMatcher $_], %disp?) { self.translate: $_, %disp }

multi method translate(Event::AST::EventMatcher $_, %next?) {
say $?LINE;
# say $?LINE;
%(
:cmd<query>,
|(:id($_) with .id),
:store,
|(:store($_) with %*store{ .id }),
|(
:query(%(
|(:type("==" => $_) with .name),
Expand All @@ -59,18 +86,18 @@ multi method translate(Event::AST::EventMatcher $_, %next?) {
multi method translate([]) {}

multi method translate(Event::AST::Condition $_) {
say $?LINE;
# say $?LINE;
.var => (.op => self.translate: .value)
}

multi method translate(Event::AST::Value $_) {
say $?LINE;
# say $?LINE;
.&ast-value
}

multi method translate(Event::AST:D $_) {
say $?LINE;
.&dd;
# say $?LINE;
# .&dd;
{
cmd => "query",
query => %(
Expand Down

0 comments on commit 1ab36f4

Please sign in to comment.