Next / Previous / Contents / Shipman's homepage

6.13. oneOf(): Check for multiple literals, longest first

pp.oneOf(alternatives, caseless=False)

This function returns a parser that matches one of a set of literals. In particular, if any literal is a substring of another, this parser will always check for the longer one first; this behavior is useful, for example, when you are parsing a set of keywords.

>>> keyList = pp.oneOf('as assert break')
>>> print keyList.parseString('assert yes')
>>> print keyList.parseString('as read')