3 ms·
Seems like it shouldn't be too hard to write a little function (perl, python, whatever) to act as a "visitor" to hold this state, then just pass it little clos
by Roboprog 14y ago
Seems like it shouldn't be too hard to write a little function (perl, python, whatever) to act as a "visitor" to hold this state, then just pass it little closures (maybe a hash/map?) to evaluate the regexs and pass the match into a code block?
Something like (perl):
&visit_matches(
{ ' +' => sub { $x += length( $1); },
'#+' => sub { print $1, ' at ' $y, ',', $x'; $x += length( $1); },
'\n' => sub { $y++; }
});
(not an exact match to the pseudo-awk, but enough to get the idea)