summaryrefslogtreecommitdiffstats
path: root/Parser/tokenizer.h
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2023-04-19 16:18:16 (GMT)
committerGitHub <noreply@github.com>2023-04-19 16:18:16 (GMT)
commit1ef61cf71a218c71860ff6aecf0fd51edb8b65dc (patch)
treed0c4995cac9cb660b66498419d528254f26baf54 /Parser/tokenizer.h
parenta6b07b5a345f7f54ee9f6d75e81d2fb55971b35c (diff)
downloadcpython-1ef61cf71a218c71860ff6aecf0fd51edb8b65dc.zip
cpython-1ef61cf71a218c71860ff6aecf0fd51edb8b65dc.tar.gz
cpython-1ef61cf71a218c71860ff6aecf0fd51edb8b65dc.tar.bz2
gh-102856: Initial implementation of PEP 701 (#102855)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Diffstat (limited to 'Parser/tokenizer.h')
-rw-r--r--Parser/tokenizer.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/Parser/tokenizer.h b/Parser/tokenizer.h
index 16a94d5..f67e0cd 100644
--- a/Parser/tokenizer.h
+++ b/Parser/tokenizer.h
@@ -33,6 +33,31 @@ struct token {
const char *start, *end;
};
+enum tokenizer_mode_kind_t {
+ TOK_REGULAR_MODE,
+ TOK_FSTRING_MODE,
+};
+
+#define MAX_EXPR_NESTING 3
+
+typedef struct _tokenizer_mode {
+ enum tokenizer_mode_kind_t kind;
+
+ int bracket_stack;
+ int bracket_mark[MAX_EXPR_NESTING];
+ int bracket_mark_index;
+
+ char f_string_quote;
+ int f_string_quote_size;
+ int f_string_raw;
+ const char* f_string_start;
+ const char* f_string_multi_line_start;
+
+ Py_ssize_t last_expr_size;
+ Py_ssize_t last_expr_end;
+ char* last_expr_buffer;
+} tokenizer_mode;
+
/* Tokenizer state */
struct tok_state {
/* Input state; buf <= cur <= inp <= end */
@@ -93,6 +118,10 @@ struct tok_state {
/* How to proceed when asked for a new token in interactive mode */
enum interactive_underflow_t interactive_underflow;
int report_warnings;
+ // TODO: Factor this into its own thing
+ tokenizer_mode tok_mode_stack[MAXLEVEL];
+ int tok_mode_stack_index;
+ int tok_report_warnings;
#ifdef Py_DEBUG
int debug;
#endif