How to use the parsita.state.Continue 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.assertNotEqual(succ, fail)

        read = SequenceReader([1, 2, 3])
        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')")
github drhagen / parsita / examples / positioned.py View on Github external
def consume(self, reader: Reader[Input]) -> Status[Input, Output]:
        start = reader.position
        status = self.parser.consume(reader)

        if isinstance(status, Continue):
            end = status.remainder.position
            return Continue(status.remainder, status.value.set_position(start, end - start)).merge(status)
        else:
            return status
github drhagen / parsita / examples / positioned.py View on Github external
def consume(self, reader: Reader[Input]) -> Status[Input, Output]:
        start = reader.position
        status = self.parser.consume(reader)

        if isinstance(status, Continue):
            end = status.remainder.position
            return Continue(status.remainder, status.value.set_position(start, end - start)).merge(status)
        else:
            return status

parsita

Parser combinator library for Python

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis