Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Perl6 Grammars

by kelan (Deacon)
on Sep 23, 2002 at 20:05 UTC ( #200215=perlmeditation: print w/ replies, xml ) Need Help??

I'm getting excited about Perl6 Grammars. We're going to be taking a big step up from normal regex's, a step that I think will make many things easier, and allow for cooler things to be possible. I've heard some grumblings from different places about how much regex's will be changing in Perl6, but as I read through Apocalypse 5, I kept thinking, "This is going to be cool." None of the Apocalypses thus far have impressed me more or had the coolness factor of the new grammar constructs. (Sorry for the overuse of 'cool.')

Full-fledged parsing will become much easier to do directly in Perl. I think this will simplify many many CPAN modules that are mostly based around parsing. Of course the other functionality provided by those modules won't go away, and in fact may be more easily enhanced by the use of grammars. I highly expect CPAN to begin offering not only modules but also standalone grammar definitions, ready to be downloaded and used directly if one of the parsing modules doesn't fit your exact needs. Perhaps the extension .pg will soon become as commonly recognized as .pm is now.

The nice part about the grammars is that if you don't need a full one, you can still write simple rules for quick and easy matching, like it's done now. But you'll still have the ability to take advantage of the flexibility, control, and power inherent in these grammars. Considering the ties to object orientation (grammars with inheritance, polymorphism, etc), this is going to be some great stuff.

Well this is the Discussion Meditation section, so what thoughts have you had regarding the new Perl6 grammars? What great ideas are forming in your minds? Do you think they're going to be juicy or junk?

kelan


Yak it up with Fullscreen ChatBox

Edited (by multiple janitors): ~Mon Sep 23 22:51:01 2002 (GMT): Moved from Perl Monks Discussion to Meditations, per Consideration.

Comment on Perl6 Grammars
Re: Perl6 Grammars
by diotalevi (Canon) on Sep 23, 2002 at 20:43 UTC

    I think this fills my wish for Parse::RecDescent to handle binary data grammars. I did some work parsing Xerox Metacode files (an undocumented binary format for use with volumn printing systems - think printers hooked up to mainframes) and while it was a pain - I would really have preferred to write the description down as a proper grammar and then let the regex engine handle the dirty work.

    I ended up solving the problem without a grammar but as with anything - I could have done it better than the straight procedural code I ended up with.

      I did some work parsing Xerox Metacode files

      Have you considered packaging and publishing your code on CPAN? There seems to be a shortage of modules in that area.

        Yes of course. Sadly I can only write down a smidgen of what I picked up. You can get the public bit from http://www.greentechnologist.org/wiki/wiki?XeroxMetacode though I think that version might be buggy (it at least expresses the essense of getting through a metcode file). With only that little bit I just never thought that it was CPAN-worthy.

Re: Perl6 Grammars
by Abigail-II (Bishop) on Sep 24, 2002 at 10:09 UTC
    I read the exergises 5, and the examples comparing the perl5 way with the perl6 way, and thought "What's the big deal? The perl6 regexes aren't much shorter".

    Abigail

      No, they will probably even tend to be longer due to defaulting to /x.

      Seems what Larry was after is readability and extensibility though. Writing complex parsers that need to chain multiple regexes is not exactly trivial in Perl5, possible as it may be. The big deal with Perl6 patterns is the fact that they get promoted to actual control flow structures in and of themselves, and that interdependent groups of regexen get to enjoy the same benefits as classes/objects already do.

      Makeshifts last the longest.

      Someone in perl6-language pointed that out a few weeks ago and suggested a few changes. None of the replies agreed with it though. They don't realize character classes outnumber closures 100 to 1...
        They don't realize character classes outnumber closures 100 to 1...
        From what I gather, the issue here is mostly Unicode -- literal character classes are a bad idea with Unicode data, so making them longer, and in effect discouraging their use, isn't considered a bad thing. This assumes, of course, that a significant number of people actually use non-ASCII a significant amount of the time. I really don't have the experience to comment on this last assumption.

        /s

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-07-29 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (212 votes), past polls