Minimalist Parse::RecDescent tutorial

jdavidb on 2003-02-19T15:02:31

Okay, so first you write your grammar. You know how to do that, or you wouldn't be looking into Parse::RecDescent in the first place. (Or, at least, if you don't, you'll have to look elsewhere; this "tutorial" is aimed at folks with yacc experience or something.) Rules, colons, etc.. Refer to literal text in double quotes, and regular expressions with slashes. Put the thing in a file.

Now, you can compile your grammar to Perl code with perl -MParse::RecDescent - grammarfile Classname to make Classname.pm a class for your parser object. Use that in your code, create a parser object, and call a method on it named after your starting rule, with the text to parse as the argument. Returns true or false for success or failure.

What do you do after that? I dunno; I haven't gotten that far yet. Really, this entry just exists to express my joy at figuring out and finally trying some of Parse::RecDescent.

Oh, and to relate this back to current events, I'm parsing SQL for fun and experience. Gotta go back to real work, now; experiment is over.


You join the mailing list!

merlyn on 2003-02-19T16:43:26

Join the mailing list!

And read about spew and come up with some more spew grammars!

Re:You join the mailing list!

jdavidb on 2003-02-19T17:40:01

Ah, yes, that's what next! And then I start a local Parse::RecDescent user's group and plan a talk for the Parse::RecDescent conference. :)

Hmmm, one day I just need to sit down and dedicate to reading through all those columns you have. There's always so much wonderful stuff there. I probably would've been up and running with P::RD long ago.