/src/cpython/Parser/pegen.h
Line | Count | Source |
1 | | #ifndef PEGEN_H |
2 | | #define PEGEN_H |
3 | | |
4 | | #include <Python.h> |
5 | | #include <pycore_ast.h> |
6 | | #include <pycore_token.h> |
7 | | #include <pycore_ceval.h> // _Py_ReachedRecursionLimitWithMargin() |
8 | | #include <pycore_pystate.h> // _Py_get_machine_stack_pointer() |
9 | | #include <pycore_pythonrun.h> // _PyOS_STACK_MARGIN_BYTES |
10 | | |
11 | | #include "tokenizer/tokenizer.h" |
12 | | |
13 | | #if 0 |
14 | | #define PyPARSE_YIELD_IS_KEYWORD 0x0001 |
15 | | #endif |
16 | | |
17 | 0 | #define PyPARSE_DONT_IMPLY_DEDENT 0x0002 |
18 | | |
19 | | #if 0 |
20 | | #define PyPARSE_WITH_IS_KEYWORD 0x0003 |
21 | | #define PyPARSE_PRINT_IS_FUNCTION 0x0004 |
22 | | #define PyPARSE_UNICODE_LITERALS 0x0008 |
23 | | #endif |
24 | | |
25 | 53.0k | #define PyPARSE_IGNORE_COOKIE 0x0010 |
26 | 77.3k | #define PyPARSE_BARRY_AS_BDFL 0x0020 |
27 | 73.3k | #define PyPARSE_TYPE_COMMENTS 0x0040 |
28 | 332k | #define PyPARSE_ALLOW_INCOMPLETE_INPUT 0x0100 |
29 | | |
30 | 254k | #define CURRENT_POS (-5) |
31 | | |
32 | | typedef struct _memo { |
33 | | int type; |
34 | | int mark; |
35 | | void *node; |
36 | | struct _memo *next; |
37 | | } Memo; |
38 | | |
39 | | typedef struct { |
40 | | int type; |
41 | | // Text required by grammar actions or helpers; otherwise NULL. |
42 | | // Unfinished f-string and t-string middle tokens retain their text so |
43 | | // their grammar action can check escapes before requesting more input. |
44 | | PyObject *bytes; |
45 | | int level; |
46 | | unsigned char is_raw; |
47 | | unsigned char is_incomplete; |
48 | | int lineno, col_offset, end_lineno, end_col_offset; |
49 | | Memo *memo; |
50 | | // Filter over the rule types present in `memo` (bit `type & 63` is set |
51 | | // for every entry): lets lookups skip walking the list on definite |
52 | | // misses, which are the common case. |
53 | | uint64_t memo_mask; |
54 | | PyObject *metadata; |
55 | | } Token; |
56 | | |
57 | | typedef struct { |
58 | | const char *str; |
59 | | int type; |
60 | | } KeywordToken; |
61 | | |
62 | | |
63 | | typedef struct { |
64 | | struct { |
65 | | int lineno; |
66 | | char *comment; // The " <tag>" in "# type: ignore <tag>" |
67 | | } *items; |
68 | | size_t size; |
69 | | size_t num_items; |
70 | | } growable_comment_array; |
71 | | |
72 | | typedef struct { |
73 | | int lineno; |
74 | | int col_offset; |
75 | | int end_lineno; |
76 | | int end_col_offset; |
77 | | } location; |
78 | | |
79 | | typedef struct _identifier_cache_entry IdentifierCacheEntry; |
80 | | |
81 | | typedef struct { |
82 | | struct tok_state *tok; |
83 | | Token **tokens; |
84 | | int mark; |
85 | | int fill, size; |
86 | | PyArena *arena; |
87 | | KeywordToken **keywords; |
88 | | char **soft_keywords; |
89 | | int n_keyword_lists; |
90 | | int start_rule; |
91 | | int *errcode; |
92 | | unsigned char parsing_started; |
93 | | unsigned char input_exhausted; |
94 | | PyObject* normalize; |
95 | | int starting_lineno; |
96 | | int starting_col_offset; |
97 | | int error_indicator; |
98 | | int flags; |
99 | | int feature_version; |
100 | | growable_comment_array type_ignore_comments; |
101 | | Token *known_err_token; |
102 | | int level; |
103 | | int call_invalid_rules; |
104 | | int debug; |
105 | | location last_stmt_location; |
106 | | IdentifierCacheEntry *identifier_cache; |
107 | | PyThreadState *tstate; |
108 | | // Cached copy of tstate->c_stack_soft_limit offset by one margin toward |
109 | | // the stack top, so the per-rule stack check is a single inline comparison. |
110 | | uintptr_t stack_soft_limit; |
111 | | } Parser; |
112 | | |
113 | | // C-stack exhaustion check run on every rule entry. The fast path compares |
114 | | // the machine stack pointer against the soft limit cached in the Parser; |
115 | | // only when the stack is nearly exhausted is the full check called. |
116 | | static inline int |
117 | | _PyPegen_stack_exhausted(Parser *p) |
118 | 108M | { |
119 | 108M | #if _Py_STACK_GROWS_DOWN |
120 | 108M | if (_Py_get_machine_stack_pointer() > p->stack_soft_limit) { |
121 | | #else |
122 | | if (_Py_get_machine_stack_pointer() <= p->stack_soft_limit) { |
123 | | #endif |
124 | 108M | assert(!_Py_ReachedRecursionLimitWithMargin(p->tstate, 1)); |
125 | 108M | return 0; |
126 | 108M | } |
127 | 0 | return _Py_ReachedRecursionLimitWithMargin(p->tstate, 1); |
128 | 108M | } Unexecuted instantiation: peg_api.c:_PyPegen_stack_exhausted Unexecuted instantiation: Python-tokenize.c:_PyPegen_stack_exhausted Unexecuted instantiation: pegen.c:_PyPegen_stack_exhausted Unexecuted instantiation: pegen_errors.c:_PyPegen_stack_exhausted parser.c:_PyPegen_stack_exhausted Line | Count | Source | 118 | 98.6M | { | 119 | 98.6M | #if _Py_STACK_GROWS_DOWN | 120 | 98.6M | if (_Py_get_machine_stack_pointer() > p->stack_soft_limit) { | 121 | | #else | 122 | | if (_Py_get_machine_stack_pointer() <= p->stack_soft_limit) { | 123 | | #endif | 124 | 98.6M | assert(!_Py_ReachedRecursionLimitWithMargin(p->tstate, 1)); | 125 | 98.6M | return 0; | 126 | 98.6M | } | 127 | 0 | return _Py_ReachedRecursionLimitWithMargin(p->tstate, 1); | 128 | 98.6M | } |
parser_invalid.c:_PyPegen_stack_exhausted Line | Count | Source | 118 | 9.40M | { | 119 | 9.40M | #if _Py_STACK_GROWS_DOWN | 120 | 9.40M | if (_Py_get_machine_stack_pointer() > p->stack_soft_limit) { | 121 | | #else | 122 | | if (_Py_get_machine_stack_pointer() <= p->stack_soft_limit) { | 123 | | #endif | 124 | 9.40M | assert(!_Py_ReachedRecursionLimitWithMargin(p->tstate, 1)); | 125 | 9.40M | return 0; | 126 | 9.40M | } | 127 | 0 | return _Py_ReachedRecursionLimitWithMargin(p->tstate, 1); | 128 | 9.40M | } |
Unexecuted instantiation: action_helpers.c:_PyPegen_stack_exhausted Unexecuted instantiation: string_parser.c:_PyPegen_stack_exhausted |
129 | | |
130 | | typedef struct { |
131 | | cmpop_ty cmpop; |
132 | | expr_ty expr; |
133 | | } CmpopExprPair; |
134 | | |
135 | | typedef struct { |
136 | | expr_ty key; |
137 | | expr_ty value; |
138 | | } KeyValuePair; |
139 | | |
140 | | typedef struct { |
141 | | expr_ty key; |
142 | | pattern_ty pattern; |
143 | | } KeyPatternPair; |
144 | | |
145 | | typedef struct { |
146 | | arg_ty arg; |
147 | | expr_ty value; |
148 | | } NameDefaultPair; |
149 | | |
150 | | typedef struct { |
151 | | asdl_arg_seq *plain_names; |
152 | | asdl_seq *names_with_defaults; // asdl_seq* of NameDefaultsPair's |
153 | | } SlashWithDefault; |
154 | | |
155 | | typedef struct { |
156 | | arg_ty vararg; |
157 | | asdl_seq *kwonlyargs; // asdl_seq* of NameDefaultsPair's |
158 | | arg_ty kwarg; |
159 | | } StarEtc; |
160 | | |
161 | | typedef struct { operator_ty kind; } AugOperator; |
162 | | typedef struct { |
163 | | void *element; |
164 | | int is_keyword; |
165 | | } KeywordOrStarred; |
166 | | |
167 | | typedef struct { |
168 | | void *result; |
169 | | PyObject *metadata; |
170 | | } ResultTokenWithMetadata; |
171 | | |
172 | | // Internal parser functions |
173 | | #if defined(Py_DEBUG) |
174 | | void _PyPegen_clear_memo_statistics(void); |
175 | | PyObject *_PyPegen_get_memo_statistics(void); |
176 | | #endif |
177 | | |
178 | | int _PyPegen_insert_memo(Parser *p, int mark, int type, void *node); |
179 | | int _PyPegen_update_memo(Parser *p, int mark, int type, void *node); |
180 | | Memo *_PyPegen_insert_memo_direct(Parser *p, int mark, int type); |
181 | | int _PyPegen_is_memoized(Parser *p, int type, void *pres); |
182 | | |
183 | | int _PyPegen_lookahead(int, void *(func)(Parser *), Parser *); |
184 | | int _PyPegen_lookahead_for_expr(int, expr_ty (func)(Parser *), Parser *); |
185 | | int _PyPegen_lookahead_for_stmt(int, stmt_ty (func)(Parser *), Parser *); |
186 | | int _PyPegen_lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int); |
187 | | int _PyPegen_lookahead_with_string(int, expr_ty (func)(Parser *, const char*), Parser *, const char*); |
188 | | |
189 | | Token *_PyPegen_expect_token(Parser *p, int type); |
190 | | void* _PyPegen_expect_forced_result(Parser *p, void* result, const char* expected); |
191 | | Token *_PyPegen_expect_forced_token(Parser *p, int type, const char* expected); |
192 | | expr_ty _PyPegen_expect_soft_keyword(Parser *p, const char *keyword); |
193 | | expr_ty _PyPegen_soft_keyword_token(Parser *p); |
194 | | expr_ty _PyPegen_fstring_middle_token(Parser* p); |
195 | | Token *_PyPegen_get_last_nonnwhitespace_token(Parser *); |
196 | | int _PyPegen_fill_token(Parser *p); |
197 | | // Return -1 on failure, leaving the buffer and capacity unchanged. |
198 | | int _PyPegen_grow_loop_buffer(void ***buffer, Py_ssize_t *capacity); |
199 | | int _PyPegen_atom_fast_path(Parser *p, void *result); |
200 | | expr_ty _PyPegen_name_token(Parser *p); |
201 | | expr_ty _PyPegen_number_token(Parser *p); |
202 | | void *_PyPegen_string_token(Parser *p); |
203 | | Py_ssize_t _PyPegen_byte_offset_to_character_offset_line(PyObject *line, Py_ssize_t col_offset, Py_ssize_t end_col_offset); |
204 | | Py_ssize_t _PyPegen_byte_offset_to_character_offset(PyObject *line, Py_ssize_t col_offset); |
205 | | Py_ssize_t _PyPegen_byte_offset_to_character_offset_raw(const char*, Py_ssize_t col_offset); |
206 | | |
207 | | typedef enum { |
208 | | STAR_TARGETS, |
209 | | DEL_TARGETS, |
210 | | FOR_TARGETS, |
211 | | SINGLE_TARGETS, |
212 | | ATTRIBUTE_OR_SUBSCRIPT_TARGETS |
213 | | } TARGETS_TYPE; |
214 | | |
215 | | // Error handling functions and APIs |
216 | | int _Pypegen_raise_decode_error(Parser *p); |
217 | | int _Pypegen_raise_decode_error_known_location(Parser *p, expr_ty a); |
218 | | int _Pypegen_tokenizer_error(Parser *p); |
219 | | void *_PyPegen_raise_incomplete_input(Parser *p); |
220 | | void *_PyPegen_raise_error(Parser *p, PyObject *errtype, int use_mark, const char *errmsg, ...); |
221 | | void *_PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, |
222 | | Py_ssize_t lineno, Py_ssize_t col_offset, |
223 | | Py_ssize_t end_lineno, Py_ssize_t end_col_offset, |
224 | | const char *errmsg, va_list va); |
225 | | void _Pypegen_set_syntax_error(Parser* p, Token* last_token); |
226 | | void _Pypegen_stack_overflow(Parser *p); |
227 | | |
228 | | static inline void * |
229 | | RAISE_ERROR_KNOWN_LOCATION(Parser *p, PyObject *errtype, |
230 | | Py_ssize_t lineno, Py_ssize_t col_offset, |
231 | | Py_ssize_t end_lineno, Py_ssize_t end_col_offset, |
232 | | const char *errmsg, ...) |
233 | 62.9k | { |
234 | 62.9k | va_list va; |
235 | 62.9k | va_start(va, errmsg); |
236 | 62.9k | Py_ssize_t _col_offset = (col_offset == CURRENT_POS ? CURRENT_POS : col_offset + 1); |
237 | 62.9k | Py_ssize_t _end_col_offset = (end_col_offset == CURRENT_POS ? CURRENT_POS : end_col_offset + 1); |
238 | 62.9k | _PyPegen_raise_error_known_location(p, errtype, lineno, _col_offset, end_lineno, _end_col_offset, errmsg, va); |
239 | 62.9k | va_end(va); |
240 | 62.9k | return NULL; |
241 | 62.9k | } Unexecuted instantiation: peg_api.c:RAISE_ERROR_KNOWN_LOCATION Unexecuted instantiation: Python-tokenize.c:RAISE_ERROR_KNOWN_LOCATION pegen.c:RAISE_ERROR_KNOWN_LOCATION Line | Count | Source | 233 | 145 | { | 234 | 145 | va_list va; | 235 | 145 | va_start(va, errmsg); | 236 | 145 | Py_ssize_t _col_offset = (col_offset == CURRENT_POS ? CURRENT_POS : col_offset + 1); | 237 | 145 | Py_ssize_t _end_col_offset = (end_col_offset == CURRENT_POS ? CURRENT_POS : end_col_offset + 1); | 238 | 145 | _PyPegen_raise_error_known_location(p, errtype, lineno, _col_offset, end_lineno, _end_col_offset, errmsg, va); | 239 | 145 | va_end(va); | 240 | | return NULL; | 241 | 145 | } |
pegen_errors.c:RAISE_ERROR_KNOWN_LOCATION Line | Count | Source | 233 | 61.1k | { | 234 | 61.1k | va_list va; | 235 | 61.1k | va_start(va, errmsg); | 236 | 61.1k | Py_ssize_t _col_offset = (col_offset == CURRENT_POS ? CURRENT_POS : col_offset + 1); | 237 | 61.1k | Py_ssize_t _end_col_offset = (end_col_offset == CURRENT_POS ? CURRENT_POS : end_col_offset + 1); | 238 | 61.1k | _PyPegen_raise_error_known_location(p, errtype, lineno, _col_offset, end_lineno, _end_col_offset, errmsg, va); | 239 | 61.1k | va_end(va); | 240 | | return NULL; | 241 | 61.1k | } |
Unexecuted instantiation: parser.c:RAISE_ERROR_KNOWN_LOCATION parser_invalid.c:RAISE_ERROR_KNOWN_LOCATION Line | Count | Source | 233 | 1.45k | { | 234 | 1.45k | va_list va; | 235 | 1.45k | va_start(va, errmsg); | 236 | 1.45k | Py_ssize_t _col_offset = (col_offset == CURRENT_POS ? CURRENT_POS : col_offset + 1); | 237 | 1.45k | Py_ssize_t _end_col_offset = (end_col_offset == CURRENT_POS ? CURRENT_POS : end_col_offset + 1); | 238 | 1.45k | _PyPegen_raise_error_known_location(p, errtype, lineno, _col_offset, end_lineno, _end_col_offset, errmsg, va); | 239 | 1.45k | va_end(va); | 240 | | return NULL; | 241 | 1.45k | } |
action_helpers.c:RAISE_ERROR_KNOWN_LOCATION Line | Count | Source | 233 | 216 | { | 234 | 216 | va_list va; | 235 | 216 | va_start(va, errmsg); | 236 | 216 | Py_ssize_t _col_offset = (col_offset == CURRENT_POS ? CURRENT_POS : col_offset + 1); | 237 | 216 | Py_ssize_t _end_col_offset = (end_col_offset == CURRENT_POS ? CURRENT_POS : end_col_offset + 1); | 238 | 216 | _PyPegen_raise_error_known_location(p, errtype, lineno, _col_offset, end_lineno, _end_col_offset, errmsg, va); | 239 | 216 | va_end(va); | 240 | | return NULL; | 241 | 216 | } |
string_parser.c:RAISE_ERROR_KNOWN_LOCATION Line | Count | Source | 233 | 4 | { | 234 | 4 | va_list va; | 235 | 4 | va_start(va, errmsg); | 236 | 4 | Py_ssize_t _col_offset = (col_offset == CURRENT_POS ? CURRENT_POS : col_offset + 1); | 237 | 4 | Py_ssize_t _end_col_offset = (end_col_offset == CURRENT_POS ? CURRENT_POS : end_col_offset + 1); | 238 | 4 | _PyPegen_raise_error_known_location(p, errtype, lineno, _col_offset, end_lineno, _end_col_offset, errmsg, va); | 239 | 4 | va_end(va); | 240 | | return NULL; | 241 | 4 | } |
|
242 | 441 | #define RAISE_SYNTAX_ERROR(msg, ...) _PyPegen_raise_error(p, PyExc_SyntaxError, 0, msg, ##__VA_ARGS__) |
243 | 165 | #define RAISE_INDENTATION_ERROR(msg, ...) _PyPegen_raise_error(p, PyExc_IndentationError, 0, msg, ##__VA_ARGS__) |
244 | 788 | #define RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN(msg, ...) _PyPegen_raise_error(p, PyExc_SyntaxError, 1, msg, ##__VA_ARGS__) |
245 | | #define RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, msg, ...) \ |
246 | 200 | RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, (a)->lineno, (a)->col_offset, (b)->end_lineno, (b)->end_col_offset, msg, ##__VA_ARGS__) |
247 | | #define RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, msg, ...) \ |
248 | 59.9k | RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, (a)->lineno, (a)->col_offset, (a)->end_lineno, (a)->end_col_offset, msg, ##__VA_ARGS__) |
249 | | #define RAISE_SYNTAX_ERROR_STARTING_FROM(a, msg, ...) \ |
250 | 658 | RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, (a)->lineno, (a)->col_offset, CURRENT_POS, CURRENT_POS, msg, ##__VA_ARGS__) |
251 | 1.32k | #define RAISE_SYNTAX_ERROR_INVALID_TARGET(type, e) _RAISE_SYNTAX_ERROR_INVALID_TARGET(p, type, e) |
252 | | |
253 | | Py_LOCAL_INLINE(int) |
254 | | _PyPegen_tokens_are_adjacent(Token *a, Token *b) |
255 | 55 | { |
256 | 55 | return (a->end_lineno == b->lineno) && (a->end_col_offset == b->col_offset); |
257 | 55 | } Unexecuted instantiation: peg_api.c:_PyPegen_tokens_are_adjacent Unexecuted instantiation: Python-tokenize.c:_PyPegen_tokens_are_adjacent Unexecuted instantiation: pegen.c:_PyPegen_tokens_are_adjacent Unexecuted instantiation: pegen_errors.c:_PyPegen_tokens_are_adjacent Unexecuted instantiation: parser.c:_PyPegen_tokens_are_adjacent parser_invalid.c:_PyPegen_tokens_are_adjacent Line | Count | Source | 255 | 55 | { | 256 | 55 | return (a->end_lineno == b->lineno) && (a->end_col_offset == b->col_offset); | 257 | 55 | } |
Unexecuted instantiation: action_helpers.c:_PyPegen_tokens_are_adjacent Unexecuted instantiation: string_parser.c:_PyPegen_tokens_are_adjacent |
258 | | |
259 | | Py_LOCAL_INLINE(void *) |
260 | | CHECK_CALL(Parser *p, void *result) |
261 | 82.6k | { |
262 | 82.6k | if (result == NULL) { |
263 | 0 | assert(PyErr_Occurred()); |
264 | 0 | p->error_indicator = 1; |
265 | 0 | } |
266 | 82.6k | return result; |
267 | 82.6k | } Unexecuted instantiation: peg_api.c:CHECK_CALL Unexecuted instantiation: Python-tokenize.c:CHECK_CALL Unexecuted instantiation: pegen.c:CHECK_CALL Unexecuted instantiation: pegen_errors.c:CHECK_CALL Line | Count | Source | 261 | 82.6k | { | 262 | 82.6k | if (result == NULL) { | 263 | | assert(PyErr_Occurred()); | 264 | 0 | p->error_indicator = 1; | 265 | 0 | } | 266 | 82.6k | return result; | 267 | 82.6k | } |
Unexecuted instantiation: parser_invalid.c:CHECK_CALL Unexecuted instantiation: action_helpers.c:CHECK_CALL Unexecuted instantiation: string_parser.c:CHECK_CALL |
268 | | |
269 | | /* This is needed for helper functions that are allowed to |
270 | | return NULL without an error. Example: _PyPegen_seq_extract_starred_exprs */ |
271 | | Py_LOCAL_INLINE(void *) |
272 | | CHECK_CALL_NULL_ALLOWED(Parser *p, void *result) |
273 | 17.1k | { |
274 | 17.1k | if (result == NULL && PyErr_Occurred()) { |
275 | 379 | p->error_indicator = 1; |
276 | 379 | } |
277 | 17.1k | return result; |
278 | 17.1k | } Unexecuted instantiation: peg_api.c:CHECK_CALL_NULL_ALLOWED Unexecuted instantiation: Python-tokenize.c:CHECK_CALL_NULL_ALLOWED Unexecuted instantiation: pegen.c:CHECK_CALL_NULL_ALLOWED Unexecuted instantiation: pegen_errors.c:CHECK_CALL_NULL_ALLOWED parser.c:CHECK_CALL_NULL_ALLOWED Line | Count | Source | 273 | 15.8k | { | 274 | 15.8k | if (result == NULL && PyErr_Occurred()) { | 275 | 379 | p->error_indicator = 1; | 276 | 379 | } | 277 | 15.8k | return result; | 278 | 15.8k | } |
parser_invalid.c:CHECK_CALL_NULL_ALLOWED Line | Count | Source | 273 | 1.32k | { | 274 | 1.32k | if (result == NULL && PyErr_Occurred()) { | 275 | 0 | p->error_indicator = 1; | 276 | 0 | } | 277 | 1.32k | return result; | 278 | 1.32k | } |
Unexecuted instantiation: action_helpers.c:CHECK_CALL_NULL_ALLOWED Unexecuted instantiation: string_parser.c:CHECK_CALL_NULL_ALLOWED |
279 | | |
280 | 85.3k | #define CHECK(type, result) ((type) CHECK_CALL(p, result)) |
281 | 17.1k | #define CHECK_NULL_ALLOWED(type, result) ((type) CHECK_CALL_NULL_ALLOWED(p, result)) |
282 | | |
283 | | expr_ty _PyPegen_get_invalid_target(expr_ty e, TARGETS_TYPE targets_type); |
284 | | const char *_PyPegen_get_expr_name(expr_ty); |
285 | | Py_LOCAL_INLINE(void *) |
286 | | _RAISE_SYNTAX_ERROR_INVALID_TARGET(Parser *p, TARGETS_TYPE type, void *e) |
287 | 1.32k | { |
288 | 1.32k | expr_ty invalid_target = CHECK_NULL_ALLOWED(expr_ty, _PyPegen_get_invalid_target(e, type)); |
289 | 1.32k | if (invalid_target != NULL) { |
290 | 160 | const char *msg; |
291 | 160 | if (type == STAR_TARGETS || type == FOR_TARGETS) { |
292 | 151 | msg = "cannot assign to %s"; |
293 | 151 | } |
294 | 9 | else { |
295 | 9 | msg = "cannot delete %s"; |
296 | 9 | } |
297 | 160 | return RAISE_SYNTAX_ERROR_KNOWN_LOCATION( |
298 | 160 | invalid_target, |
299 | 160 | msg, |
300 | 160 | _PyPegen_get_expr_name(invalid_target) |
301 | 160 | ); |
302 | 0 | return RAISE_SYNTAX_ERROR_KNOWN_LOCATION(invalid_target, "invalid syntax"); |
303 | 160 | } |
304 | 1.16k | return NULL; |
305 | 1.32k | } Unexecuted instantiation: peg_api.c:_RAISE_SYNTAX_ERROR_INVALID_TARGET Unexecuted instantiation: Python-tokenize.c:_RAISE_SYNTAX_ERROR_INVALID_TARGET Unexecuted instantiation: pegen.c:_RAISE_SYNTAX_ERROR_INVALID_TARGET Unexecuted instantiation: pegen_errors.c:_RAISE_SYNTAX_ERROR_INVALID_TARGET Unexecuted instantiation: parser.c:_RAISE_SYNTAX_ERROR_INVALID_TARGET parser_invalid.c:_RAISE_SYNTAX_ERROR_INVALID_TARGET Line | Count | Source | 287 | 1.32k | { | 288 | 1.32k | expr_ty invalid_target = CHECK_NULL_ALLOWED(expr_ty, _PyPegen_get_invalid_target(e, type)); | 289 | 1.32k | if (invalid_target != NULL) { | 290 | 160 | const char *msg; | 291 | 160 | if (type == STAR_TARGETS || type == FOR_TARGETS) { | 292 | 151 | msg = "cannot assign to %s"; | 293 | 151 | } | 294 | 9 | else { | 295 | 9 | msg = "cannot delete %s"; | 296 | 9 | } | 297 | 160 | return RAISE_SYNTAX_ERROR_KNOWN_LOCATION( | 298 | 160 | invalid_target, | 299 | 160 | msg, | 300 | 160 | _PyPegen_get_expr_name(invalid_target) | 301 | 160 | ); | 302 | 0 | return RAISE_SYNTAX_ERROR_KNOWN_LOCATION(invalid_target, "invalid syntax"); | 303 | 160 | } | 304 | 1.16k | return NULL; | 305 | 1.32k | } |
Unexecuted instantiation: action_helpers.c:_RAISE_SYNTAX_ERROR_INVALID_TARGET Unexecuted instantiation: string_parser.c:_RAISE_SYNTAX_ERROR_INVALID_TARGET |
306 | | |
307 | | // Action utility functions |
308 | | |
309 | | void *_PyPegen_dummy_name(Parser *p, ...); |
310 | | void * _PyPegen_seq_last_item(asdl_seq *seq); |
311 | 6 | #define PyPegen_last_item(seq, type) ((type)_PyPegen_seq_last_item((asdl_seq*)seq)) |
312 | | void * _PyPegen_seq_first_item(asdl_seq *seq); |
313 | | #define PyPegen_first_item(seq, type) ((type)_PyPegen_seq_first_item((asdl_seq*)seq)) |
314 | 101M | #define UNUSED(expr) do { (void)(expr); } while (0) |
315 | 204k | #define EXTRA_EXPR(head, tail) head->lineno, (head)->col_offset, (tail)->end_lineno, (tail)->end_col_offset, p->arena |
316 | 7.75M | #define EXTRA _start_lineno, _start_col_offset, _end_lineno, _end_col_offset, p->arena |
317 | | PyObject *_PyPegen_new_type_comment(Parser *, const char *); |
318 | | |
319 | | Py_LOCAL_INLINE(PyObject *) |
320 | | NEW_TYPE_COMMENT(Parser *p, Token *tc) |
321 | 16.5k | { |
322 | 16.5k | if (tc == NULL) { |
323 | 16.5k | return NULL; |
324 | 16.5k | } |
325 | 0 | const char *bytes = PyBytes_AsString(tc->bytes); |
326 | 0 | if (bytes == NULL) { |
327 | 0 | goto error; |
328 | 0 | } |
329 | 0 | PyObject *tco = _PyPegen_new_type_comment(p, bytes); |
330 | 0 | if (tco == NULL) { |
331 | 0 | goto error; |
332 | 0 | } |
333 | 0 | return tco; |
334 | 0 | error: |
335 | 0 | p->error_indicator = 1; // Inline CHECK_CALL |
336 | 0 | return NULL; |
337 | 0 | } Unexecuted instantiation: peg_api.c:NEW_TYPE_COMMENT Unexecuted instantiation: Python-tokenize.c:NEW_TYPE_COMMENT Unexecuted instantiation: pegen.c:NEW_TYPE_COMMENT Unexecuted instantiation: pegen_errors.c:NEW_TYPE_COMMENT parser.c:NEW_TYPE_COMMENT Line | Count | Source | 321 | 16.5k | { | 322 | 16.5k | if (tc == NULL) { | 323 | 16.5k | return NULL; | 324 | 16.5k | } | 325 | 0 | const char *bytes = PyBytes_AsString(tc->bytes); | 326 | 0 | if (bytes == NULL) { | 327 | 0 | goto error; | 328 | 0 | } | 329 | 0 | PyObject *tco = _PyPegen_new_type_comment(p, bytes); | 330 | 0 | if (tco == NULL) { | 331 | 0 | goto error; | 332 | 0 | } | 333 | 0 | return tco; | 334 | 0 | error: | 335 | 0 | p->error_indicator = 1; // Inline CHECK_CALL | 336 | | return NULL; | 337 | 0 | } |
Unexecuted instantiation: parser_invalid.c:NEW_TYPE_COMMENT Unexecuted instantiation: action_helpers.c:NEW_TYPE_COMMENT Unexecuted instantiation: string_parser.c:NEW_TYPE_COMMENT |
338 | | |
339 | | Py_LOCAL_INLINE(void *) |
340 | | INVALID_VERSION_CHECK(Parser *p, int version, char *msg, void *node) |
341 | 25.1k | { |
342 | 25.1k | if (node == NULL) { |
343 | 12 | p->error_indicator = 1; // Inline CHECK_CALL |
344 | 12 | return NULL; |
345 | 12 | } |
346 | 25.1k | if (p->feature_version < version) { |
347 | 0 | p->error_indicator = 1; |
348 | 0 | return RAISE_SYNTAX_ERROR("%s only supported in Python 3.%i and greater", |
349 | 0 | msg, version); |
350 | 0 | } |
351 | 25.1k | return node; |
352 | 25.1k | } Unexecuted instantiation: peg_api.c:INVALID_VERSION_CHECK Unexecuted instantiation: Python-tokenize.c:INVALID_VERSION_CHECK Unexecuted instantiation: pegen.c:INVALID_VERSION_CHECK Unexecuted instantiation: pegen_errors.c:INVALID_VERSION_CHECK parser.c:INVALID_VERSION_CHECK Line | Count | Source | 341 | 25.1k | { | 342 | 25.1k | if (node == NULL) { | 343 | 6 | p->error_indicator = 1; // Inline CHECK_CALL | 344 | 6 | return NULL; | 345 | 6 | } | 346 | 25.1k | if (p->feature_version < version) { | 347 | 0 | p->error_indicator = 1; | 348 | 0 | return RAISE_SYNTAX_ERROR("%s only supported in Python 3.%i and greater", | 349 | 0 | msg, version); | 350 | 0 | } | 351 | 25.1k | return node; | 352 | 25.1k | } |
parser_invalid.c:INVALID_VERSION_CHECK Line | Count | Source | 341 | 6 | { | 342 | 6 | if (node == NULL) { | 343 | 6 | p->error_indicator = 1; // Inline CHECK_CALL | 344 | 6 | return NULL; | 345 | 6 | } | 346 | 0 | if (p->feature_version < version) { | 347 | 0 | p->error_indicator = 1; | 348 | 0 | return RAISE_SYNTAX_ERROR("%s only supported in Python 3.%i and greater", | 349 | 0 | msg, version); | 350 | 0 | } | 351 | 0 | return node; | 352 | 0 | } |
Unexecuted instantiation: action_helpers.c:INVALID_VERSION_CHECK Unexecuted instantiation: string_parser.c:INVALID_VERSION_CHECK |
353 | | |
354 | 25.1k | #define CHECK_VERSION(type, version, msg, node) ((type) INVALID_VERSION_CHECK(p, version, msg, node)) |
355 | | |
356 | | arg_ty _PyPegen_add_type_comment_to_arg(Parser *, arg_ty, Token *); |
357 | | PyObject *_PyPegen_new_identifier(Parser *, const char *); |
358 | | asdl_seq *_PyPegen_singleton_seq(Parser *, void *); |
359 | | asdl_seq *_PyPegen_seq_insert_in_front(Parser *, void *, asdl_seq *); |
360 | | asdl_seq *_PyPegen_seq_append_to_end(Parser *, asdl_seq *, void *); |
361 | | asdl_seq *_PyPegen_seq_flatten(Parser *, asdl_seq *); |
362 | | expr_ty _PyPegen_join_names_with_dot(Parser *, expr_ty, expr_ty); |
363 | | int _PyPegen_seq_count_dots(asdl_seq *); |
364 | | alias_ty _PyPegen_alias_for_star(Parser *, int, int, int, int, PyArena *); |
365 | | asdl_identifier_seq *_PyPegen_map_names_to_ids(Parser *, asdl_expr_seq *); |
366 | | CmpopExprPair *_PyPegen_cmpop_expr_pair(Parser *, cmpop_ty, expr_ty); |
367 | | asdl_int_seq *_PyPegen_get_cmpops(Parser *p, asdl_seq *); |
368 | | asdl_expr_seq *_PyPegen_get_exprs(Parser *, asdl_seq *); |
369 | | expr_ty _PyPegen_set_expr_context(Parser *, expr_ty, expr_context_ty); |
370 | | expr_ty _PyPegen_make_target(Parser *, expr_ty, TARGETS_TYPE); |
371 | | KeyValuePair *_PyPegen_key_value_pair(Parser *, expr_ty, expr_ty); |
372 | | asdl_expr_seq *_PyPegen_get_keys(Parser *, asdl_seq *); |
373 | | asdl_expr_seq *_PyPegen_get_values(Parser *, asdl_seq *); |
374 | | KeyPatternPair *_PyPegen_key_pattern_pair(Parser *, expr_ty, pattern_ty); |
375 | | asdl_expr_seq *_PyPegen_get_pattern_keys(Parser *, asdl_seq *); |
376 | | asdl_pattern_seq *_PyPegen_get_patterns(Parser *, asdl_seq *); |
377 | | NameDefaultPair *_PyPegen_name_default_pair(Parser *, arg_ty, expr_ty, Token *); |
378 | | SlashWithDefault *_PyPegen_slash_with_default(Parser *, asdl_arg_seq *, asdl_seq *); |
379 | | StarEtc *_PyPegen_star_etc(Parser *, arg_ty, asdl_seq *, arg_ty); |
380 | | arguments_ty _PyPegen_make_arguments(Parser *, asdl_arg_seq *, SlashWithDefault *, |
381 | | asdl_arg_seq *, asdl_seq *, StarEtc *); |
382 | | arguments_ty _PyPegen_empty_arguments(Parser *); |
383 | | expr_ty _PyPegen_template_str(Parser *p, Token *a, asdl_expr_seq *raw_expressions, Token *b); |
384 | | expr_ty _PyPegen_joined_str(Parser *p, Token *a, asdl_expr_seq *raw_expressions, Token *b); |
385 | | expr_ty _PyPegen_interpolation(Parser *, expr_ty, Token *, ResultTokenWithMetadata *, ResultTokenWithMetadata *, Token *, |
386 | | int, int, int, int, PyArena *); |
387 | | expr_ty _PyPegen_formatted_value(Parser *, expr_ty, Token *, ResultTokenWithMetadata *, ResultTokenWithMetadata *, Token *, |
388 | | int, int, int, int, PyArena *); |
389 | | AugOperator *_PyPegen_augoperator(Parser*, operator_ty type); |
390 | | stmt_ty _PyPegen_function_def_decorators(Parser *, asdl_expr_seq *, stmt_ty); |
391 | | stmt_ty _PyPegen_class_def_decorators(Parser *, asdl_expr_seq *, stmt_ty); |
392 | | KeywordOrStarred *_PyPegen_keyword_or_starred(Parser *, void *, int); |
393 | | asdl_expr_seq *_PyPegen_seq_extract_starred_exprs(Parser *, asdl_seq *); |
394 | | asdl_keyword_seq *_PyPegen_seq_delete_starred_exprs(Parser *, asdl_seq *); |
395 | | expr_ty _PyPegen_collect_call_seqs(Parser *, asdl_expr_seq *, asdl_seq *, |
396 | | int lineno, int col_offset, int end_lineno, |
397 | | int end_col_offset, PyArena *arena); |
398 | | expr_ty _PyPegen_constant_from_token(Parser* p, Token* tok); |
399 | | expr_ty _PyPegen_decoded_constant_from_token(Parser* p, Token* tok); |
400 | | expr_ty _PyPegen_constant_from_string(Parser* p, Token* tok); |
401 | | expr_ty _PyPegen_concatenate_tstrings(Parser *p, asdl_expr_seq *, int, int, int, int, PyArena *); |
402 | | expr_ty _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *, int, int, int, int, PyArena *); |
403 | | expr_ty _PyPegen_FetchRawForm(Parser *p, int, int, int, int); |
404 | | expr_ty _PyPegen_ensure_imaginary(Parser *p, expr_ty); |
405 | | expr_ty _PyPegen_ensure_real(Parser *p, expr_ty); |
406 | | asdl_seq *_PyPegen_join_sequences(Parser *, asdl_seq *, asdl_seq *); |
407 | | int _PyPegen_check_barry_as_flufl(Parser *, Token *); |
408 | | int _PyPegen_check_legacy_stmt(Parser *p, expr_ty t); |
409 | | void *_PyPegen_raise_error_for_missing_comma(Parser *p, expr_ty a, expr_ty b); |
410 | | ResultTokenWithMetadata *_PyPegen_check_fstring_conversion(Parser *p, Token *, expr_ty t); |
411 | | ResultTokenWithMetadata *_PyPegen_setup_full_format_spec(Parser *, Token *, asdl_expr_seq *, int, int, |
412 | | int, int, PyArena *); |
413 | | mod_ty _PyPegen_make_module(Parser *, asdl_stmt_seq *); |
414 | | void *_PyPegen_arguments_parsing_error(Parser *, expr_ty); |
415 | | expr_ty _PyPegen_get_last_comprehension_item(comprehension_ty comprehension); |
416 | | void *_PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args, asdl_comprehension_seq *comprehensions); |
417 | | stmt_ty _PyPegen_checked_from_import(Parser *p, asdl_seq *dots, expr_ty module_name, |
418 | | asdl_alias_seq *names, expr_ty lazy_token, int lineno, |
419 | | int col_offset, int end_lineno, int end_col_offset, |
420 | | PyArena *arena); |
421 | | asdl_stmt_seq* _PyPegen_register_stmts(Parser *p, asdl_stmt_seq* stmts); |
422 | | stmt_ty _PyPegen_register_stmt(Parser *p, stmt_ty s); |
423 | | |
424 | | // Parser API |
425 | | |
426 | | Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int, int *, const char*, PyArena *); |
427 | | void _PyPegen_Parser_Free(Parser *); |
428 | | mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *, |
429 | | const char *, const char *, PyCompilerFlags *, int *, PyObject **, |
430 | | PyArena *); |
431 | | void *_PyPegen_run_parser(Parser *); |
432 | | mod_ty _PyPegen_run_parser_from_string(const char *, int, PyObject *, PyCompilerFlags *, PyArena *, PyObject *, PyObject **); |
433 | | asdl_stmt_seq *_PyPegen_interactive_exit(Parser *); |
434 | | |
435 | | // Generated function in parse.c - function definition in python.gram |
436 | | void *_PyPegen_parse(Parser *); |
437 | | |
438 | | #endif |