Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Typo in Exegesis 5?

by jynx (Priest)
on Aug 23, 2002 at 16:00 UTC ( #192368=perlquestion: print w/ replies, xml ) Need Help??
jynx has asked for the wisdom of the Perl Monks concerning the following question:


i don't know where the most appropriate place to put this is,

but it seems there's a typographical error in Exegesis 5. If there isn't, hopefully someone can explain it to me?

On the last page, when discussing new rewrites of old regexen, for IPv4 matching it has the following:

# Perl 5 my $quad = qr/(?: 25[0-5] | 2[0-4]\d | [0-1]??\d{1,2} )/x; $str =~ m/ $quad \. $quad \. $quad \. $quad /x; # Perl 6 rule quad { (\d<1,3>) :: { fail unless $1 < 256 } } $str =~ m/ <quad> <dot> <quad> <dot> <quad> <dot> <quad> /x; # Perl 6 (same great approach, now less syntax) rule quad { (\d<1,3>) :: <($1 < 256)> } $str =~ m/ <quad> <dot> <quad> <dot> <quad> <dot> <quad> /x;
However according to earlier in the exegesis (and the apoc that preceded it), there was no x modifier for perl 6 regexen, and even if there were, it would be at the front of the RE, not the back. Am i forgetting a feature?

jynx


PS i have already e-mailed O'Reilly Net about it, but it doesn't seem changed, so this seems a reasonable place to inform TheDamian, get his opinion (if i'm in error), and whore for XP :-)

Comment on Typo in Exegesis 5?
Download Code
Re: Typo in Exegesis 5?
by waswas-fng (Curate) on Aug 23, 2002 at 18:49 UTC
    From Page 2 Line 1, In Perl 6 every rule implicitly has the equivalent of the Perl 5 /x modifier turned on...

    He must have gotten confused himself after swapping from 5 regex to 6 regex so many times durring the paper, unless /x is doing something new in 6?

    -Waswas
Re: Typo in Exegesis 5?
by VSarkiss (Monsignor) on Aug 23, 2002 at 18:53 UTC

    I think you're right, it's just a typo. Your reasoning (no /x modifier, and modifiers at the front) is my understanding as well. Keep an eye on the page, it'll probably be fixed as soon as TheDamian has a chance to look at it.

    I could swear I posted this same writeup once already, but it appears to have disappeared....

Re: Typo in Exegesis 5?
by Juerd (Abbot) on Aug 24, 2002 at 10:39 UTC

    # Perl 5 @cmd = ('get','put','try','find','copy','fold','spindle','mutilate +'); $cmd = join '|', map { quotemeta $_ } @cmd; $str =~ / (?:$cmd) \( .*? \) /;
    There should be an 'x' there.
    $deleteline = rx/^^ \< <sp> (\N* \n) / $appendline = rx/^^ \> <sp> (\N* \n) /
    ...
    The first character on that line must be either a '<' or a '>'. Note that we have to escape these characters since angle brackets are metacharacters in Perl 6.
    I don't think > needs to be escaped when not used in <...>. I'd be surprised if rx/>/ were invalid.
    $text =~ /<Diff.file>/; # Invoke through grammar
    In Apocalypse 5, Larry uses ::, not . to separate grammar and rule names.
    ... $0/2002/08/22/exegesis5.html{hunk} ...
    The O'Reilly CMS probably screwed this up.
    # Perl 5 $str =~ m/ ^ m* (?:d?c{0,3}|c[dm]) (?:l?x{0,3}|x[lc]) (?:v?i{0,3}|i[vx +]) $ /ix; # Perl 6 $str =~ m:i/ ^ m* [d?c<0,3>|c<[dm]>] [l?x<0,3>|x<[lc]>] [v?i<0,3>|i<[v +x]>] $ /;
    Those can't be completely equal, because the meaning of the $ metacharacter changed.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      You do indeed seem right on most of those points, Jured, but there's a couple that bear a closer look. I'm sure > doesn't need to be escaped when not inside a <> construction (just like the HTML I'm writing now, which is rather interesting, in a cool meta- sort of way, but I'm going off on a tangent)... but in that case, I'd escape it anyway, for parallelism. As to the last point, the meaning of $ did indeed change, and he meant $$, not $, since that is a newline in the middle of the string.


      Confession: It does an Immortal Body good.

        As to the last point, the meaning of $ did indeed change, and he meant $$, not $, since that is a newline in the middle of the string.

        No, there is no /m in the Perl5 version. I think the correct translation is \n? $.

        - Yes, I reinvent wheels.
        - Spam: Visit eurotraQ.
        

      $text =~ /<Diff.file>/; # Invoke through grammar
      In Apocalypse 5, Larry uses ::, not . to separate grammar and rule names.

      This is a method call.

      Update: As Juerd rightly points out, there is a distinction between a grammer and a class, and their rules and methods. However, the same syntax is used to call a rule from a grammer, as a grammer can inherit from other grammer(s), delegate to other grammers, and possibly even autogenerate rules. In these cases, the rule needs to be treated as a method call.

      Cheers,
      Erik

      Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

        This is a method call.

        file is a rule, not a method. (Diff is a grammar, not a class. -- There is a parallel, but Damian and Larry interpret it differently)

        - Yes, I reinvent wheels.
        - Spam: Visit eurotraQ.
        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://192368]
Approved by VSarkiss
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-12-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls