4 ms·
Possibly true, but we have perl, python, ruby to deal with those cases which all embed regex in a structural way. Occasionally you can just convert it to lines
by gouranga 14y ago
Possibly true, but we have perl, python, ruby to deal with those cases which all embed regex in a structural way.
Occasionally you can just convert it to lines first as well and problem solved.
- 4ad 14y agoYou 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.
- duncanbojangles 14y agoPerl - 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.
- Spooky23 14y agoKeep 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.
- _delirium 14y agoI 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.
- Roboprog 14y agoSeems 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)
- luriel 14y agoExcept 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 http://swtch.com/~rsc/regexp/regexp1.html