Re: implementing a callback interface for a RecDescent parser
[email protected] (Dave McD)
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
OK, I think I understand what you are saying. I will defer any more questions on this until I study your OO Perl book a little more. It's not too important yet. But...I have another issue: I have built a parser which is working very well except for the line numbers being printed in error messages are negative numbers. It looks like if you add the TOTAL line count for the $text to this, then you get the correct line # + 1. Seems like a bug. Maybe I can get around it by initializing the starting line # with the total line count when I first call the parser as an extra argument? Also, I looked at your implementation of the TIE'ed subroutine to the $thisline variable in RecDescent.pm, and its seems really inefficient to have to compute the line number by counting lines for the remaining $text at the parse point, and subtracting the total lines for the intial $text. On long input files, if I use the $thisline variable in my grammer, it slows the parse down by like 5-10X. Is there not some way to carry a running total of newlines seen as the parse proceeds, similar to how $text is localized per rule? Dave Mc --- damian <[email protected]> wrote: > Hi Dave, > > You wrote: > > > I would like to implement a generic callback > interface > > on the parser object where I can pass in a > function > > pointer and a hash of the rules where the function > > should be called within an action assuming the > rule is > > matched sucessfully. I know I can hack this in > just > > by sticking a named main subroutine into the > actions, > > but I would like a generic interface. > > I'm not entirely clear exactly what you want to do, > but I > suspect it's entirely possible. ;-) > > Are you aware that you can define other methods in > the > Parse::RecDescent namespace, and they immediately > become > methods of any parser object. > > If I'm not on the right track here, you'll need to > send > me a (short!) example of what you want to achieve, > and > as soon as I understand it, I'll tell you how. > > Damian > > __________________________________________________ Do You Yahoo!? Send FREE Valentine eCards with Yahoo! Greetings! http://greetings.yahoo.com