Skip to content

Commit

Permalink
Update grammar.py to work with the latest pyparsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeurbach committed Jul 20, 2023
1 parent f8ff165 commit f241d4c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pydevicetree/source/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()) + \
Expand All @@ -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()

Expand Down

0 comments on commit f241d4c

Please sign in to comment.