summaryrefslogtreecommitdiff
path: root/src/examples/groupUsingListAllMatches.py
blob: 28cdfd61abacc5cc4d2e1cdc4fb92c9c63a21116 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
# A simple example showing the use of the implied listAllMatches=True for
# results names with a trailing '*' character.
#
# This example performs work similar to itertools.groupby, but without
# having to sort the input first.
#
# Copyright 2004-2016, by Paul McGuire
#
from pyparsing import Word, ZeroOrMore, nums

aExpr = Word("A", nums)
bExpr = Word("B", nums)
cExpr = Word("C", nums)
grammar = ZeroOrMore(aExpr("A*") | bExpr("B*") | cExpr("C*"))

grammar.runTests("A1 B1 A2 C1 B2 A3")