[pmwiki-devel] Question about nested expressions...

Patrick R. Michaud pmichaud at pobox.com
Sun Apr 29 12:03:03 CDT 2007


On Sun, Apr 29, 2007 at 12:45:41PM -0400, The Editor wrote:
> Thanks so much. It's coming into focus now.  I take it these lines
> actually evaluate the nested functions somehow, is that correct?
> 
>    $code = @$MarkupExpr[$func];
>    ...
>    $out = eval("return ({$code});");
>    if ($expr == $repl) { $expr = $out; break; }
>    $expr = str_replace($repl, Keep($out, 'P'), $expr);
> 
> Could you help briefly parse this for me too?  

$func is the name of the markup expression function to be
evaluated.  Based on this, we look up the code to be executed 
in the $MarkupExpr array (indexed by the name of the function) 
and store that in $code.  We then use eval() to evaluate the 
code and store the result in $out.

If the overall expression we were evaluating is exactly the
string to be replaced (i.e., this isn't a nested expression),
then we return $out directly.  Otherwise, this was possibly
a nested expression, so we replace the nested expression
with its result (using Keep() to make sure the result is
treated as a single parameter even if it contains quotes or
spaces), and then loop around to evaluate another expression.

Pm



More information about the pmwiki-devel mailing list