diff options
author | ptmcg <ptmcg@austin.rr.com> | 2023-05-04 03:11:59 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2023-05-04 03:11:59 -0500 |
commit | fa12321610037188f9043323ad580b922726831d (patch) | |
tree | 036e8dc354c59269fc08583b3e30543999f6a35b /examples/cpp_enum_parser.py | |
parent | 6f3d0af494c4d52e979414f8f0f3b4d068b44d8e (diff) | |
download | pyparsing-git-fa12321610037188f9043323ad580b922726831d.tar.gz |
Updated several examples to latest method names
Diffstat (limited to 'examples/cpp_enum_parser.py')
-rw-r--r-- | examples/cpp_enum_parser.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/examples/cpp_enum_parser.py b/examples/cpp_enum_parser.py index 26dde7c..77eb3a7 100644 --- a/examples/cpp_enum_parser.py +++ b/examples/cpp_enum_parser.py @@ -9,7 +9,7 @@ #
#
-from pyparsing import *
+import pyparsing as pp
# sample string with enums and other stuff
sample = """
@@ -35,19 +35,19 @@ sample = """ """
# syntax we don't want to see in the final parse tree
-LBRACE, RBRACE, EQ, COMMA = map(Suppress, "{}=,")
-_enum = Suppress("enum")
-identifier = Word(alphas, alphanums + "_")
-integer = Word(nums)
-enumValue = Group(identifier("name") + Optional(EQ + integer("value")))
-enumList = Group(enumValue + ZeroOrMore(COMMA + enumValue))
+LBRACE, RBRACE, EQ, COMMA = pp.Suppress.using_each("{}=,")
+_enum = pp.Suppress("enum")
+identifier = pp.Word(pp.alphas + "_", pp.alphanums + "_")
+integer = pp.Word(pp.nums)
+enumValue = pp.Group(identifier("name") + pp.Optional(EQ + integer("value")))
+enumList = pp.Group(enumValue + (COMMA + enumValue)[...])
enum = _enum + identifier("enum") + LBRACE + enumList("names") + RBRACE
# find instances of enums ignoring other syntax
-for item, start, stop in enum.scanString(sample):
- id = 0
+for item, start, stop in enum.scan_string(sample):
+ idx = 0
for entry in item.names:
if entry.value != "":
- id = int(entry.value)
- print("%s_%s = %d" % (item.enum.upper(), entry.name.upper(), id))
- id += 1
+ idx = int(entry.value)
+ print("%s_%s = %d" % (item.enum.upper(), entry.name.upper(), idx))
+ idx += 1
|