diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-06-11 17:30:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-11 17:30:46 +0100 |
commit | 1ed83adb0e95305af858bd41af531e487f54fee7 (patch) | |
tree | 5b05876e1800975fd2f0b8021544423f9fd9822a /Parser/string_parser.h | |
parent | 311110abcd8ab648dbf1803e36a8ba5d93fa019b (diff) | |
download | cpython-git-1ed83adb0e95305af858bd41af531e487f54fee7.tar.gz |
bpo-40939: Remove the old parser (GH-20768)
This commit removes the old parser, the deprecated parser module, the old parser compatibility flags and environment variables and all associated support code and documentation.
Diffstat (limited to 'Parser/string_parser.h')
-rw-r--r-- | Parser/string_parser.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Parser/string_parser.h b/Parser/string_parser.h new file mode 100644 index 0000000000..cd85bd57d0 --- /dev/null +++ b/Parser/string_parser.h @@ -0,0 +1,46 @@ +#ifndef STRINGS_H +#define STRINGS_H + +#include <Python.h> +#include <Python-ast.h> +#include "pegen.h" + +#define EXPRLIST_N_CACHED 64 + +typedef struct { + /* Incrementally build an array of expr_ty, so be used in an + asdl_seq. Cache some small but reasonably sized number of + expr_ty's, and then after that start dynamically allocating, + doubling the number allocated each time. Note that the f-string + f'{0}a{1}' contains 3 expr_ty's: 2 FormattedValue's, and one + Constant for the literal 'a'. So you add expr_ty's about twice as + fast as you add expressions in an f-string. */ + + Py_ssize_t allocated; /* Number we've allocated. */ + Py_ssize_t size; /* Number we've used. */ + expr_ty *p; /* Pointer to the memory we're actually + using. Will point to 'data' until we + start dynamically allocating. */ + expr_ty data[EXPRLIST_N_CACHED]; +} ExprList; + +/* The FstringParser is designed to add a mix of strings and + f-strings, and concat them together as needed. Ultimately, it + generates an expr_ty. */ +typedef struct { + PyObject *last_str; + ExprList expr_list; + int fmode; +} FstringParser; + +void _PyPegen_FstringParser_Init(FstringParser *); +int _PyPegen_parsestr(Parser *, int *, int *, PyObject **, + const char **, Py_ssize_t *, Token *); +int _PyPegen_FstringParser_ConcatFstring(Parser *, FstringParser *, const char **, + const char *, int, int, Token *, Token *, + Token *); +int _PyPegen_FstringParser_ConcatAndDel(FstringParser *, PyObject *); +expr_ty _PyPegen_FstringParser_Finish(Parser *, FstringParser *, Token *, Token *); +void _PyPegen_FstringParser_Dealloc(FstringParser *); + +#endif |