Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 1 | #ifndef PEGEN_H |
| 2 | #define PEGEN_H |
| 3 | |
| 4 | #define PY_SSIZE_T_CLEAN |
| 5 | #include <Python.h> |
| 6 | #include <token.h> |
Victor Stinner | 94faa07 | 2021-03-23 20:47:40 +0100 | [diff] [blame] | 7 | #include <pycore_ast.h> |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 8 | |
Pablo Galindo | 2b74c83 | 2020-04-27 18:02:07 +0100 | [diff] [blame] | 9 | #if 0 |
| 10 | #define PyPARSE_YIELD_IS_KEYWORD 0x0001 |
| 11 | #endif |
| 12 | |
| 13 | #define PyPARSE_DONT_IMPLY_DEDENT 0x0002 |
| 14 | |
| 15 | #if 0 |
| 16 | #define PyPARSE_WITH_IS_KEYWORD 0x0003 |
| 17 | #define PyPARSE_PRINT_IS_FUNCTION 0x0004 |
| 18 | #define PyPARSE_UNICODE_LITERALS 0x0008 |
| 19 | #endif |
| 20 | |
| 21 | #define PyPARSE_IGNORE_COOKIE 0x0010 |
| 22 | #define PyPARSE_BARRY_AS_BDFL 0x0020 |
| 23 | #define PyPARSE_TYPE_COMMENTS 0x0040 |
| 24 | #define PyPARSE_ASYNC_HACKS 0x0080 |
| 25 | |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 26 | typedef struct _memo { |
| 27 | int type; |
| 28 | void *node; |
| 29 | int mark; |
| 30 | struct _memo *next; |
| 31 | } Memo; |
| 32 | |
| 33 | typedef struct { |
| 34 | int type; |
| 35 | PyObject *bytes; |
Lysandros Nikolaou | 861efc6 | 2020-06-20 15:57:27 +0300 | [diff] [blame] | 36 | int lineno, col_offset, end_lineno, end_col_offset; |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 37 | Memo *memo; |
| 38 | } Token; |
| 39 | |
| 40 | typedef struct { |
| 41 | char *str; |
| 42 | int type; |
| 43 | } KeywordToken; |
| 44 | |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 45 | |
| 46 | typedef struct { |
| 47 | struct { |
| 48 | int lineno; |
| 49 | char *comment; // The " <tag>" in "# type: ignore <tag>" |
| 50 | } *items; |
| 51 | size_t size; |
| 52 | size_t num_items; |
| 53 | } growable_comment_array; |
| 54 | |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 55 | typedef struct { |
| 56 | struct tok_state *tok; |
| 57 | Token **tokens; |
| 58 | int mark; |
| 59 | int fill, size; |
| 60 | PyArena *arena; |
| 61 | KeywordToken **keywords; |
Pablo Galindo | b280248 | 2021-04-15 21:38:45 +0100 | [diff] [blame] | 62 | char **soft_keywords; |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 63 | int n_keyword_lists; |
| 64 | int start_rule; |
| 65 | int *errcode; |
| 66 | int parsing_started; |
| 67 | PyObject* normalize; |
| 68 | int starting_lineno; |
| 69 | int starting_col_offset; |
| 70 | int error_indicator; |
Pablo Galindo | 2b74c83 | 2020-04-27 18:02:07 +0100 | [diff] [blame] | 71 | int flags; |
Lysandros Nikolaou | 3e0a6f3 | 2020-05-01 06:27:52 +0300 | [diff] [blame] | 72 | int feature_version; |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 73 | growable_comment_array type_ignore_comments; |
Lysandros Nikolaou | 2f37c35 | 2020-05-07 13:37:51 +0300 | [diff] [blame] | 74 | Token *known_err_token; |
Pablo Galindo | 800a35c6 | 2020-05-25 18:38:45 +0100 | [diff] [blame] | 75 | int level; |
Lysandros Nikolaou | bca7014 | 2020-10-27 00:42:04 +0200 | [diff] [blame] | 76 | int call_invalid_rules; |
Miss Islington (bot) | ae1732d | 2021-05-21 11:20:43 -0700 | [diff] [blame] | 77 | int in_raw_rule; |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 78 | } Parser; |
| 79 | |
| 80 | typedef struct { |
| 81 | cmpop_ty cmpop; |
| 82 | expr_ty expr; |
| 83 | } CmpopExprPair; |
| 84 | |
| 85 | typedef struct { |
| 86 | expr_ty key; |
| 87 | expr_ty value; |
| 88 | } KeyValuePair; |
| 89 | |
| 90 | typedef struct { |
Nick Coghlan | 1e7b858 | 2021-04-29 15:58:44 +1000 | [diff] [blame] | 91 | expr_ty key; |
| 92 | pattern_ty pattern; |
| 93 | } KeyPatternPair; |
| 94 | |
| 95 | typedef struct { |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 96 | arg_ty arg; |
| 97 | expr_ty value; |
| 98 | } NameDefaultPair; |
| 99 | |
| 100 | typedef struct { |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 101 | asdl_arg_seq *plain_names; |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 102 | asdl_seq *names_with_defaults; // asdl_seq* of NameDefaultsPair's |
| 103 | } SlashWithDefault; |
| 104 | |
| 105 | typedef struct { |
| 106 | arg_ty vararg; |
| 107 | asdl_seq *kwonlyargs; // asdl_seq* of NameDefaultsPair's |
| 108 | arg_ty kwarg; |
| 109 | } StarEtc; |
| 110 | |
Victor Stinner | 94faa07 | 2021-03-23 20:47:40 +0100 | [diff] [blame] | 111 | typedef struct { operator_ty kind; } AugOperator; |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 112 | typedef struct { |
| 113 | void *element; |
| 114 | int is_keyword; |
| 115 | } KeywordOrStarred; |
| 116 | |
Pablo Galindo | 58bafe4 | 2021-04-09 01:17:31 +0100 | [diff] [blame] | 117 | #if defined(Py_DEBUG) |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 118 | void _PyPegen_clear_memo_statistics(void); |
| 119 | PyObject *_PyPegen_get_memo_statistics(void); |
Pablo Galindo | 58bafe4 | 2021-04-09 01:17:31 +0100 | [diff] [blame] | 120 | #endif |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 121 | |
| 122 | int _PyPegen_insert_memo(Parser *p, int mark, int type, void *node); |
| 123 | int _PyPegen_update_memo(Parser *p, int mark, int type, void *node); |
| 124 | int _PyPegen_is_memoized(Parser *p, int type, void *pres); |
| 125 | |
Pablo Galindo | 58fb156 | 2021-02-02 19:54:22 +0000 | [diff] [blame] | 126 | |
Pablo Galindo | 1df5a9e | 2020-04-23 12:42:13 +0100 | [diff] [blame] | 127 | int _PyPegen_lookahead_with_name(int, expr_ty (func)(Parser *), Parser *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 128 | int _PyPegen_lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int); |
Pablo Galindo | 404b23b | 2020-05-27 00:15:52 +0100 | [diff] [blame] | 129 | int _PyPegen_lookahead_with_string(int , expr_ty (func)(Parser *, const char*), Parser *, const char*); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 130 | int _PyPegen_lookahead(int, void *(func)(Parser *), Parser *); |
| 131 | |
| 132 | Token *_PyPegen_expect_token(Parser *p, int type); |
Pablo Galindo | 58fb156 | 2021-02-02 19:54:22 +0000 | [diff] [blame] | 133 | Token *_PyPegen_expect_forced_token(Parser *p, int type, const char* expected); |
Guido van Rossum | b45af1a | 2020-05-26 10:58:44 -0700 | [diff] [blame] | 134 | expr_ty _PyPegen_expect_soft_keyword(Parser *p, const char *keyword); |
Pablo Galindo | b280248 | 2021-04-15 21:38:45 +0100 | [diff] [blame] | 135 | expr_ty _PyPegen_soft_keyword_token(Parser *p); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 136 | Token *_PyPegen_get_last_nonnwhitespace_token(Parser *); |
| 137 | int _PyPegen_fill_token(Parser *p); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 138 | expr_ty _PyPegen_name_token(Parser *p); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 139 | expr_ty _PyPegen_number_token(Parser *p); |
| 140 | void *_PyPegen_string_token(Parser *p); |
| 141 | const char *_PyPegen_get_expr_name(expr_ty); |
Lysandros Nikolaou | a15c9b3 | 2020-05-13 22:36:27 +0300 | [diff] [blame] | 142 | void *_PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...); |
| 143 | void *_PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, |
Pablo Galindo | 51c5896 | 2020-06-16 16:49:43 +0100 | [diff] [blame] | 144 | Py_ssize_t lineno, Py_ssize_t col_offset, |
Pablo Galindo | a77aac4 | 2021-04-23 14:27:05 +0100 | [diff] [blame] | 145 | Py_ssize_t end_lineno, Py_ssize_t end_col_offset, |
Lysandros Nikolaou | a15c9b3 | 2020-05-13 22:36:27 +0300 | [diff] [blame] | 146 | const char *errmsg, va_list va); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 147 | void *_PyPegen_dummy_name(Parser *p, ...); |
| 148 | |
Pablo Galindo | a77aac4 | 2021-04-23 14:27:05 +0100 | [diff] [blame] | 149 | void * _PyPegen_seq_last_item(asdl_seq *seq); |
| 150 | #define PyPegen_last_item(seq, type) ((type)_PyPegen_seq_last_item((asdl_seq*)seq)) |
| 151 | |
Miss Islington (bot) | 11f1a30 | 2021-06-24 08:34:28 -0700 | [diff] [blame] | 152 | void * _PyPegen_seq_first_item(asdl_seq *seq); |
| 153 | #define PyPegen_first_item(seq, type) ((type)_PyPegen_seq_first_item((asdl_seq*)seq)) |
| 154 | |
Pablo Galindo | a77aac4 | 2021-04-23 14:27:05 +0100 | [diff] [blame] | 155 | #define CURRENT_POS (-5) |
| 156 | |
Lysandros Nikolaou | a15c9b3 | 2020-05-13 22:36:27 +0300 | [diff] [blame] | 157 | Py_LOCAL_INLINE(void *) |
Pablo Galindo | 96eeff5 | 2021-03-22 17:28:11 +0000 | [diff] [blame] | 158 | RAISE_ERROR_KNOWN_LOCATION(Parser *p, PyObject *errtype, |
| 159 | Py_ssize_t lineno, Py_ssize_t col_offset, |
Brandt Bucher | dbe60ee | 2021-04-29 17:19:28 -0700 | [diff] [blame] | 160 | Py_ssize_t end_lineno, Py_ssize_t end_col_offset, |
Pablo Galindo | 96eeff5 | 2021-03-22 17:28:11 +0000 | [diff] [blame] | 161 | const char *errmsg, ...) |
Lysandros Nikolaou | a15c9b3 | 2020-05-13 22:36:27 +0300 | [diff] [blame] | 162 | { |
| 163 | va_list va; |
| 164 | va_start(va, errmsg); |
Pablo Galindo | a77aac4 | 2021-04-23 14:27:05 +0100 | [diff] [blame] | 165 | Py_ssize_t _col_offset = (col_offset == CURRENT_POS ? CURRENT_POS : col_offset + 1); |
| 166 | Py_ssize_t _end_col_offset = (end_col_offset == CURRENT_POS ? CURRENT_POS : end_col_offset + 1); |
| 167 | _PyPegen_raise_error_known_location(p, errtype, lineno, _col_offset, end_lineno, _end_col_offset, errmsg, va); |
Lysandros Nikolaou | a15c9b3 | 2020-05-13 22:36:27 +0300 | [diff] [blame] | 168 | va_end(va); |
| 169 | return NULL; |
| 170 | } |
| 171 | |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 172 | #define UNUSED(expr) do { (void)(expr); } while (0) |
Pablo Galindo | 58bafe4 | 2021-04-09 01:17:31 +0100 | [diff] [blame] | 173 | #define EXTRA_EXPR(head, tail) head->lineno, (head)->col_offset, (tail)->end_lineno, (tail)->end_col_offset, p->arena |
Pablo Galindo | ac7a92c | 2020-05-10 05:34:50 +0100 | [diff] [blame] | 174 | #define EXTRA _start_lineno, _start_col_offset, _end_lineno, _end_col_offset, p->arena |
Lysandros Nikolaou | a15c9b3 | 2020-05-13 22:36:27 +0300 | [diff] [blame] | 175 | #define RAISE_SYNTAX_ERROR(msg, ...) _PyPegen_raise_error(p, PyExc_SyntaxError, msg, ##__VA_ARGS__) |
| 176 | #define RAISE_INDENTATION_ERROR(msg, ...) _PyPegen_raise_error(p, PyExc_IndentationError, msg, ##__VA_ARGS__) |
Pablo Galindo | a77aac4 | 2021-04-23 14:27:05 +0100 | [diff] [blame] | 177 | #define RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, msg, ...) \ |
| 178 | RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, (a)->lineno, (a)->col_offset, (b)->end_lineno, (b)->end_col_offset, msg, ##__VA_ARGS__) |
Lysandros Nikolaou | a15c9b3 | 2020-05-13 22:36:27 +0300 | [diff] [blame] | 179 | #define RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, msg, ...) \ |
Pablo Galindo | a77aac4 | 2021-04-23 14:27:05 +0100 | [diff] [blame] | 180 | RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, (a)->lineno, (a)->col_offset, (a)->end_lineno, (a)->end_col_offset, msg, ##__VA_ARGS__) |
| 181 | #define RAISE_SYNTAX_ERROR_STARTING_FROM(a, msg, ...) \ |
| 182 | RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, (a)->lineno, (a)->col_offset, CURRENT_POS, CURRENT_POS, msg, ##__VA_ARGS__) |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 183 | |
| 184 | Py_LOCAL_INLINE(void *) |
| 185 | CHECK_CALL(Parser *p, void *result) |
| 186 | { |
| 187 | if (result == NULL) { |
| 188 | assert(PyErr_Occurred()); |
| 189 | p->error_indicator = 1; |
| 190 | } |
| 191 | return result; |
| 192 | } |
| 193 | |
| 194 | /* This is needed for helper functions that are allowed to |
| 195 | return NULL without an error. Example: _PyPegen_seq_extract_starred_exprs */ |
| 196 | Py_LOCAL_INLINE(void *) |
| 197 | CHECK_CALL_NULL_ALLOWED(Parser *p, void *result) |
| 198 | { |
| 199 | if (result == NULL && PyErr_Occurred()) { |
| 200 | p->error_indicator = 1; |
| 201 | } |
| 202 | return result; |
| 203 | } |
| 204 | |
Lysandros Nikolaou | 2e5ca9e | 2020-10-21 22:53:14 +0300 | [diff] [blame] | 205 | #define CHECK(type, result) ((type) CHECK_CALL(p, result)) |
| 206 | #define CHECK_NULL_ALLOWED(type, result) ((type) CHECK_CALL_NULL_ALLOWED(p, result)) |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 207 | |
Serhiy Storchaka | c43317d | 2021-06-12 20:44:32 +0300 | [diff] [blame] | 208 | PyObject *_PyPegen_new_type_comment(Parser *, const char *); |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 209 | |
| 210 | Py_LOCAL_INLINE(PyObject *) |
| 211 | NEW_TYPE_COMMENT(Parser *p, Token *tc) |
| 212 | { |
| 213 | if (tc == NULL) { |
| 214 | return NULL; |
| 215 | } |
Serhiy Storchaka | c43317d | 2021-06-12 20:44:32 +0300 | [diff] [blame] | 216 | const char *bytes = PyBytes_AsString(tc->bytes); |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 217 | if (bytes == NULL) { |
| 218 | goto error; |
| 219 | } |
| 220 | PyObject *tco = _PyPegen_new_type_comment(p, bytes); |
| 221 | if (tco == NULL) { |
| 222 | goto error; |
| 223 | } |
| 224 | return tco; |
| 225 | error: |
| 226 | p->error_indicator = 1; // Inline CHECK_CALL |
| 227 | return NULL; |
| 228 | } |
| 229 | |
Lysandros Nikolaou | 3e0a6f3 | 2020-05-01 06:27:52 +0300 | [diff] [blame] | 230 | Py_LOCAL_INLINE(void *) |
| 231 | INVALID_VERSION_CHECK(Parser *p, int version, char *msg, void *node) |
| 232 | { |
| 233 | if (node == NULL) { |
| 234 | p->error_indicator = 1; // Inline CHECK_CALL |
| 235 | return NULL; |
| 236 | } |
| 237 | if (p->feature_version < version) { |
| 238 | p->error_indicator = 1; |
Batuhan Taskaya | 76c1b4d | 2020-05-01 16:13:43 +0300 | [diff] [blame] | 239 | return RAISE_SYNTAX_ERROR("%s only supported in Python 3.%i and greater", |
| 240 | msg, version); |
Lysandros Nikolaou | 3e0a6f3 | 2020-05-01 06:27:52 +0300 | [diff] [blame] | 241 | } |
| 242 | return node; |
| 243 | } |
| 244 | |
Lysandros Nikolaou | 2e5ca9e | 2020-10-21 22:53:14 +0300 | [diff] [blame] | 245 | #define CHECK_VERSION(type, version, msg, node) ((type) INVALID_VERSION_CHECK(p, version, msg, node)) |
Lysandros Nikolaou | 3e0a6f3 | 2020-05-01 06:27:52 +0300 | [diff] [blame] | 246 | |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 247 | arg_ty _PyPegen_add_type_comment_to_arg(Parser *, arg_ty, Token *); |
Serhiy Storchaka | c43317d | 2021-06-12 20:44:32 +0300 | [diff] [blame] | 248 | PyObject *_PyPegen_new_identifier(Parser *, const char *); |
Lysandros Nikolaou | 3e0a6f3 | 2020-05-01 06:27:52 +0300 | [diff] [blame] | 249 | Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int, int *, PyArena *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 250 | void _PyPegen_Parser_Free(Parser *); |
| 251 | mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *, |
Pablo Galindo | 2b74c83 | 2020-04-27 18:02:07 +0100 | [diff] [blame] | 252 | const char *, const char *, PyCompilerFlags *, int *, PyArena *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 253 | void *_PyPegen_run_parser(Parser *); |
Pablo Galindo | 2b74c83 | 2020-04-27 18:02:07 +0100 | [diff] [blame] | 254 | mod_ty _PyPegen_run_parser_from_string(const char *, int, PyObject *, PyCompilerFlags *, PyArena *); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 255 | asdl_stmt_seq *_PyPegen_interactive_exit(Parser *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 256 | asdl_seq *_PyPegen_singleton_seq(Parser *, void *); |
| 257 | asdl_seq *_PyPegen_seq_insert_in_front(Parser *, void *, asdl_seq *); |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 258 | asdl_seq *_PyPegen_seq_append_to_end(Parser *, asdl_seq *, void *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 259 | asdl_seq *_PyPegen_seq_flatten(Parser *, asdl_seq *); |
| 260 | expr_ty _PyPegen_join_names_with_dot(Parser *, expr_ty, expr_ty); |
| 261 | int _PyPegen_seq_count_dots(asdl_seq *); |
Matthew Suozzo | 75a06f0 | 2021-04-10 16:56:28 -0400 | [diff] [blame] | 262 | alias_ty _PyPegen_alias_for_star(Parser *, int, int, int, int, PyArena *); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 263 | asdl_identifier_seq *_PyPegen_map_names_to_ids(Parser *, asdl_expr_seq *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 264 | CmpopExprPair *_PyPegen_cmpop_expr_pair(Parser *, cmpop_ty, expr_ty); |
| 265 | asdl_int_seq *_PyPegen_get_cmpops(Parser *p, asdl_seq *); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 266 | asdl_expr_seq *_PyPegen_get_exprs(Parser *, asdl_seq *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 267 | expr_ty _PyPegen_set_expr_context(Parser *, expr_ty, expr_context_ty); |
| 268 | KeyValuePair *_PyPegen_key_value_pair(Parser *, expr_ty, expr_ty); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 269 | asdl_expr_seq *_PyPegen_get_keys(Parser *, asdl_seq *); |
| 270 | asdl_expr_seq *_PyPegen_get_values(Parser *, asdl_seq *); |
Nick Coghlan | 1e7b858 | 2021-04-29 15:58:44 +1000 | [diff] [blame] | 271 | KeyPatternPair *_PyPegen_key_pattern_pair(Parser *, expr_ty, pattern_ty); |
| 272 | asdl_expr_seq *_PyPegen_get_pattern_keys(Parser *, asdl_seq *); |
| 273 | asdl_pattern_seq *_PyPegen_get_patterns(Parser *, asdl_seq *); |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 274 | NameDefaultPair *_PyPegen_name_default_pair(Parser *, arg_ty, expr_ty, Token *); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 275 | SlashWithDefault *_PyPegen_slash_with_default(Parser *, asdl_arg_seq *, asdl_seq *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 276 | StarEtc *_PyPegen_star_etc(Parser *, arg_ty, asdl_seq *, arg_ty); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 277 | arguments_ty _PyPegen_make_arguments(Parser *, asdl_arg_seq *, SlashWithDefault *, |
| 278 | asdl_arg_seq *, asdl_seq *, StarEtc *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 279 | arguments_ty _PyPegen_empty_arguments(Parser *); |
| 280 | AugOperator *_PyPegen_augoperator(Parser*, operator_ty type); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 281 | stmt_ty _PyPegen_function_def_decorators(Parser *, asdl_expr_seq *, stmt_ty); |
| 282 | stmt_ty _PyPegen_class_def_decorators(Parser *, asdl_expr_seq *, stmt_ty); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 283 | KeywordOrStarred *_PyPegen_keyword_or_starred(Parser *, void *, int); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 284 | asdl_expr_seq *_PyPegen_seq_extract_starred_exprs(Parser *, asdl_seq *); |
| 285 | asdl_keyword_seq *_PyPegen_seq_delete_starred_exprs(Parser *, asdl_seq *); |
| 286 | expr_ty _PyPegen_collect_call_seqs(Parser *, asdl_expr_seq *, asdl_seq *, |
Pablo Galindo | 315a61f | 2020-09-03 15:29:32 +0100 | [diff] [blame] | 287 | int lineno, int col_offset, int end_lineno, |
| 288 | int end_col_offset, PyArena *arena); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 289 | expr_ty _PyPegen_concatenate_strings(Parser *p, asdl_seq *); |
Nick Coghlan | 1e7b858 | 2021-04-29 15:58:44 +1000 | [diff] [blame] | 290 | expr_ty _PyPegen_ensure_imaginary(Parser *p, expr_ty); |
Brandt Bucher | dbe60ee | 2021-04-29 17:19:28 -0700 | [diff] [blame] | 291 | expr_ty _PyPegen_ensure_real(Parser *p, expr_ty); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 292 | asdl_seq *_PyPegen_join_sequences(Parser *, asdl_seq *, asdl_seq *); |
Pablo Galindo | 06f8c33 | 2020-10-30 23:48:42 +0000 | [diff] [blame] | 293 | int _PyPegen_check_barry_as_flufl(Parser *, Token *); |
Pablo Galindo Salgado | b977f85 | 2021-07-27 18:52:32 +0100 | [diff] [blame] | 294 | int _PyPegen_check_legacy_stmt(Parser *p, expr_ty t); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 295 | mod_ty _PyPegen_make_module(Parser *, asdl_stmt_seq *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 296 | |
Pablo Galindo | 16ab070 | 2020-05-15 02:04:52 +0100 | [diff] [blame] | 297 | // Error reporting helpers |
Lysandros Nikolaou | 01ece63 | 2020-06-19 02:10:43 +0300 | [diff] [blame] | 298 | typedef enum { |
| 299 | STAR_TARGETS, |
| 300 | DEL_TARGETS, |
| 301 | FOR_TARGETS |
| 302 | } TARGETS_TYPE; |
| 303 | expr_ty _PyPegen_get_invalid_target(expr_ty e, TARGETS_TYPE targets_type); |
Lysandros Nikolaou | 6c4e0bd | 2020-06-21 05:18:01 +0300 | [diff] [blame] | 304 | #define RAISE_SYNTAX_ERROR_INVALID_TARGET(type, e) _RAISE_SYNTAX_ERROR_INVALID_TARGET(p, type, e) |
| 305 | |
| 306 | Py_LOCAL_INLINE(void *) |
| 307 | _RAISE_SYNTAX_ERROR_INVALID_TARGET(Parser *p, TARGETS_TYPE type, void *e) |
| 308 | { |
Lysandros Nikolaou | 2e5ca9e | 2020-10-21 22:53:14 +0300 | [diff] [blame] | 309 | expr_ty invalid_target = CHECK_NULL_ALLOWED(expr_ty, _PyPegen_get_invalid_target(e, type)); |
Lysandros Nikolaou | 6c4e0bd | 2020-06-21 05:18:01 +0300 | [diff] [blame] | 310 | if (invalid_target != NULL) { |
| 311 | const char *msg; |
| 312 | if (type == STAR_TARGETS || type == FOR_TARGETS) { |
| 313 | msg = "cannot assign to %s"; |
| 314 | } |
| 315 | else { |
| 316 | msg = "cannot delete %s"; |
| 317 | } |
| 318 | return RAISE_SYNTAX_ERROR_KNOWN_LOCATION( |
| 319 | invalid_target, |
| 320 | msg, |
| 321 | _PyPegen_get_expr_name(invalid_target) |
| 322 | ); |
| 323 | } |
| 324 | return RAISE_SYNTAX_ERROR("invalid syntax"); |
| 325 | } |
Lysandros Nikolaou | 01ece63 | 2020-06-19 02:10:43 +0300 | [diff] [blame] | 326 | |
Lysandros Nikolaou | 75b863a | 2020-05-18 22:14:47 +0300 | [diff] [blame] | 327 | void *_PyPegen_arguments_parsing_error(Parser *, expr_ty); |
Lysandros Nikolaou | ae14583 | 2020-05-22 03:56:52 +0300 | [diff] [blame] | 328 | void *_PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args); |
Lysandros Nikolaou | 75b863a | 2020-05-18 22:14:47 +0300 | [diff] [blame] | 329 | |
Pablo Galindo | 16ab070 | 2020-05-15 02:04:52 +0100 | [diff] [blame] | 330 | |
Lysandros Nikolaou | 01ece63 | 2020-06-19 02:10:43 +0300 | [diff] [blame] | 331 | // Generated function in parse.c - function definition in python.gram |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 332 | void *_PyPegen_parse(Parser *); |
| 333 | |
| 334 | #endif |