summaryrefslogtreecommitdiff
path: root/examples/parsePythonValue.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2020-04-26 10:33:12 -0500
committerptmcg <ptmcg@austin.rr.com>2020-04-26 10:33:12 -0500
commit203fa36d7ae6b79344e4bf13531b77c09f313793 (patch)
tree443459f498f38b97618344c6f707eeaa117cf670 /examples/parsePythonValue.py
parent813ba3bed433a96e02d82cad2e2940a6850d96a5 (diff)
downloadpyparsing-git-203fa36d7ae6b79344e4bf13531b77c09f313793.tar.gz
change some lambdas to explicit methods for clarity (see discussion in #207); deleted duplicated examples (commit *all* changes this time)
Diffstat (limited to 'examples/parsePythonValue.py')
-rw-r--r--examples/parsePythonValue.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/examples/parsePythonValue.py b/examples/parsePythonValue.py
index 6a75d48..47f9102 100644
--- a/examples/parsePythonValue.py
+++ b/examples/parsePythonValue.py
@@ -23,16 +23,16 @@ tupleStr = pp.Forward()
listStr = pp.Forward()
dictStr = pp.Forward()
-pp.unicodeString.setParseAction(lambda t: t[0][2:-1])
-pp.quotedString.setParseAction(lambda t: t[0][1:-1])
-boolLiteral = pp.oneOf("True False").setParseAction(cvtBool)
-noneLiteral = pp.Literal("None").setParseAction(pp.replaceWith(None))
+unistr = pp.unicodeString().setParseAction(lambda t: t[0][2:-1])
+quoted_str = pp.quotedString().setParseAction(lambda t: t[0][1:-1])
+boolLiteral = pp.oneOf("True False", asKeyword=True).setParseAction(cvtBool)
+noneLiteral = pp.Keyword("None").setParseAction(pp.replaceWith(None))
listItem = (
real
| integer
- | pp.quotedString
- | pp.unicodeString
+ | quoted_str
+ | unistr
| boolLiteral
| noneLiteral
| pp.Group(listStr)
@@ -40,18 +40,18 @@ listItem = (
| dictStr
)
-tupleStr << (
+tupleStr <<= (
lparen + pp.Optional(pp.delimitedList(listItem)) + pp.Optional(comma) + rparen
)
tupleStr.setParseAction(cvtTuple)
-listStr << (
+listStr <<= (
lbrack + pp.Optional(pp.delimitedList(listItem) + pp.Optional(comma)) + rbrack
)
listStr.setParseAction(cvtList, lambda t: t[0])
dictEntry = pp.Group(listItem + colon + listItem)
-dictStr << (
+dictStr <<= (
lbrace + pp.Optional(pp.delimitedList(dictEntry) + pp.Optional(comma)) + rbrace
)
dictStr.setParseAction(cvtDict)