|
List Info
Thread: Question about nested expressions...
|
|
| Question about nested expressions... |

|
2007-04-29 09:46:03 |
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?
TIA, a bunch!
Cheers,
Dan
_______________________________________________
pmwiki-devel mailing list
pmwiki-devel pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-devel
|
|
| Re: Question about nested
expressions... |
  United States |
2007-04-29 11:24:41 |
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
_______________________________________________
pmwiki-devel mailing list
pmwiki-devel pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-devel
|
|
| Re: Question about nested
expressions... |

|
2007-04-29 11:45:41 |
On 4/29/07, Patrick R. Michaud <pmichaud 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
_______________________________________________
pmwiki-devel mailing list
pmwiki-devel pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-devel
|
|
| Re: Question about nested
expressions... |
  United States |
2007-04-29 12:03:03 |
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
_______________________________________________
pmwiki-devel mailing list
pmwiki-devel pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-devel
|
|
[1-4]
|
|