How to use the parsita.state.Backtrack function in parsita

To help you get started, we’ve selected a few parsita examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drhagen / parsita / tests / test_state.py View on Github external
self.assertEqual(read.first, 1)
        self.assertEqual(read.rest.first, 2)
        self.assertEqual(str(read), 'Reader(1@0)')
        self.assertEqual(str(read.rest.rest.rest), 'Reader(finished)')

        read = StringReader('a b')
        self.assertEqual(read.first, 'a')
        self.assertEqual(read.rest.first, ' ')
        self.assertEqual(str(read), 'StringReader(a@0)')
        self.assertEqual(str(read.rest.rest.rest), 'StringReader(finished)')

        cont = Continue(read, 40)
        self.assertEqual(cont.value, 40)
        self.assertEqual(str(cont), 'Continue(40, StringReader(a@0))')

        back = Backtrack(read, lambda: 'no further')
        self.assertEqual(back.expected[0](), 'no further')
        self.assertEqual(str(back), "Backtrack(StringReader(a@0), ['no further'])")

        error = ParseError('Expected a but found b at index 0')
        self.assertEqual(str(error), 'Expected a but found b at index 0')
        self.assertEqual(repr(error), "ParseError('Expected a but found b at index 0')")

parsita

Parser combinator library for Python

MIT
Latest version published 26 days ago

Package Health Score

75 / 100
Full package analysis