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:
- ParseIterable and ParseIterator: Lazily parse contiguous matches from an in-memory string.
- StreamParserExtension.parseIterable: Constructs a ParseIterable directly from a parser.
- StreamParserExtension.parseStream: Emits parsed matches from an in-memory string as an asynchronous Stream.
- StreamParserExtension.parseStreamChunks and ParseStreamStringExtension.parseWith: Transform a chunked Stream of String into parsed elements across chunk boundaries.
- ParseDecoder and ParseDecoderSink: Standard Converter and StringConversionSinkBase for chunked stream conversion.
- ParseMatchCallback, ParseErrorCallback, and ParseCloseCallback: Callback types for observing matches, errors, and completion.
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
Rcontiguously. -
ParseIterable<
R> -
An Iterable that parses contiguous results of type
Rfrom an input String. -
ParseIterator<
R> -
An Iterator that parses contiguous results of type
Rfrom 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.