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

Patrick R. Michaud pmichaud at pobox.com
Sun Apr 29 11:24:41 CDT 2007


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



More information about the pmwiki-devel mailing list