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 *
@@ -19,13 +33,7 @@ _PyToken_TextView(const struct tok_state *tok, const struct token *token,
1933 * length = 0 ;
2034 return "" ;
2135 }
22- assert (_PyTok_SpanIsValid (token -> span ));
23- assert (tok -> buf != NULL );
24- assert (tok -> inp >= tok -> buf );
25- assert (token -> span .start >= tok -> buf_offset );
26- assert (token -> span .end - tok -> buf_offset <= tok -> inp - tok -> buf );
27- * length = token -> span .end - token -> span .start ;
28- return tok -> buf + (token -> span .start - tok -> buf_offset );
36+ return _PyLexer_SpanView (tok , token -> span , length );
2937}
3038
3139#endif
0 commit comments