From f241d4ca62483ed83014d7fac49ef5445343a8c6 Mon Sep 17 00:00:00 2001 From: Mike Urbach Date: Wed, 19 Jul 2023 22:21:33 -0600 Subject: [PATCH] Update grammar.py to work with the latest pyparsing. --- pydevicetree/source/grammar.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pydevicetree/source/grammar.py b/pydevicetree/source/grammar.py index cabf917..f9c244f 100644 --- a/pydevicetree/source/grammar.py +++ b/pydevicetree/source/grammar.py @@ -17,7 +17,10 @@ cache_bound = int(option) except ValueError: print("%s requires a valid integer" % ENV_CACHE_OPTION, file=sys.stderr) -p.ParserElement.enablePackrat(cache_bound) + +# Don't typecheck this line, because the type annotation for enable_packrat is +# incorrect, and won't accept None, even though this is allowed and documented. +p.ParserElement.enable_packrat(cache_bound) # type: ignore node_name = p.Word(p.alphanums + ",.-+_") ^ p.Literal("/") integer = p.pyparsing_common.integer ^ (p.Literal("0x").suppress() + p.pyparsing_common.hex_integer) @@ -43,7 +46,7 @@ arith_expr = p.Forward() ternary_element = arith_expr ^ integer ternary_expr = ternary_element + p.Literal("?") + ternary_element + p.Literal(":") + ternary_element -arith_expr = p.nestedExpr(content=(p.OneOrMore(operator ^ integer) ^ ternary_expr)) +arith_expr <<= p.nestedExpr(content=(p.OneOrMore(operator ^ integer) ^ ternary_expr)) cell_array = p.Literal("<").suppress() + \ p.ZeroOrMore(integer ^ arith_expr ^ string ^ reference ^ label_creation.suppress()) + \ @@ -52,8 +55,8 @@ (p.OneOrMore(p.Word(p.hexnums, exact=2) ^ label_creation.suppress())) + \ p.Literal("]").suppress() property_values = p.Forward() -property_values = p.delimitedList(property_values ^ cell_array ^ bytestring ^ stringlist ^ \ - reference) +property_values <<= p.delimitedList(property_values ^ cell_array ^ bytestring ^ stringlist ^ \ + reference) property_assignment = property_name("property_name") + p.Optional(p.Literal("=").suppress() + \ (property_values)).setResultsName("value") + p.Literal(";").suppress()