Skip to content

Commit 6ddaccd

Browse files
committed
document .span() and SourceSpan
1 parent 554b0c8 commit 6ddaccd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/ref/methods_and_combinators.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,20 @@ can be used and manipulated as below.
401401
</howto/lexing/>` and want subsequent parsing of the token stream to be
402402
able to report original positions in error messages etc.
403403

404+
.. method:: span()
405+
406+
Returns a parser that augments the initial parser's result with a :class:`SourceSpan`
407+
containing information about where that parser started and stopped within the
408+
source data. The new value is a tuple:
409+
410+
.. code:: python
411+
412+
(source_span, original_value)
413+
414+
This enables reporting of custom errors involving source locations, such as when
415+
using parsy as a :doc:`lexer</howto/lexing/>` or when building a syntax tree that will be
416+
further analyzed.
417+
404418
.. _operators:
405419

406420
Parser operators
@@ -607,3 +621,9 @@ Auxiliary data structures
607621
.. method:: __init__(data, [source=None])
608622
609623
Wraps the data into a stream, possibly equipping it with a source.
624+
625+
.. class:: SourceSpan
626+
627+
Identifies a span of material from the data being parsed by its start row and column and its end
628+
row and column. If the data stream was equipped with a source, that value is also available in
629+
this object.

0 commit comments

Comments
 (0)