Skip to content

Commit b81c83b

Browse files
committed
document Stream
1 parent 114e5ef commit b81c83b

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

docs/ref/methods_and_combinators.rst

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ can be used and manipulated as below.
2323
The following methods are for actually **using** the parsers that you have
2424
created:
2525

26-
.. method:: parse(string_or_list)
26+
.. method:: parse(stream)
2727

28-
Attempts to parse the given string (or list). If the parse is successful
29-
and consumes the entire string, the result is returned - otherwise, a
28+
Attempts to parse the given :class:`Stream` of data. If the parse is successful
29+
and consumes the entire stream, the result is returned - otherwise, a
3030
``ParseError`` is raised.
3131

32-
Instead of passing a string, you can in fact pass a list of tokens. Almost
33-
all the examples assume strings for simplicity. Some of the primitives are
32+
Most commonly, a stream simply wraps a string, but you could use a list of tokens instead.
33+
Almost all the examples assume strings for simplicity. Some of the primitives are
3434
also clearly string specific, and a few of the combinators (such as
3535
:meth:`Parser.concat`) are string specific, but most of the rest of the
3636
library will work with tokens just as well. See :doc:`/howto/lexing` for
3737
more information.
3838

39-
.. method:: parse_partial(string_or_list)
39+
.. method:: parse_partial(stream)
4040

4141
Similar to ``parse``, except that it does not require the entire
42-
string (or list) to be consumed. Returns a tuple of
42+
stream to be consumed. Returns a tuple of
4343
``(result, remainder)``, where ``remainder`` is the part of
44-
the string (or list) that was left over.
44+
the stream that was left over.
4545

4646
The following methods are essentially **combinators** that produce new
4747
parsers from the existing one. They are provided as methods on ``Parser`` for
@@ -594,3 +594,16 @@ Parsy does not try to include every possible combinator - there is no reason why
594594
you cannot create your own for your needs using the built-in combinators and
595595
primitives. If you find something that is very generic and would be very useful
596596
to have as a built-in, please :doc:`submit </contributing>` as a PR!
597+
598+
Auxiliary data structures
599+
=========================
600+
601+
.. class:: Stream
602+
603+
Wraps a string, byte sequence, or list, possibly equipping it with a source.
604+
If the data is loaded from a file or URL, the source should be that file path or URL.
605+
The source name is used in generated parse error messages.
606+
607+
.. method:: __init__(data, [source=None])
608+
609+
Wraps the data into a stream, possibly equipping it with a source.

0 commit comments

Comments
 (0)