44
55#include "tokenizer.h"
66#include "reader.h"
7- #include "reader_internal.h"
87#include "../lexer/state.h"
98
109_PyTokenizer_Info
1110_PyTokenizer_GetInfo (const struct tok_state * tok )
1211{
1312 _PyTokenizer_Info info = {
1413 .status = tok -> done ,
14+ .diagnostic = tok -> diagnostic ,
1515 .location = {tok -> lineno , tok -> line_start < 0
1616 ? -1 : (int )(tok -> cur - tok -> line_start )},
1717 .cursor = tok -> cur ,
@@ -20,7 +20,7 @@ _PyTokenizer_GetInfo(const struct tok_state *tok)
2020 .level = tok -> level ,
2121 .delimiter_loc = {-1 , -1 },
2222 .in_formatted_string = tok -> ftstring_depth != 0 ,
23- .is_interactive = tok -> reader -> kind == _PYTOK_READER_INTERACTIVE ,
23+ .is_interactive = _PyTok_ReaderIsInteractive ( tok ) ,
2424 .is_file = tok -> fp != NULL && tok -> fp != stdin ,
2525 .filename = tok -> filename ,
2626 .module = tok -> module ,
@@ -81,32 +81,7 @@ const char *
8181_PyTokenizer_LineView (const struct tok_state * tok , Py_ssize_t lineno ,
8282 Py_ssize_t * length )
8383{
84- const char * line = _PyTokenizer_RetainedSource (tok );
85- if (line == NULL ) {
86- line = _PyLexer_BufferPointer (tok , tok -> buf_offset );
87- }
88- for (Py_ssize_t i = 1 ; i < lineno ; i ++ ) {
89- const char * next = strchr (line , '\n' );
90- if (next == NULL ) {
91- break ;
92- }
93- line = next + 1 ;
94- }
95- const char * end = strchr (line , '\n' );
96- * length = end != NULL ? end - line : (Py_ssize_t )strlen (line );
97- return line ;
98- }
99-
100- const char *
101- _PyTokenizer_RetainedSource (const struct tok_state * tok )
102- {
103- if (tok -> reader -> kind == _PYTOK_READER_PREPARED ) {
104- return _PyTok_SourceData (& tok -> source );
105- }
106- if (tok -> reader -> kind == _PYTOK_READER_INTERACTIVE ) {
107- return tok -> source .bytes ;
108- }
109- return NULL ;
84+ return _PyTok_SourceLineView (& tok -> source , lineno , length );
11085}
11186
11287void
0 commit comments