summaryrefslogtreecommitdiff
path: root/examples/rosettacode.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2022-07-12 02:38:08 -0500
committerptmcg <ptmcg@austin.rr.com>2022-07-12 02:38:08 -0500
commitc74949d0cafbe7c136a54777b9b340c37f00b484 (patch)
tree51ca330cc1adbafbc3670032b6d0f3bd9a0c0b07 /examples/rosettacode.py
parent905c7efde425eb2c406035c595258e6203ea714a (diff)
downloadpyparsing-git-c74949d0cafbe7c136a54777b9b340c37f00b484.tar.gz
Add delta_time, excelExpr, and rosettacode to test_examples.py
Diffstat (limited to 'examples/rosettacode.py')
-rw-r--r--examples/rosettacode.py63
1 files changed, 18 insertions, 45 deletions
diff --git a/examples/rosettacode.py b/examples/rosettacode.py
index fd3a0e0..6f2e6e7 100644
--- a/examples/rosettacode.py
+++ b/examples/rosettacode.py
@@ -50,46 +50,20 @@ integer = pp.pyparsing_common.integer
string = pp.QuotedString('"', convertWhitespaceEscapes=False).setName("quoted string")
char = pp.Regex(r"'\\?.'")
+# fmt: off
expr = pp.infixNotation(
identifier | integer | char,
[
- (
- pp.oneOf("+ - !"),
- 1,
- pp.opAssoc.RIGHT,
- ),
- (
- pp.oneOf("* / %"),
- 2,
- pp.opAssoc.LEFT,
- ),
- (
- pp.oneOf("+ -"),
- 2,
- pp.opAssoc.LEFT,
- ),
- (
- pp.oneOf("< <= > >="),
- 2,
- pp.opAssoc.LEFT,
- ),
- (
- pp.oneOf("== !="),
- 2,
- pp.opAssoc.LEFT,
- ),
- (
- pp.oneOf("&&"),
- 2,
- pp.opAssoc.LEFT,
- ),
- (
- pp.oneOf("||"),
- 2,
- pp.opAssoc.LEFT,
- ),
+ (pp.oneOf("+ - !"), 1, pp.opAssoc.RIGHT,),
+ (pp.oneOf("* / %"), 2, pp.opAssoc.LEFT, ),
+ (pp.oneOf("+ -"), 2, pp.opAssoc.LEFT, ),
+ (pp.oneOf("< <= > >="), 2, pp.opAssoc.LEFT, ),
+ (pp.oneOf("== !="), 2, pp.opAssoc.LEFT, ),
+ (pp.oneOf("&&"), 2, pp.opAssoc.LEFT, ),
+ (pp.oneOf("||"), 2, pp.opAssoc.LEFT, ),
],
)
+# fmt: on
prt_list = pp.Group(pp.delimitedList(string | expr))
paren_expr = pp.Group(LPAR + expr + RPAR)
@@ -300,15 +274,14 @@ tests = [
""",
]
-import sys
-sys.setrecursionlimit(2000)
+def main():
+ import sys
+ sys.setrecursionlimit(2000)
-for test in tests:
- try:
- results = code.parseString(test)
- except pp.ParseException as pe:
- pp.ParseException.explain(pe)
- else:
- results.pprint()
- print()
+ success, report = code.run_tests(tests)
+ assert success
+
+
+if __name__ == '__main__':
+ main() \ No newline at end of file