[dokuwiki] Re: Multiple parser instances and PARSER_WIKITEXT_PREPROCESS

  • From: Michael Hamann <michael@xxxxxxxxxxxxxxxx>
  • To: dokuwiki <dokuwiki@xxxxxxxxxxxxx>
  • Date: Mon, 27 Dec 2010 00:35:13 +0100

Hi,

Excerpts from TNHarris's message of 2010-11-05 22:17:09 +0100:
> I'm adding two-phase parsing using the PARSER_WIKITEXT_PREPROCESS 
> event.[1] But when I created the pre-rendering parser in my plugin, it 
> would interfere with the parser used by p_get_instructions. I couldn't 
> figure out where there was a static or global variable that prevented 
> two parsers from being used at the same time. But when I changed the 
> location of the event trigger, it worked again.
> 
> Instances *should* be independent, so changing the trigger doesn't solve 
> the problem, it just avoids it. So I'd like an explanation of why it 
> doesn't work without the patch. But wouldn't it also be more 
> straightforward to have the trigger before setting up the parser anyway?

I think the problem is that p_get_parsermodes() uses a static array to
cache the modes. Thus you get the exactly same mode objects as
p_get_instructions gets. $parser->addMode() now sets the "Lexer"
attribute of each mode which is probably what causes these problems.
Some print_r() statements have confirmed my assumptions, the problem is
that PHP returns objects by reference so we have the same mode objects
in all parsers but different lexer objects.

Michael
-- 
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: