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 | |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 8 | /* Tokenizer interface */ |
| 9 | |
| 10 | #include "token.h" /* For token types */ |
| 11 | |
| 12 | #define MAXINDENT 100 /* Max indentation level */ |
| 13 | |
| 14 | /* Tokenizer state */ |
| 15 | struct tok_state { |
| 16 | /* Input state; buf <= cur <= inp <= end */ |
Guido van Rossum | 6ac258d | 1993-05-12 08:24:20 +0000 | [diff] [blame] | 17 | /* NB an entire line is held in the buffer */ |
| 18 | char *buf; /* Input buffer, or NULL; malloc'ed if fp != NULL */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 19 | char *cur; /* Next character in buffer */ |
| 20 | char *inp; /* End of data in buffer */ |
Guido van Rossum | 6ac258d | 1993-05-12 08:24:20 +0000 | [diff] [blame] | 21 | char *end; /* End of input buffer if buf != NULL */ |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 22 | char *start; /* Start of current token if not NULL */ |
Guido van Rossum | 6ac258d | 1993-05-12 08:24:20 +0000 | [diff] [blame] | 23 | int done; /* E_OK normally, E_EOF at EOF, otherwise error code */ |
| 24 | /* NB If done != E_OK, cur must be == inp!!! */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 25 | FILE *fp; /* Rest of input; NULL if tokenizing a string */ |
| 26 | int tabsize; /* Tab spacing */ |
| 27 | int indent; /* Current indentation index */ |
| 28 | int indstack[MAXINDENT]; /* Stack of indents */ |
| 29 | int atbol; /* Nonzero if at begin of new line */ |
| 30 | int pendin; /* Pending indents (if > 0) or dedents (if < 0) */ |
| 31 | char *prompt, *nextprompt; /* For interactive prompting */ |
| 32 | int lineno; /* Current line number */ |
Guido van Rossum | a849b83 | 1993-05-12 11:35:44 +0000 | [diff] [blame] | 33 | int level; /* () [] {} Parentheses nesting level */ |
| 34 | /* Used to allow free continuations inside them */ |
Guido van Rossum | 926f13a | 1998-04-09 21:38:06 +0000 | [diff] [blame] | 35 | /* Stuff for checking on different tab sizes */ |
| 36 | char *filename; /* For error messages */ |
| 37 | int altwarning; /* Issue warning if alternate tabs don't match */ |
| 38 | int alterror; /* Issue error if alternate tabs don't match */ |
| 39 | int alttabsize; /* Alternate tab spacing */ |
| 40 | int altindstack[MAXINDENT]; /* Stack of alternate indents */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 43 | extern struct tok_state *PyTokenizer_FromString(char *); |
| 44 | extern struct tok_state *PyTokenizer_FromFile(FILE *, char *, char *); |
| 45 | extern void PyTokenizer_Free(struct tok_state *); |
| 46 | extern int PyTokenizer_Get(struct tok_state *, char **, char **); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 47 | |
| 48 | #ifdef __cplusplus |
| 49 | } |
| 50 | #endif |
| 51 | #endif /* !Py_TOKENIZER_H */ |