And today I discover use re 'debug'.
With a simple line, I can get an overview of what the regular expression evaluator is trying to do when parsing a string (coloring added manually).
In yellow, we can track the position within the string: how much has been accepted so far. In green, a quick overview of what was just behind that position and what is just ahead. The blue code seems to identify the next operation that the regexp will do -- its program counter, sort of, and in white the detail of what is tried/done.
edit: let's not paint colors manually any more!
redebug=> sub {
if (s/(END [(]0[)])$/$ign$1$norm/) {
$compiling = 0;
} elsif ($compiling) {
s/(.*)/$ign$1$norm/;
}
if (s/^(Compiling .*)/$low$1$ign ___/) {
$compiling = 1;
}
s/^(Freeing .*)/${ign}$1$norm/;
s/^(Matching REx) ("[^"]+"[.]*) against ("[^"]+"[.]*)/$1 $high$2$norm against $low$3$norm/;
s/(Found anchored)/$blink$1$norm/;
s/^ ([0-9 ]+) (<[^>]+> <[^>]+>) * ([|0-9 ]+:)/ $blink$1 $high$2 $low$3$norm/;
s/(Match succesful.)/$blink$1$norm/;
},
$blink, $ign, $high and such are ANSI escape code to apply the colors you want. just make sure $norm returns to regular display.
ReplyDelete