stream library

Streaming and iteration infrastructure for PetitParser.

This library provides tools for contiguous, lazy, and chunked parsing over in-memory String data and asynchronous Stream sources:

Matches must appear immediately adjacent without unparsed input between them; unmatched input triggers onError or throws a ParserException. For non-contiguous scanning across in-memory strings, use Parser.allMatches.

Chunked Stream Contract

Parsers that succeed at the end of a non-final chunk (such as greedy unbounded matchers without a closing boundary) emit immediately without waiting for subsequent chunks. Tokens that must not split across chunk boundaries should require an explicit closing delimiter or boundary, skipping grammars should avoid bare catch-all fallbacks (such as any()) after multi-chunk tokens, and parsers should not terminate with .end().

Classes

ParseDecoder<R>
A Converter that decodes a String or chunked String stream into lists of parsed elements of type R.
ParseDecoderSink<R>
A StringConversionSinkBase that decodes chunks of String into batches of R contiguously.
ParseIterable<R>
An Iterable that parses contiguous results of type R from an input String.
ParseIterator<R>
An Iterator that parses contiguous results of type R from an input String.

Extensions

ParseStreamStringExtension on Stream<String>
Extension on Stream<String> for fluent parser streaming.
StreamParserExtension on Parser<R>
Extension on Parser providing streaming and iteration capabilities.

Typedefs

ParseCloseCallback = void Function({required String buffer, required int position})
Callback invoked when iteration or stream conversion closes.
ParseErrorCallback = void Function(Failure failure)
Callback invoked when a parse failure occurs.
ParseMatchCallback<R> = void Function(R value, {required String buffer, required int start, required int stop})
Callback invoked when a match is produced during streaming or iteration.