[Pyre2-devel] compile functions
Status: Beta
Brought to you by:
ottrey
|
From: <ot...@py...> - 2005-04-05 05:07:18
|
I've checked in the new compile functions change.
ie. The code no longer tries to magically search for the functions in the
calling frame - now they must be explicitly passed in to the compile()
function as keyword arguments. Which IMO is a lot easier for the user
to understand and therefore trust and use.
So now functions (until we think up a better name for "functions") are
passed in as keyword arguments to compile() like this:
>>> from string import upper
>>> buf=3D'0x0C drummers drumming, 0x0B pipers piping, 0x0A lords a-leaping'
>>> regex=3D'(?P<verse>(?P<number:int_16>0x[\dA-F]+) \
... (?P<activity:upper>[^,]+))(,)?'
>>> pat=3Dre.compile(regex, int_16=3Dlambda x: int(x, 16), upper=3Dupper)
>>> pat.extract(buf)
[{'number': 12, 'activity': 'DRUMMERS DRUMMING'}, {'number': 11,
'activity':
'PIPERS PIPING'}, {'number': 10, 'activity': 'LORDS A-LEAPING'}]
(BTW I'm not ~requiring~ builtin functions like "int()" to be passed
in, they are still being retrieved from __builtins__.)
I've also updated the wiki and the sourceforge website.
I wont bother making a new sourceforge release because A: the sourceforge
file release system is a major pain to work with and B: no one seems to
have downloaded this "work in progress" yet and anyway. ;-)
Chris.
|