Implementing User-Defined Patterns

Like the AndP/& example:

  • Define a subclass derived from "Pattern".

  • Define a "Match" method with one argument (other than "self") which is the input.

  • On success, advance the ".Pos" property of the input and return True.

  • On failure, return False.

New Models for Processing Text and XML with Python Sam Wilmott
Slide 22 of 51        www.wilmott.ca