Re: An alternative to sufreplace
Bram Moolenaar <[email protected]>
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
Adriaan de Groot wrote:
> The attached patch adds suffixmangle() to the library of AAP-specific
> Python functions. It acts like a kind of list-lifted sufreplace() -
> you give it a list of replacements and it does them. The calling form
> is
>
> suffixmangle(recdict,variablename,replacementlist)
>
> typically, recdict will be _recipe when calling suffixmangle.
> variablename is the _name_ of a variable - not it's value. So use
> "source", not source, when calling this. Actually, I don't even know
> if "source" is in there - use "SOURCES", or whatever you named the
> variable that stores the list of interesting files, instead.
> replacementlist is a list of pairs (suffix,new suffix), and if a
> suffix matches, that suffix is replaced by the new suffix. The first
> match wins.
>
> Possible use is, say, to deal with "fake sources", or to change some
> filenames on the way:
>
> suffixmangle(_recipe,"SOURCES",[ (".y","_"+OSNAME+".y") ])
>
> this would replace all .y by _OSNAME.y in your list of sources, which
> would let you list one source name but have it replaced at AAP runtime
> by another.
>
> A previous version I mentioned removed attributes. As Bram pointed
> out, using var2dictlist fixes that. This version preserves attributes.
The functionality of this function comes very close to sufreplace().
It's not clear to me why you want it to work differently.
You pass the recdict and variable name. But you only use these to
obtain the value of the variable. So why not pass the value directly?
This allows using an expression intead of a variable.
Passing a list of tuples makes it very Pythonesque. Just passing a
"from" suffix and a "to" soffix makes it much easier to use for people
who don't know Python syntax that well. What would the use of the list
be? Is there a situation where you can't do it by calling
suffixmangle() for each suffix in the list?
--
hundred-and-one symptoms of being an internet addict:
150. You find yourself counting emoticons to get to sleep.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
\\\ Project leader for A-A-P -- http://www.A-A-P.org ///
\\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01