More Perl regex stuff in E

Ka-Ping Yee ping@lfw.org
Fri, 16 Apr 1999 14:19:42 -0700 (PDT)


On Thu, 15 Apr 1999, Mark S. Miller wrote:
> If I'd tried to write this without regex's, it might 
> be locally more readable, but would also be a lot more code -- an 
> interesting tradeoff.  How does it compare with regex use in Perl or 
> Python?

It looks pretty much par for the course, except for the cryptic
(?ms) option in front and the unfamiliarity of the @bindings.

It's surprising how much it causes E to look like Perl.  I guess
even despite all the punctuation that Perl uses everywhere else,
a sufficiently large fraction is in regular expressions to cause
E-with-regexes to have a similar look.

> Here's a readability test: By reading this code, can you easily tell what 
> syntax it parses?

Not in a brief glance.  I wanted to study it a little more before
replying, but i thought i ought to point you at something i did a
little while ago to make regular expressions more Python-like
(i.e. readable).

See http://www.lfw.org/python/ and look at the "rxb" module.

It turns this:

    flag = member(letters, '-')
    listing = (begline +
        label.mode(
            flag +                            # file type
            flag*3 + flag*3 + flag*3) +       # owner, group, world perms
        label.data(
            somespace + anything +            # links, owner, grp, sz, date
            somespace +
            digit*2 + maybe(':') + digit*2 +  # year or hh:mm
            somespace) +
        label.file(
            anybut('->')) +                   # anything before symlink
        maybe(label.link(
            somespace + '->' + anything)) +   # possible symlink
        endline)

into this:

    print listing
    <Pattern ^\\(<mode>[A-Za-z-][A-Za-z-][A-Za-z-][A-Za-z-][A-Za-z-][A-Za-z-][A-Za-z-][A-Za-z-][A-Za-z-][A-Za-z-]\\)\\(<data>[ \011\015\012\014]+.*[ \011\015\012\014]+[0-9][0-9]\\(:\\)?[0-9][0-9][ \011\015\012\014]+\\)\\(<file>\\([^-]|-[^>]\\)*\\)\\(\\(<l
ink>[ \011\015\012\014]+->.*\\)\\)?$>


!ping

"I was recently on a tour of Latin America, and the only regret
I have was that I didn't study Latin harder in school so I could
converse with those people."
    -- Former U.S. Vice-President Dan Quayle