[Python-Dev] A standard lexer?

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Mon, 3 Jul 2000 00:35:28 +0200

tim wrote:
> >         for phrase, action in lexicon:
> >             p.append("(?:%s)(?P#%d)" % (phrase, len(p)))
> How about instead enhancing existing (?P<name>pattern) notation, to =
set a
> new match object attribute to name if & when pattern matches?  Then
> arbitrary info associated with a named pattern can be gotten at via =
> via the pattern name, & the whole mess should be more readable.

I just added "lastindex" and "lastgroup" attributes to the match object.

"lastindex" is the integer index of the last matched capturing group,
"lastgroup" the corresponding name (or None, if the group didn't have
a name).  both attributes are None if no group were matched.