Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')")
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
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