summaryrefslogtreecommitdiff
path: root/src/examples/listAllMatches.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2015-12-31 00:55:47 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2015-12-31 00:55:47 +0000
commit92562084aa4c90ac21dc868edb12c8f6c0cf1a2b (patch)
tree9570287813d7358750ddd1ffe50ba60c0a999972 /src/examples/listAllMatches.py
parent289665740e0bbd7b752d6bcb83a0da9ea331d5c2 (diff)
downloadpyparsing-92562084aa4c90ac21dc868edb12c8f6c0cf1a2b.tar.gz
Added new example parseTabularData.py
Updated several examples to more current Python and pyparsing practices (and better Py2/Py3 cross-compatibility) git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@309 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
Diffstat (limited to 'src/examples/listAllMatches.py')
-rw-r--r--src/examples/listAllMatches.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/examples/listAllMatches.py b/src/examples/listAllMatches.py
index 43f998b..1b1bdd4 100644
--- a/src/examples/listAllMatches.py
+++ b/src/examples/listAllMatches.py
@@ -12,13 +12,13 @@ nonAlphas = [ c for c in printables if not c.isalpha() ]
print("Extract vowels, consonants, and special characters from this test string:")
print("'" + test + "'")
-print()
+print('')
print("Define grammar using normal results names")
print("(only last matching symbol is saved)")
-vowels = oneOf(list("aeiouy"), caseless=True).setResultsName("vowels")
-cons = oneOf(list("bcdfghjklmnpqrstvwxz"), caseless=True).setResultsName("cons")
-other = oneOf(list(nonAlphas)).setResultsName("others")
+vowels = oneOf(list("aeiouy"), caseless=True)("vowels")
+cons = oneOf(list("bcdfghjklmnpqrstvwxz"), caseless=True)("cons")
+other = oneOf(nonAlphas)("others")
letters = OneOrMore(cons | vowels | other) + StringEnd()
results = letters.parseString(test)
@@ -26,27 +26,27 @@ print(results)
print(results.vowels)
print(results.cons)
print(results.others)
-print()
+print('')
print("Define grammar using results names, with listAllMatches=True")
print("(all matching symbols are saved)")
-vowels = oneOf(list("aeiouy"), caseless=True).setResultsName("vowels",listAllMatches=True)
-cons = oneOf(list("bcdfghjklmnpqrstvwxz"), caseless=True).setResultsName("cons",listAllMatches=True)
-other = oneOf(list(nonAlphas)).setResultsName("others",listAllMatches=True)
+vowels = oneOf(list("aeiouy"), caseless=True)("vowels*")
+cons = oneOf(list("bcdfghjklmnpqrstvwxz"), caseless=True)("cons*")
+other = oneOf(nonAlphas)("others*")
-letters = OneOrMore(cons | vowels | other) + StringEnd()
+letters = OneOrMore(cons | vowels | other)
-results = letters.parseString(test)
+results = letters.parseString(test, parseAll=True)
print(results)
-print(sorted(list(set(results))))
-print()
+print(sorted(set(results)))
+print('')
print(results.vowels)
-print(sorted(list(set(results.vowels))))
-print()
+print(sorted(set(results.vowels)))
+print('')
print(results.cons)
-print(sorted(list(set(results.cons))))
-print()
+print(sorted(set(results.cons)))
+print('')
print(results.others)
-print(sorted(list(set(results.others))))
+print(sorted(set(results.others)))