Mercurial > lbo > hg > pcombinators
changeset 73:28e317b97a64 draft
Split parse function in arith module
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 25 May 2019 23:14:24 +0200 |
parents | 72fb4eb79973 |
children | 7532e67d2b2d |
files | pcombinators/tests/arith.py |
diffstat | 1 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/pcombinators/tests/arith.py Sat May 25 23:14:10 2019 +0200 +++ b/pcombinators/tests/arith.py Sat May 25 23:14:24 2019 +0200 @@ -66,10 +66,15 @@ assert len(tpl) == 3 return '({} {} {})'.format(pretty_print(tpl[0]), tpl[1], pretty_print(tpl[2])) +def parse(s): + if type(s) is str: + s = ParseState(s.replace(' ', '')) + parsed, st = Term().then_skip(EndOfInput()).parse(s) + if parsed is None: + print('Parse error :(', st) + return None + return parsed + def parse_and_print(expr): """Parse an expression string and return a string of the parsing result.""" - parsed, st = Term().parse(ParseState(expr.replace(' ', ''))) - if parsed is None: - print('Parse error :(', st) - return - return pretty_print(parsed) \ No newline at end of file + return pretty_print(parse(expr)) \ No newline at end of file