Coverage Report

Created: 2026-10-17 06:15

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