2 Jul
2000
2 Jul
'00
3:35 p.m.
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 dicts 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. </F>