blob: 8fded37ad998cbe17352458ec6739c5a66c29607 [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_TOKENIZER_H
2#define Py_TOKENIZER_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00008/* Tokenizer interface */
9
10#include "token.h" /* For token types */
11
12#define MAXINDENT 100 /* Max indentation level */
13
14/* Tokenizer state */
15struct tok_state {
16 /* Input state; buf <= cur <= inp <= end */
Guido van Rossum6ac258d1993-05-12 08:24:20 +000017 /* NB an entire line is held in the buffer */
18 char *buf; /* Input buffer, or NULL; malloc'ed if fp != NULL */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000019 char *cur; /* Next character in buffer */
20 char *inp; /* End of data in buffer */
Guido van Rossum6ac258d1993-05-12 08:24:20 +000021 char *end; /* End of input buffer if buf != NULL */
Guido van Rossum1d5735e1994-08-30 08:27:36 +000022 char *start; /* Start of current token if not NULL */
Guido van Rossum6ac258d1993-05-12 08:24:20 +000023 int done; /* E_OK normally, E_EOF at EOF, otherwise error code */
24 /* NB If done != E_OK, cur must be == inp!!! */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025 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 Rossuma849b831993-05-12 11:35:44 +000033 int level; /* () [] {} Parentheses nesting level */
34 /* Used to allow free continuations inside them */
Guido van Rossum926f13a1998-04-09 21:38:06 +000035 /* 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 Rossum85a5fbb1990-10-14 12:07:46 +000041};
42
Tim Petersdbd9ba62000-07-09 03:09:57 +000043extern struct tok_state *PyTokenizer_FromString(char *);
44extern struct tok_state *PyTokenizer_FromFile(FILE *, char *, char *);
45extern void PyTokenizer_Free(struct tok_state *);
46extern int PyTokenizer_Get(struct tok_state *, char **, char **);
Guido van Rossuma3309961993-07-28 09:05:47 +000047
48#ifdef __cplusplus
49}
50#endif
51#endif /* !Py_TOKENIZER_H */