Skip Menu |

This queue is for tickets about the Parse-RecDescent CPAN distribution.

Report information
The Basics
Id: 74088
Status: resolved
Priority: 0/
Queue: Parse-RecDescent

People
Owner: Nobody in particular
Requestors: ribasushi [...] leporine.io
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: State sharing between parser instances
Just adding a placeholder RT - I already worked around the issue (with a hideous hack), but having a fix upstream would be really nice. The problem is that any accumulators registered in the parser "namespace" will be visible to every instance of a parser. The result is this: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/SQL-Translator.git;a=blob;f=lib/SQL/Translator/Utils.pm;hb=b62fa4925be9fc3f0ef0fd32a31ea1ced60696cd#l222 Cheers
Hello! Would you be willing to provide a small test case (along with any required input files) that demonstrate this issue? Also, what do you mean by: "accumulators registered in the parser "namespace""? Thanks! Jeremy
I've looked into this, and I've made some fixes to both modules that address the issue. 1. Parse::RecDescent's Precompiled parsers didn't have a good way to be independent of Parse::RecDescent. There's an experimental -standalone flag for Precompile that will allow P::RD to build parsers that no longer depend directly on P::RD. 2. The currently-released P::RD generates standalone parsers with a great deal of duplicated functions. I've made some (local) changes to P::RD to allow that shared data to be output once to a "Runtime" module with a name of your choosing. 3. SQL::Translator itself uses global variables (like %tables, @table_comments, etc.) to keep track of the parse state. P::RD provides $thisparser->{local} to allow for per-parser object data. This, combined with integrating the new, unreleased features above gets rid of the need for Class::Unload in SQL::Translator. After I clean up P::RD, test and release a new version to CPAN, I'll provide the SQL:Translator patch to match. Thanks for the bug report! Jeremy
Hi Jeremy! I M resurrecting my work on this, trying to get it a tad further along. On Mon Mar 26 07:37:34 2012, jtbraun wrote: Show quoted text
> ... > 3. SQL::Translator itself uses global variables (like %tables, > @table_comments, etc.) to keep track of the parse state. P::RD provides > $thisparser->{local} to allow for per-parser object data. This, > combined with integrating the new, unreleased features above gets rid of > the need for Class::Unload in SQL::Translator.
Mmmm now that I am looking at this more carefully it actually does not answer my question at all. My main goal is to use the same *parser object* multiple times. While I understand how the globals work (it's very well described here [1]), it is not clear to me what will improve if I switch to $thisparser->{local}. There still doesn't seem to be a clear way for me to reset/undef the contents of {local} between $parser->parse($rulename) invocations. What would you recommend? Cheers! [1] https://metacpan.org/pod/release/JTBRAUN/Parse-RecDescent-1.967_010/lib/Parse/RecDescent.pm#Start-up-Actions
Show quoted text
> Mmmm now that I am looking at this more carefully it actually does not > answer my question at all. My main goal is to use the same *parser > object* multiple times. While I understand how the globals work (it's > very well described here [1]), it is not clear to me what will improve > if I switch to $thisparser->{local}. > > There still doesn't seem to be a clear way for me to reset/undef the > contents of {local} between $parser->parse($rulename) invocations. > > What would you recommend?
As long as you're not sharing the parser object between threads, one of two things. 1. If you have control of the locations calling $parser->parse($rulename), just assign to $parser->{local} prior. 2. Modify your rule(s) to include a dummy rule that modifies {local}. Something like: clearlocal: { $thisparser->{local} = ResetLocalToWhateverYouWant; } startrule: clearlocal original_stuff_here
Ping! Do anything need anything further on this, or may I mark it resolved?
On Sat Sep 12 23:09:28 2015, jtbraun wrote: Show quoted text
> Ping! Do anything need anything further on this, or may I mark it resolved?
Nope, at this point it seems I have all I need. If I run into any sort of issues when working with the "bundled P::RD", I will open new tickets. Cheers!