Repository navigation
Expand file tree
/
Copy pathapi.c
More file actions
162 lines (147 loc) · 4.15 KB
/
Copy pathapi.c
File metadata and controls
162 lines (147 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "Python.h"
#include "errcode.h"
#include "pycore_token.h"
#include "tokenizer.h"
#include "reader.h"
#include "reader_internal.h"
#include "../lexer/state.h"
int
_PyTokenizer_GetStatus(const struct tok_state *tok)
{
return tok->done;
}
int
_PyTokenizer_GetNewlineRequirements(const struct tok_state *tok)
{
return tok->needs_newline;
}
_PyTokenizer_Info
_PyTokenizer_GetInfo(const struct tok_state *tok)
{
_PyTokenizer_Info info = {
.status = tok->done,
.implicit_newline = tok->implicit_newline,
.diagnostic = tok->diagnostic,
.location = {tok->lineno, tok->line_start < 0
? -1 : (int)(tok->cur - tok->line_start)},
.cursor = tok->cur,
.input_span = {tok->buf_offset, tok->inp},
.line_span = {tok->line_start, tok->inp},
.level = tok->level,
.delimiter_loc = {-1, -1},
.in_formatted_string = tok->ftstring_depth != 0,
.is_interactive = _PyTok_ReaderIsInteractive(tok),
.is_file = tok->reader->fp != NULL && tok->reader->fp != stdin,
.filename = tok->filename,
.module = tok->module,
.encoding = tok->reader->encoding,
};
if (tok->level > 0) {
int level = tok->level - 1;
info.delimiter = tok->parenstack[level];
info.delimiter_loc = (_PyTok_Loc){
tok->parenlinenostack[level], tok->parencolstack[level]};
}
return info;
}
const char *
_PyToken_TextView(const struct tok_state *tok, const struct token *token,
Py_ssize_t *length)
{
assert(length != NULL);
if (token->span.start < 0) {
assert(token->span.start == -1 && token->span.end == -1);
*length = 0;
return "";
}
return _PyTok_SourceSpanView(&tok->source, token->span, length);
}
const char *
_PyTokenizer_SpanView(const struct tok_state *tok, _PyTok_Span span,
Py_ssize_t *length)
{
return _PyTok_SourceSpanView(&tok->source, span, length);
}
void
_PyToken_GetView(const struct tok_state *tok, const struct token *token,
_PyToken_View *view)
{
assert(view != NULL);
view->text = _PyToken_TextView(tok, token, &view->length);
view->end_line_start = tok->line_start;
view->line_span = (_PyTok_Span){
ISSTRINGLIT(token->type)
? token->span.start - token->start_loc.byte_col : tok->line_start,
tok->inp,
};
view->implicit_newline = tok->implicit_newline;
view->at_eof = tok->done == E_EOF;
}
const char *
_PyTokenizer_LineView(const struct tok_state *tok, Py_ssize_t lineno,
Py_ssize_t *length)
{
return _PyTok_SourceLineView(&tok->source, lineno, length);
}
void
_PyTokenizer_SetContext(struct tok_state *tok, PyObject *filename,
PyObject *module)
{
Py_XINCREF(filename);
Py_XINCREF(module);
Py_XSETREF(tok->filename, filename);
Py_XSETREF(tok->module, module);
}
void
_PyTokenizer_SetOptions(struct tok_state *tok, int extra_tokens,
int type_comments)
{
tok->tok_extra_tokens = extra_tokens;
tok->type_comments = type_comments;
}
void
_PyTokenizer_ImplyDedents(struct tok_state *tok)
{
_PyLexer_ImplyDedents(tok);
}
void
_PyTokenizer_AllowIncompleteInput(struct tok_state *tok, int allow)
{
tok->allow_incomplete_input = allow != 0;
}
int
_PyTokenizer_HasTrailingStatement(const struct tok_state *tok)
{
_PyTok_Off cur = tok->cur;
_PyTok_Off end = tok->source.base_offset + tok->source.len;
while (cur < end) {
int c = _PyTok_SourceByte(&tok->source, cur++);
if (c == '\0') {
return 0;
}
if (c == ' ' || c == '\t' || c == '\n' || c == '\014') {
continue;
}
if (c != '#') {
return 1;
}
while (cur < end) {
c = _PyTok_SourceByte(&tok->source, cur);
if (c == '\0' || c == '\n') {
break;
}
cur++;
}
}
return 0;
}
int
_PyTokenizer_IsInteractive(const struct tok_state *tok)
{
return _PyTok_ReaderIsInteractive(tok);
}
void
_PyTokenizer_StopInteractive(struct tok_state *tok)
{
_PyTok_ReaderStopInteractive(tok);
}