Skip to content

Commit

Permalink
Fix some inconsistencies in random access docs.
Browse files Browse the repository at this point in the history
Closes #1920
  • Loading branch information
evantypanski committed Nov 11, 2024
1 parent 99049d8 commit 7fbb11a
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions doc/programming/parsing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1828,13 +1828,10 @@ control the current position:
Returns iterator to the current input position in the stream fed
into this unit.

For random access, you'd typically get the current position through
``input()``, subtract from it the desired number of bytes you want to
back, and then use ``set_input`` to establish that new position. By
further storing iterators as unit variables you can decouple these
steps and, e.g., remember a position to later come back to.

Here's an example that parses input data twice with different sub units:
You can achieve random access by saving an iterator from ``input()``
in a unit variable, then later return to that position by calling
``set_input()`` with that variable. Here's an example that parses
input data twice with different sub units:

.. spicy-code:: parse-random-access.spicy

Expand Down Expand Up @@ -1864,7 +1861,7 @@ Here's an example that parses input data twice with different sub units:
:exec: printf '\00\00\00\01' | spicy-driver %INPUT
:show-with: foo.spicy

If you look at output, you see that ``start`` iterator remembers it's
If you look at output, you see that ``start`` iterator remembers its
offset, relative to the global input stream. It would also show the
data at that offset if the parser had not already discarded that at
the time we print it out.
Expand Down

0 comments on commit 7fbb11a

Please sign in to comment.