diff options
| author | ptmcg <ptmcg@austin.rr.com> | 2022-07-12 02:38:08 -0500 |
|---|---|---|
| committer | ptmcg <ptmcg@austin.rr.com> | 2022-07-12 02:38:08 -0500 |
| commit | c74949d0cafbe7c136a54777b9b340c37f00b484 (patch) | |
| tree | 51ca330cc1adbafbc3670032b6d0f3bd9a0c0b07 /examples/rosettacode.py | |
| parent | 905c7efde425eb2c406035c595258e6203ea714a (diff) | |
| download | pyparsing-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.py | 63 |
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 |
