I would like to use raku’s comb
function with a regex from a grammar instead of a stand alone regex. For example in the following code, which parses journalctl
logs from stdin, I would like to replace the &h
in MAIN
with something like &Journalctl::full_log
role Log {
token preamble { ... };
token message { [^<preamble>]* };
regex full_log { <preamble> <message> };
}
grammar Journalctl does Log {
token date { S+sdd:dd:dd };
token hostname { [^s]+ };
token ctl_unit { [^[]+ };
token pid { d+ };
regex preamble { <date> 's' <hostname> <ctrl_unit> '[' <pid> ']' ':' }
}
sub MAIN( ) {
my regex h { h. };
for $*IN.comb(&h) -> $wof { # FIXME
say $wof;
}
}
Here are some example journalctl
logs for reference:
Jun 25 14:45:54 cpu-hostname systemd-timesyncd[725]: Initial synchronization to time server 185.125.190.56:123 (ntp.ubuntu.com).
Jun 25 14:45:54 cpu-hostname systemd-resolved[722]: Clock change detected. Flushing caches.