You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.8 KiB

  1. #ifndef STRINGS_H
  2. #define STRINGS_H
  3. #include <Python.h>
  4. #include <Python-ast.h>
  5. #include "pegen.h"
  6. #define EXPRLIST_N_CACHED 64
  7. typedef struct {
  8. /* Incrementally build an array of expr_ty, so be used in an
  9. asdl_seq. Cache some small but reasonably sized number of
  10. expr_ty's, and then after that start dynamically allocating,
  11. doubling the number allocated each time. Note that the f-string
  12. f'{0}a{1}' contains 3 expr_ty's: 2 FormattedValue's, and one
  13. Constant for the literal 'a'. So you add expr_ty's about twice as
  14. fast as you add expressions in an f-string. */
  15. Py_ssize_t allocated; /* Number we've allocated. */
  16. Py_ssize_t size; /* Number we've used. */
  17. expr_ty *p; /* Pointer to the memory we're actually
  18. using. Will point to 'data' until we
  19. start dynamically allocating. */
  20. expr_ty data[EXPRLIST_N_CACHED];
  21. } ExprList;
  22. /* The FstringParser is designed to add a mix of strings and
  23. f-strings, and concat them together as needed. Ultimately, it
  24. generates an expr_ty. */
  25. typedef struct {
  26. PyObject *last_str;
  27. ExprList expr_list;
  28. int fmode;
  29. } FstringParser;
  30. void _PyPegen_FstringParser_Init(FstringParser *);
  31. int _PyPegen_parsestr(Parser *, int *, int *, PyObject **,
  32. const char **, Py_ssize_t *, Token *);
  33. int _PyPegen_FstringParser_ConcatFstring(Parser *, FstringParser *, const char **,
  34. const char *, int, int, Token *, Token *,
  35. Token *);
  36. int _PyPegen_FstringParser_ConcatAndDel(FstringParser *, PyObject *);
  37. expr_ty _PyPegen_FstringParser_Finish(Parser *, FstringParser *, Token *, Token *);
  38. void _PyPegen_FstringParser_Dealloc(FstringParser *);
  39. #endif