Re:Rob Pike: "Current Unix tools are weakened by the built-i...
by _delirium on Thursday June 14, 2012 @01:12PM
(#4112378)
I don't think they really give you a structural way to use regexes; more of a procedural way, where you can embed regexes within explicit loops that iterate over lines, matching and updating state-variables as you go. Unlike regexes, which are declarative and abstract away the details of the match algorithm and its internal match-progress variables, you are explicitly maintaining the match state there. I find myself writing manual-FSM code like if($scanning_for_new_record) { /.../; }. And even that only really works if you can do a one-pass match, without needing to backtrack across line boundaries.
It's inelegant enough that I sometimes do a two-step process instead: 1) transform the input so that whatever view I want of it maps to a line-oriented format; and then 2) process the result in the standard Unix line-oriented fashion.
Re:Rob Pike: "Current Unix tools are weakened by the built-i...
by Roboprog on Thursday June 14, 2012 @02:53PM
(#4112907)
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)
Re:Rob Pike: "Current Unix tools are weakened by the built-i...
by 4ad on Thursday June 14, 2012 @11:33AM
(#4111786)
You do realize that this paper is from early 80s and Perl, Python and Ruby did not exist, right?
As for your second statement, if you would have read the paper you would have seen why it is not the case.
Re:Rob Pike: "Current Unix tools are weakened by the built-i...
by duncanbojangles on Thursday June 14, 2012 @12:49PM
(#4112256)
Perl - Appeared in 1987
A bit late in the 80s, but still.
[Edit] I read your comment too quickly and hadn't noticed that you said "early 80s". My apologies.
Re:Rob Pike: "Current Unix tools are weakened by the built-i...
by Spooky23 on Thursday June 14, 2012 @12:50PM
(#4112260)
Keep in mind that Perl4 was the first "big" version of Perl, available in 1991 with the publication of the camel book.
When this was written companies were advertising "Cut and Paste" as a big feature for word processors.
Re:Rob Pike: "Current Unix tools are weakened by the built-i...
by luriel on Thursday June 14, 2012 @01:50PM
(#4112600)
Except that PCREs (or most of their implementations which are used in all those languages, re2 and Go's standard regexp package are exceptions) have some fundamental issues: http://swtch.com/~rsc/regexp/regexp1.html
Occasionally you can just convert it to lines first as well and problem solved.