From fa12321610037188f9043323ad580b922726831d Mon Sep 17 00:00:00 2001 From: ptmcg Date: Thu, 4 May 2023 03:11:59 -0500 Subject: Updated several examples to latest method names --- examples/cpp_enum_parser.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'examples/cpp_enum_parser.py') 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 -- cgit v1.2.1