{
const char *start;
const char *end;
- int type = PyTokenizer_Get(p->tok, &start, &end);
+ int type = _PyTokenizer_Get(p->tok, &start, &end);
// Record and skip '# type: ignore' comments
while (type == TYPE_IGNORE) {
PyErr_NoMemory();
return -1;
}
- type = PyTokenizer_Get(p->tok, &start, &end);
+ type = _PyTokenizer_Get(p->tok, &start, &end);
}
// If we have reached the end and we are in single input mode we need to insert a newline and reset the parsing
for (;;) {
const char *start;
const char *end;
- switch (PyTokenizer_Get(p->tok, &start, &end)) {
+ switch (_PyTokenizer_Get(p->tok, &start, &end)) {
case ERRORTOKEN:
if (p->tok->level != 0) {
int error_lineno = p->tok->parenlinenostack[p->tok->level-1];
const char *enc, const char *ps1, const char *ps2,
PyCompilerFlags *flags, int *errcode, PyArena *arena)
{
- struct tok_state *tok = PyTokenizer_FromFile(fp, enc, ps1, ps2);
+ struct tok_state *tok = _PyTokenizer_FromFile(fp, enc, ps1, ps2);
if (tok == NULL) {
if (PyErr_Occurred()) {
raise_tokenizer_init_error(filename_ob);
_PyPegen_Parser_Free(p);
error:
- PyTokenizer_Free(tok);
+ _PyTokenizer_Free(tok);
return result;
}
struct tok_state *tok;
if (flags == NULL || flags->cf_flags & PyCF_IGNORE_COOKIE) {
- tok = PyTokenizer_FromUTF8(str, exec_input);
+ tok = _PyTokenizer_FromUTF8(str, exec_input);
} else {
- tok = PyTokenizer_FromString(str, exec_input);
+ tok = _PyTokenizer_FromString(str, exec_input);
}
if (tok == NULL) {
if (PyErr_Occurred()) {
_PyPegen_Parser_Free(p);
error:
- PyTokenizer_Free(tok);
+ _PyTokenizer_Free(tok);
return result;
}
error_ret(struct tok_state *tok) /* XXX */
{
tok->decoding_erred = 1;
- if (tok->fp != NULL && tok->buf != NULL) /* see PyTokenizer_Free */
+ if (tok->fp != NULL && tok->buf != NULL) /* see _PyTokenizer_Free */
PyMem_Free(tok->buf);
tok->buf = tok->cur = tok->inp = NULL;
tok->start = NULL;
/* Set up tokenizer for string */
struct tok_state *
-PyTokenizer_FromString(const char *str, int exec_input)
+_PyTokenizer_FromString(const char *str, int exec_input)
{
struct tok_state *tok = tok_new();
char *decoded;
return NULL;
decoded = decode_str(str, exec_input, tok);
if (decoded == NULL) {
- PyTokenizer_Free(tok);
+ _PyTokenizer_Free(tok);
return NULL;
}
/* Set up tokenizer for UTF-8 string */
struct tok_state *
-PyTokenizer_FromUTF8(const char *str, int exec_input)
+_PyTokenizer_FromUTF8(const char *str, int exec_input)
{
struct tok_state *tok = tok_new();
char *translated;
return NULL;
tok->input = translated = translate_newlines(str, exec_input, tok);
if (translated == NULL) {
- PyTokenizer_Free(tok);
+ _PyTokenizer_Free(tok);
return NULL;
}
tok->decoding_state = STATE_NORMAL;
tok->str = translated;
tok->encoding = new_string("utf-8", 5, tok);
if (!tok->encoding) {
- PyTokenizer_Free(tok);
+ _PyTokenizer_Free(tok);
return NULL;
}
/* Set up tokenizer for file */
struct tok_state *
-PyTokenizer_FromFile(FILE *fp, const char* enc,
- const char *ps1, const char *ps2)
+_PyTokenizer_FromFile(FILE *fp, const char* enc,
+ const char *ps1, const char *ps2)
{
struct tok_state *tok = tok_new();
if (tok == NULL)
return NULL;
if ((tok->buf = (char *)PyMem_Malloc(BUFSIZ)) == NULL) {
- PyTokenizer_Free(tok);
+ _PyTokenizer_Free(tok);
return NULL;
}
tok->cur = tok->inp = tok->buf;
gets copied into the parse tree. */
tok->encoding = new_string(enc, strlen(enc), tok);
if (!tok->encoding) {
- PyTokenizer_Free(tok);
+ _PyTokenizer_Free(tok);
return NULL;
}
tok->decoding_state = STATE_NORMAL;
/* Free a tok_state structure */
void
-PyTokenizer_Free(struct tok_state *tok)
+_PyTokenizer_Free(struct tok_state *tok)
{
if (tok->encoding != NULL) {
PyMem_Free(tok->encoding);
}
int
-PyTokenizer_Get(struct tok_state *tok, const char **p_start, const char **p_end)
+_PyTokenizer_Get(struct tok_state *tok,
+ const char **p_start, const char **p_end)
{
int result = tok_get(tok, p_start, p_end);
if (tok->decoding_erred) {
/* Get the encoding of a Python file. Check for the coding cookie and check if
the file starts with a BOM.
- PyTokenizer_FindEncodingFilename() returns NULL when it can't find the
+ _PyTokenizer_FindEncodingFilename() returns NULL when it can't find the
encoding in the first or second line of the file (in which case the encoding
should be assumed to be UTF-8).
by the caller. */
char *
-PyTokenizer_FindEncodingFilename(int fd, PyObject *filename)
+_PyTokenizer_FindEncodingFilename(int fd, PyObject *filename)
{
struct tok_state *tok;
FILE *fp;
if (fp == NULL) {
return NULL;
}
- tok = PyTokenizer_FromFile(fp, NULL, NULL, NULL);
+ tok = _PyTokenizer_FromFile(fp, NULL, NULL, NULL);
if (tok == NULL) {
fclose(fp);
return NULL;
tok->filename = PyUnicode_FromString("<string>");
if (tok->filename == NULL) {
fclose(fp);
- PyTokenizer_Free(tok);
+ _PyTokenizer_Free(tok);
return encoding;
}
}
while (tok->lineno < 2 && tok->done == E_OK) {
- PyTokenizer_Get(tok, &p_start, &p_end);
+ _PyTokenizer_Get(tok, &p_start, &p_end);
}
fclose(fp);
if (tok->encoding) {
strcpy(encoding, tok->encoding);
}
}
- PyTokenizer_Free(tok);
+ _PyTokenizer_Free(tok);
return encoding;
}
-char *
-PyTokenizer_FindEncoding(int fd)
-{
- return PyTokenizer_FindEncodingFilename(fd, NULL);
-}
-
#ifdef Py_DEBUG
-
void
tok_dump(int type, char *start, char *end)
{
if (type == NAME || type == NUMBER || type == STRING || type == OP)
printf("(%.*s)", (int)(end - start), start);
}
-
-#endif
+#endif // Py_DEBUG
enum interactive_underflow_t interactive_underflow;
};
-extern struct tok_state *PyTokenizer_FromString(const char *, int);
-extern struct tok_state *PyTokenizer_FromUTF8(const char *, int);
-extern struct tok_state *PyTokenizer_FromFile(FILE *, const char*,
+extern struct tok_state *_PyTokenizer_FromString(const char *, int);
+extern struct tok_state *_PyTokenizer_FromUTF8(const char *, int);
+extern struct tok_state *_PyTokenizer_FromFile(FILE *, const char*,
const char *, const char *);
-extern void PyTokenizer_Free(struct tok_state *);
-extern int PyTokenizer_Get(struct tok_state *, const char **, const char **);
+extern void _PyTokenizer_Free(struct tok_state *);
+extern int _PyTokenizer_Get(struct tok_state *, const char **, const char **);
#define tok_dump _Py_tok_dump