Mercurial > lbo > hg > pcombinators
changeset 38:74801fe3d0dc draft
arith_test: Fix Power parsing
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Thu, 23 May 2019 19:53:50 +0200 |
parents | 423f7851fe6d |
children | 8b9c4713b049 |
files | pcombinators/arith_test.py |
diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/pcombinators/arith_test.py Wed May 22 22:48:28 2019 +0200 +++ b/pcombinators/arith_test.py Thu May 23 19:53:50 2019 +0200 @@ -6,6 +6,7 @@ @author: lbo """ +from pcombinators.state import ParseState from pcombinators.combinators import * from pcombinators.primitives import * @@ -34,8 +35,11 @@ # Parse failed if not either 1 or 3. raise Exception("Parse failed: Missing operand") -def Power(): - return (OptimisticSequence(Atom(), Operator('^') + Atom()) >> operator_result_to_tuple) +class Power(): + + def parse(self, st): + p = OptimisticSequence(Atom(), Operator('^') + Power()) >> operator_result_to_tuple + return p.parse(st) class Product(Parser): @@ -61,7 +65,7 @@ def parse_and_print(expr): """Parse an expression string and return a string of the parsing result.""" - parsed, st = Term().parse(ps(expr)) + parsed, st = Term().parse(ParseState(expr)) if parsed is None: print('Parse error :(', st) return