[Python-Dev] A standard lexer?
Fredrik Lundh" <firstname.lastname@example.org
Mon, 3 Jul 2000 00:35:28 +0200
> > for phrase, action in lexicon:
> > p.append("(?:%s)(?P#%d)" % (phrase, len(p)))
> How about instead enhancing existing (?P<name>pattern) notation, to =
> 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.