33
44#include "state.h"
55
6- int _PyLexer_update_ftstring_expr (struct tok_state * tok , char cur );
7-
86int _PyTokenizer_Get (struct tok_state * , struct token * );
97
8+ static inline const char *
9+ _PyLexer_SpanView (const struct tok_state * tok , _PyTok_Span span ,
10+ Py_ssize_t * length )
11+ {
12+ assert (length != NULL );
13+ assert (_PyTok_SpanIsValid (span ));
14+ assert (tok -> buf != NULL );
15+ assert (tok -> inp >= tok -> buf );
16+ if (span .start >= tok -> buf_offset &&
17+ span .end - tok -> buf_offset <= tok -> inp - tok -> buf ) {
18+ * length = span .end - span .start ;
19+ return tok -> buf + (span .start - tok -> buf_offset );
20+ }
21+ return _PyTok_SourceSpanView (& tok -> source , span , length );
22+ }
23+
1024/* The view points into the current input window. The next
1125 _PyTokenizer_Get() call may discard it. */
1226static inline const char *
@@ -18,12 +32,7 @@ _PyToken_TextView(const struct tok_state *tok, const struct token *token,
1832 * length = 0 ;
1933 return "" ;
2034 }
21- assert (tok -> buf != NULL );
22- assert (tok -> inp >= tok -> buf );
23- assert (token -> span .start >= tok -> buf_offset );
24- assert (token -> span .end - tok -> buf_offset <= tok -> inp - tok -> buf );
25- * length = token -> span .end - token -> span .start ;
26- return tok -> buf + (token -> span .start - tok -> buf_offset );
35+ return _PyLexer_SpanView (tok , token -> span , length );
2736}
2837
2938#endif
0 commit comments