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

The Editor editor at fast.st
Sun Apr 29 11:45:41 CDT 2007


On 4/29/07, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> On Sun, Apr 29, 2007 at 10:46:03AM -0400, The Editor wrote:
> > I'm trying to understand how the nesting capabilities work in Pm's new
> > core markup expressions function and think it has to do with these
> > main lines...
> >
> >   $expr = preg_replace('/\\(\\W/e', "Keep(PSS('$2'),'P')", $expr);
> >   while (preg_match('/\\((\\w+)(\\s[^()]*)?\\)/', $expr, $match)) {
> >     list($repl, $func, $params) = $match;
> >
> > But for the life of me it doesn't make too much sense.  Would anyone
> > be willing to try and interpret this briefly in a little bit more
> > accessible english?
>
> Short:  It's finding the smallest matching paren set for "(funcname ... )",
> and breaking it down into
>    $repl    - the entire string to be replaced
>    $func    - the name of the function to be called
>    $params  - any arguments to that function
>
> Longer:
>
> The first line escapes any opening parens that aren't followed by
> an identifier character -- this is in case some of the params
> contain an unquoted open parenthesis.  The while loop then
> looks for any instance of an open paren, a function name
> (captured to $1), and optionally a whitespace character followed
> by any sequence of characters excluding parens (captured to $2),
> and a close paren.
>
> Pm


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?  I really appreciate
your explanations!

Cheers,
Dan



More information about the pmwiki-devel mailing list