55
66typedef Py_ssize_t _PyTok_Off ;
77
8+ /* Half-open byte offsets into a _PyTok_SourceText. */
89typedef struct {
910 _PyTok_Off start ;
1011 _PyTok_Off end ;
1112} _PyTok_Span ;
1213
14+ /* Lines are 1-based and byte columns are 0-based. */
1315typedef struct {
1416 int lineno ;
1517 int byte_col ;
@@ -20,6 +22,7 @@ typedef enum {
2022 _PYTOK_AFFINITY_RIGHT ,
2123} _PyTok_Affinity ;
2224
25+ /* The half-open range includes the terminating newline when present. */
2326typedef struct {
2427 _PyTok_Off start ;
2528 _PyTok_Off end ;
@@ -39,19 +42,27 @@ typedef struct {
3942} _PyTok_SourceText ;
4043
4144PyAPI_FUNC (void ) _PyTok_SourceInit (_PyTok_SourceText * );
42- /* Clear invalidates all cursors and span views for the source. */
45+ /* Clear invalidates all cursors, spans, and views for the source. */
4346PyAPI_FUNC (void ) _PyTok_SourceClear (_PyTok_SourceText * );
44- /* Append one logical line. The implicit_newline flag means that its newline
45- terminator was synthesized. The input must not point into source storage. */
47+ /* Append one nonempty logical line and return its start offset. The input may
48+ contain one newline, as its final byte. An unterminated line must be the
49+ final line. implicit_newline means that the final newline was synthesized.
50+ The input must not point into source storage. */
4651PyAPI_FUNC (_PyTok_Off ) _PyTok_SourceAppendLine (
4752 _PyTok_SourceText * source , const char * bytes , Py_ssize_t len ,
4853 int implicit_newline );
4954/* The returned view is invalidated by SourceAppendLine and SourceClear. */
5055PyAPI_FUNC (const char * ) _PyTok_SourceSpanView (
5156 const _PyTok_SourceText * , _PyTok_Span , Py_ssize_t * );
57+ /* Look up a 1-based line. Empty and newline-terminated sources have an empty
58+ virtual line at EOF. */
5259PyAPI_FUNC (int ) _PyTok_SourceLine (
5360 const _PyTok_SourceText * , int , _PyTok_Line * );
54- /* At a line boundary, affinity selects the preceding or following line. */
61+ /* Return false for invalid line numbers and the virtual EOF line. */
62+ PyAPI_FUNC (int ) _PyTok_SourceLineIsImplicit (
63+ const _PyTok_SourceText * , int );
64+ /* At a line boundary, left affinity selects the preceding line at its end;
65+ right affinity selects the following line at byte column zero. */
5566PyAPI_FUNC (int ) _PyTok_SourceLocation (
5667 const _PyTok_SourceText * , _PyTok_Off , _PyTok_Affinity , _PyTok_Loc * );
5768
0 commit comments