Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_TOKENIZER_H |
| 2 | #define Py_TOKENIZER_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Martin v. Löwis | 00f1e3f | 2002-08-04 17:29:52 +0000 | [diff] [blame] | 7 | #include "object.h" |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 8 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 9 | /* Tokenizer interface */ |
| 10 | |
| 11 | #include "token.h" /* For token types */ |
| 12 | |
| 13 | #define MAXINDENT 100 /* Max indentation level */ |
| 14 | |
| 15 | /* Tokenizer state */ |
| 16 | struct tok_state { |
| 17 | /* Input state; buf <= cur <= inp <= end */ |
Guido van Rossum | 6ac258d | 1993-05-12 08:24:20 +0000 | [diff] [blame] | 18 | /* NB an entire line is held in the buffer */ |
| 19 | char *buf; /* Input buffer, or NULL; malloc'ed if fp != NULL */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 20 | char *cur; /* Next character in buffer */ |
| 21 | char *inp; /* End of data in buffer */ |
Guido van Rossum | 6ac258d | 1993-05-12 08:24:20 +0000 | [diff] [blame] | 22 | char *end; /* End of input buffer if buf != NULL */ |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 23 | char *start; /* Start of current token if not NULL */ |
Guido van Rossum | 6ac258d | 1993-05-12 08:24:20 +0000 | [diff] [blame] | 24 | int done; /* E_OK normally, E_EOF at EOF, otherwise error code */ |
| 25 | /* NB If done != E_OK, cur must be == inp!!! */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 26 | FILE *fp; /* Rest of input; NULL if tokenizing a string */ |
| 27 | int tabsize; /* Tab spacing */ |
| 28 | int indent; /* Current indentation index */ |
| 29 | int indstack[MAXINDENT]; /* Stack of indents */ |
| 30 | int atbol; /* Nonzero if at begin of new line */ |
| 31 | int pendin; /* Pending indents (if > 0) or dedents (if < 0) */ |
| 32 | char *prompt, *nextprompt; /* For interactive prompting */ |
| 33 | int lineno; /* Current line number */ |
Guido van Rossum | a849b83 | 1993-05-12 11:35:44 +0000 | [diff] [blame] | 34 | int level; /* () [] {} Parentheses nesting level */ |
| 35 | /* Used to allow free continuations inside them */ |
Guido van Rossum | 926f13a | 1998-04-09 21:38:06 +0000 | [diff] [blame] | 36 | /* Stuff for checking on different tab sizes */ |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 37 | const char *filename; /* For error messages */ |
Guido van Rossum | 926f13a | 1998-04-09 21:38:06 +0000 | [diff] [blame] | 38 | int altwarning; /* Issue warning if alternate tabs don't match */ |
| 39 | int alterror; /* Issue error if alternate tabs don't match */ |
| 40 | int alttabsize; /* Alternate tab spacing */ |
| 41 | int altindstack[MAXINDENT]; /* Stack of alternate indents */ |
Martin v. Löwis | 00f1e3f | 2002-08-04 17:29:52 +0000 | [diff] [blame] | 42 | /* Stuff for PEP 0263 */ |
| 43 | int decoding_state; /* -1:decoding, 0:init, 1:raw */ |
| 44 | int decoding_erred; /* whether erred in decoding */ |
| 45 | int read_coding_spec; /* whether 'coding:...' has been read */ |
| 46 | int issued_encoding_warning; /* whether non-ASCII warning was issued */ |
| 47 | char *encoding; |
Martin v. Löwis | f62a89b | 2002-09-03 11:52:44 +0000 | [diff] [blame] | 48 | int cont_line; /* whether we are in a continuation line. */ |
Martin v. Löwis | 1ee99d3 | 2002-08-04 20:10:29 +0000 | [diff] [blame] | 49 | #ifndef PGEN |
Martin v. Löwis | 00f1e3f | 2002-08-04 17:29:52 +0000 | [diff] [blame] | 50 | PyObject *decoding_readline; /* codecs.open(...).readline */ |
| 51 | PyObject *decoding_buffer; |
Martin v. Löwis | 1ee99d3 | 2002-08-04 20:10:29 +0000 | [diff] [blame] | 52 | #endif |
Martin v. Löwis | 00f1e3f | 2002-08-04 17:29:52 +0000 | [diff] [blame] | 53 | const char* enc; |
| 54 | const char* str; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 57 | extern struct tok_state *PyTokenizer_FromString(const char *); |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 58 | extern struct tok_state *PyTokenizer_FromFile(FILE *, char *, char *); |
| 59 | extern void PyTokenizer_Free(struct tok_state *); |
| 60 | extern int PyTokenizer_Get(struct tok_state *, char **, char **); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 61 | |
| 62 | #ifdef __cplusplus |
| 63 | } |
| 64 | #endif |
| 65 | #endif /* !Py_TOKENIZER_H */ |