summaryrefslogtreecommitdiff
path: root/examples/builtin_parse_action_demo.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/builtin_parse_action_demo.py')
-rw-r--r--examples/builtin_parse_action_demo.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/examples/builtin_parse_action_demo.py b/examples/builtin_parse_action_demo.py
index 36b3a98..fed6e2a 100644
--- a/examples/builtin_parse_action_demo.py
+++ b/examples/builtin_parse_action_demo.py
@@ -5,14 +5,13 @@
# Simple example of using builtin functions as parse actions.
#
-from pyparsing import *
-
-integer = Word(nums).setParseAction(lambda t: int(t[0]))
+import pyparsing as pp
+ppc = pp.common
# make an expression that will match a list of ints (which
# will be converted to actual ints by the parse action attached
# to integer)
-nums = OneOrMore(integer)
+nums = ppc.integer[...]
test = "2 54 34 2 211 66 43 2 0"
@@ -20,10 +19,9 @@ print(test)
# try each of these builtins as parse actions
for fn in (sum, max, min, len, sorted, reversed, list, tuple, set, any, all):
- fn_name = fn.__name__
if fn is reversed:
# reversed returns an iterator, we really want to show the list of items
fn = lambda x: list(reversed(x))
# show how each builtin works as a free-standing parse action
- print(fn_name, nums.setParseAction(fn).parseString(test))
+ print(fn.__name__, nums.set_parse_action(fn).parse_string(test))