[pmwiki-users] Wikipaths (was: PData support for pagelisting images)

Patrick R. Michaud pmichaud at pobox.com
Thu Sep 7 17:27:42 CDT 2006


On Fri, Sep 08, 2006 at 12:16:05AM +0200, Dominique Faure wrote:
> On 9/7/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> >> Also, how about using a more tradtional function form
> >> (is it too hard from a regexp standpoint?):
> >>
> >> >   {(function args)Group.PageName#section$[:?]var}
> >>
> >>     {function(args)Group.PageName#section$[:?]var}
> >
> >It's not too hard, but I like the {(function)...}
> >syntax since "{(" is a clear marker that a function is
> >being applied.  It's also somewhat consistent with (:directive:)
> >syntax, where the args are inside the parens instead of out.
> >It also leaves the door slightly open for a way to apply
> >functions to non-variables, like:
> >
> >    {(toupper) This text is converted to all caps}
> >
> 
> [You replied too fast for me :-)]
> 
> I would love to get the regexps required to refactor PVE according to
> these specs...

FWIW, the generalized form I'm thinking of would allow multiple 
cascaded functions, so that

   {(toupper)(date "%b %Y") 20020106 }

would become

   JANUARY 2006

So, the regexp to find and replace this becomes something like:

    preg_replace('/\\{(\\(\\w[^)]+\\)*)([^}]*)\\}/e', 
                 "ApplyFunctions(PSS('$1'), PSS('$2'))", $x, $match)

where we then parse out the first argument by parens
parens to get the functions and arguments being applied:

    function ApplyFunctions($fnlist, $text) {
      preg_match_all('/\\((\\w+)([^)]*)\\)/', $fnlist, $functions)
      // $functions has the list of functions names and their arguments...
     
Pm




More information about the pmwiki-users mailing list