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 | |
| 152 | #define CURRENT_POS (-5) |
| 153 | |
Lysandros Nikolaou | a15c9b3 | 2020-05-13 22:36:27 +0300 | [diff] [blame] | 154 | Py_LOCAL_INLINE(void *) |
Pablo Galindo | 96eeff5 | 2021-03-22 17:28:11 +0000 | [diff] [blame] | 155 | RAISE_ERROR_KNOWN_LOCATION(Parser *p, PyObject *errtype, |
| 156 | Py_ssize_t lineno, Py_ssize_t col_offset, |
Brandt Bucher | dbe60ee | 2021-04-29 17:19:28 -0700 | [diff] [blame] | 157 | Py_ssize_t end_lineno, Py_ssize_t end_col_offset, |
Pablo Galindo | 96eeff5 | 2021-03-22 17:28:11 +0000 | [diff] [blame] | 158 | const char *errmsg, ...) |
Lysandros Nikolaou | a15c9b3 | 2020-05-13 22:36:27 +0300 | [diff] [blame] | 159 | { |
| 160 | va_list va; |
| 161 | va_start(va, errmsg); |
Pablo Galindo | a77aac4 | 2021-04-23 14:27:05 +0100 | [diff] [blame] | 162 | Py_ssize_t _col_offset = (col_offset == CURRENT_POS ? CURRENT_POS : col_offset + 1); |
| 163 | Py_ssize_t _end_col_offset = (end_col_offset == CURRENT_POS ? CURRENT_POS : end_col_offset + 1); |
| 164 | _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] | 165 | va_end(va); |
| 166 | return NULL; |
| 167 | } |
| 168 | |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 169 | #define UNUSED(expr) do { (void)(expr); } while (0) |
Pablo Galindo | 58bafe4 | 2021-04-09 01:17:31 +0100 | [diff] [blame] | 170 | #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] | 171 | #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] | 172 | #define RAISE_SYNTAX_ERROR(msg, ...) _PyPegen_raise_error(p, PyExc_SyntaxError, msg, ##__VA_ARGS__) |
| 173 | #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] | 174 | #define RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, msg, ...) \ |
| 175 | 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] | 176 | #define RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, msg, ...) \ |
Pablo Galindo | a77aac4 | 2021-04-23 14:27:05 +0100 | [diff] [blame] | 177 | RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, (a)->lineno, (a)->col_offset, (a)->end_lineno, (a)->end_col_offset, msg, ##__VA_ARGS__) |
| 178 | #define RAISE_SYNTAX_ERROR_STARTING_FROM(a, msg, ...) \ |
| 179 | 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] | 180 | |
| 181 | Py_LOCAL_INLINE(void *) |
| 182 | CHECK_CALL(Parser *p, void *result) |
| 183 | { |
| 184 | if (result == NULL) { |
| 185 | assert(PyErr_Occurred()); |
| 186 | p->error_indicator = 1; |
| 187 | } |
| 188 | return result; |
| 189 | } |
| 190 | |
| 191 | /* This is needed for helper functions that are allowed to |
| 192 | return NULL without an error. Example: _PyPegen_seq_extract_starred_exprs */ |
| 193 | Py_LOCAL_INLINE(void *) |
| 194 | CHECK_CALL_NULL_ALLOWED(Parser *p, void *result) |
| 195 | { |
| 196 | if (result == NULL && PyErr_Occurred()) { |
| 197 | p->error_indicator = 1; |
| 198 | } |
| 199 | return result; |
| 200 | } |
| 201 | |
Lysandros Nikolaou | 2e5ca9e | 2020-10-21 22:53:14 +0300 | [diff] [blame] | 202 | #define CHECK(type, result) ((type) CHECK_CALL(p, result)) |
| 203 | #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] | 204 | |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 205 | PyObject *_PyPegen_new_type_comment(Parser *, char *); |
| 206 | |
| 207 | Py_LOCAL_INLINE(PyObject *) |
| 208 | NEW_TYPE_COMMENT(Parser *p, Token *tc) |
| 209 | { |
| 210 | if (tc == NULL) { |
| 211 | return NULL; |
| 212 | } |
| 213 | char *bytes = PyBytes_AsString(tc->bytes); |
| 214 | if (bytes == NULL) { |
| 215 | goto error; |
| 216 | } |
| 217 | PyObject *tco = _PyPegen_new_type_comment(p, bytes); |
| 218 | if (tco == NULL) { |
| 219 | goto error; |
| 220 | } |
| 221 | return tco; |
| 222 | error: |
| 223 | p->error_indicator = 1; // Inline CHECK_CALL |
| 224 | return NULL; |
| 225 | } |
| 226 | |
Lysandros Nikolaou | 3e0a6f3 | 2020-05-01 06:27:52 +0300 | [diff] [blame] | 227 | Py_LOCAL_INLINE(void *) |
| 228 | INVALID_VERSION_CHECK(Parser *p, int version, char *msg, void *node) |
| 229 | { |
| 230 | if (node == NULL) { |
| 231 | p->error_indicator = 1; // Inline CHECK_CALL |
| 232 | return NULL; |
| 233 | } |
| 234 | if (p->feature_version < version) { |
| 235 | p->error_indicator = 1; |
Batuhan Taskaya | 76c1b4d | 2020-05-01 16:13:43 +0300 | [diff] [blame] | 236 | return RAISE_SYNTAX_ERROR("%s only supported in Python 3.%i and greater", |
| 237 | msg, version); |
Lysandros Nikolaou | 3e0a6f3 | 2020-05-01 06:27:52 +0300 | [diff] [blame] | 238 | } |
| 239 | return node; |
| 240 | } |
| 241 | |
Lysandros Nikolaou | 2e5ca9e | 2020-10-21 22:53:14 +0300 | [diff] [blame] | 242 | #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] | 243 | |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 244 | arg_ty _PyPegen_add_type_comment_to_arg(Parser *, arg_ty, Token *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 245 | PyObject *_PyPegen_new_identifier(Parser *, char *); |
Lysandros Nikolaou | 3e0a6f3 | 2020-05-01 06:27:52 +0300 | [diff] [blame] | 246 | Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int, int *, PyArena *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 247 | void _PyPegen_Parser_Free(Parser *); |
| 248 | 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] | 249 | const char *, const char *, PyCompilerFlags *, int *, PyArena *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 250 | void *_PyPegen_run_parser(Parser *); |
Pablo Galindo | 2b74c83 | 2020-04-27 18:02:07 +0100 | [diff] [blame] | 251 | 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] | 252 | asdl_stmt_seq *_PyPegen_interactive_exit(Parser *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 253 | asdl_seq *_PyPegen_singleton_seq(Parser *, void *); |
| 254 | asdl_seq *_PyPegen_seq_insert_in_front(Parser *, void *, asdl_seq *); |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 255 | asdl_seq *_PyPegen_seq_append_to_end(Parser *, asdl_seq *, void *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 256 | asdl_seq *_PyPegen_seq_flatten(Parser *, asdl_seq *); |
| 257 | expr_ty _PyPegen_join_names_with_dot(Parser *, expr_ty, expr_ty); |
| 258 | int _PyPegen_seq_count_dots(asdl_seq *); |
Matthew Suozzo | 75a06f0 | 2021-04-10 16:56:28 -0400 | [diff] [blame] | 259 | alias_ty _PyPegen_alias_for_star(Parser *, int, int, int, int, PyArena *); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 260 | asdl_identifier_seq *_PyPegen_map_names_to_ids(Parser *, asdl_expr_seq *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 261 | CmpopExprPair *_PyPegen_cmpop_expr_pair(Parser *, cmpop_ty, expr_ty); |
| 262 | asdl_int_seq *_PyPegen_get_cmpops(Parser *p, asdl_seq *); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 263 | asdl_expr_seq *_PyPegen_get_exprs(Parser *, asdl_seq *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 264 | expr_ty _PyPegen_set_expr_context(Parser *, expr_ty, expr_context_ty); |
| 265 | KeyValuePair *_PyPegen_key_value_pair(Parser *, expr_ty, expr_ty); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 266 | asdl_expr_seq *_PyPegen_get_keys(Parser *, asdl_seq *); |
| 267 | asdl_expr_seq *_PyPegen_get_values(Parser *, asdl_seq *); |
Nick Coghlan | 1e7b858 | 2021-04-29 15:58:44 +1000 | [diff] [blame] | 268 | KeyPatternPair *_PyPegen_key_pattern_pair(Parser *, expr_ty, pattern_ty); |
| 269 | asdl_expr_seq *_PyPegen_get_pattern_keys(Parser *, asdl_seq *); |
| 270 | asdl_pattern_seq *_PyPegen_get_patterns(Parser *, asdl_seq *); |
Guido van Rossum | c001c09 | 2020-04-30 12:12:19 -0700 | [diff] [blame] | 271 | NameDefaultPair *_PyPegen_name_default_pair(Parser *, arg_ty, expr_ty, Token *); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 272 | SlashWithDefault *_PyPegen_slash_with_default(Parser *, asdl_arg_seq *, asdl_seq *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 273 | StarEtc *_PyPegen_star_etc(Parser *, arg_ty, asdl_seq *, arg_ty); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 274 | arguments_ty _PyPegen_make_arguments(Parser *, asdl_arg_seq *, SlashWithDefault *, |
| 275 | asdl_arg_seq *, asdl_seq *, StarEtc *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 276 | arguments_ty _PyPegen_empty_arguments(Parser *); |
| 277 | AugOperator *_PyPegen_augoperator(Parser*, operator_ty type); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 278 | stmt_ty _PyPegen_function_def_decorators(Parser *, asdl_expr_seq *, stmt_ty); |
| 279 | stmt_ty _PyPegen_class_def_decorators(Parser *, asdl_expr_seq *, stmt_ty); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 280 | KeywordOrStarred *_PyPegen_keyword_or_starred(Parser *, void *, int); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 281 | asdl_expr_seq *_PyPegen_seq_extract_starred_exprs(Parser *, asdl_seq *); |
| 282 | asdl_keyword_seq *_PyPegen_seq_delete_starred_exprs(Parser *, asdl_seq *); |
| 283 | expr_ty _PyPegen_collect_call_seqs(Parser *, asdl_expr_seq *, asdl_seq *, |
Pablo Galindo | 315a61f | 2020-09-03 15:29:32 +0100 | [diff] [blame] | 284 | int lineno, int col_offset, int end_lineno, |
| 285 | int end_col_offset, PyArena *arena); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 286 | expr_ty _PyPegen_concatenate_strings(Parser *p, asdl_seq *); |
Nick Coghlan | 1e7b858 | 2021-04-29 15:58:44 +1000 | [diff] [blame] | 287 | expr_ty _PyPegen_ensure_imaginary(Parser *p, expr_ty); |
Brandt Bucher | dbe60ee | 2021-04-29 17:19:28 -0700 | [diff] [blame] | 288 | expr_ty _PyPegen_ensure_real(Parser *p, expr_ty); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 289 | asdl_seq *_PyPegen_join_sequences(Parser *, asdl_seq *, asdl_seq *); |
Pablo Galindo | 06f8c33 | 2020-10-30 23:48:42 +0000 | [diff] [blame] | 290 | int _PyPegen_check_barry_as_flufl(Parser *, Token *); |
Pablo Galindo | a5634c4 | 2020-09-16 19:42:00 +0100 | [diff] [blame] | 291 | mod_ty _PyPegen_make_module(Parser *, asdl_stmt_seq *); |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 292 | |
Pablo Galindo | 16ab070 | 2020-05-15 02:04:52 +0100 | [diff] [blame] | 293 | // Error reporting helpers |
Lysandros Nikolaou | 01ece63 | 2020-06-19 02:10:43 +0300 | [diff] [blame] | 294 | typedef enum { |
| 295 | STAR_TARGETS, |
| 296 | DEL_TARGETS, |
| 297 | FOR_TARGETS |
| 298 | } TARGETS_TYPE; |
| 299 | 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] | 300 | #define RAISE_SYNTAX_ERROR_INVALID_TARGET(type, e) _RAISE_SYNTAX_ERROR_INVALID_TARGET(p, type, e) |
| 301 | |
| 302 | Py_LOCAL_INLINE(void *) |
| 303 | _RAISE_SYNTAX_ERROR_INVALID_TARGET(Parser *p, TARGETS_TYPE type, void *e) |
| 304 | { |
Lysandros Nikolaou | 2e5ca9e | 2020-10-21 22:53:14 +0300 | [diff] [blame] | 305 | 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] | 306 | if (invalid_target != NULL) { |
| 307 | const char *msg; |
| 308 | if (type == STAR_TARGETS || type == FOR_TARGETS) { |
| 309 | msg = "cannot assign to %s"; |
| 310 | } |
| 311 | else { |
| 312 | msg = "cannot delete %s"; |
| 313 | } |
| 314 | return RAISE_SYNTAX_ERROR_KNOWN_LOCATION( |
| 315 | invalid_target, |
| 316 | msg, |
| 317 | _PyPegen_get_expr_name(invalid_target) |
| 318 | ); |
| 319 | } |
| 320 | return RAISE_SYNTAX_ERROR("invalid syntax"); |
| 321 | } |
Lysandros Nikolaou | 01ece63 | 2020-06-19 02:10:43 +0300 | [diff] [blame] | 322 | |
Lysandros Nikolaou | 75b863a | 2020-05-18 22:14:47 +0300 | [diff] [blame] | 323 | void *_PyPegen_arguments_parsing_error(Parser *, expr_ty); |
Lysandros Nikolaou | ae14583 | 2020-05-22 03:56:52 +0300 | [diff] [blame] | 324 | void *_PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args); |
Lysandros Nikolaou | 75b863a | 2020-05-18 22:14:47 +0300 | [diff] [blame] | 325 | |
Pablo Galindo | 16ab070 | 2020-05-15 02:04:52 +0100 | [diff] [blame] | 326 | |
Lysandros Nikolaou | 01ece63 | 2020-06-19 02:10:43 +0300 | [diff] [blame] | 327 | // Generated function in parse.c - function definition in python.gram |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame] | 328 | void *_PyPegen_parse(Parser *); |
| 329 | |
| 330 | #endif |