/Parser/tokenizer.h

http://unladen-swallow.googlecode.com/ · C Header · 69 lines · 54 code · 7 blank · 8 comment · 1 complexity · 09ca14a3d7754546bf85288cdf0c6f00 MD5 · raw file

  1. #ifndef Py_TOKENIZER_H
  2. #define Py_TOKENIZER_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "object.h"
  7. /* Tokenizer interface */
  8. #include "token.h" /* For token types */
  9. #define MAXINDENT 100 /* Max indentation level */
  10. /* Tokenizer state */
  11. struct tok_state {
  12. /* Input state; buf <= cur <= inp <= end */
  13. /* NB an entire line is held in the buffer */
  14. char *buf; /* Input buffer, or NULL; malloc'ed if fp != NULL */
  15. char *cur; /* Next character in buffer */
  16. char *inp; /* End of data in buffer */
  17. char *end; /* End of input buffer if buf != NULL */
  18. char *start; /* Start of current token if not NULL */
  19. int done; /* E_OK normally, E_EOF at EOF, otherwise error code */
  20. /* NB If done != E_OK, cur must be == inp!!! */
  21. FILE *fp; /* Rest of input; NULL if tokenizing a string */
  22. int tabsize; /* Tab spacing */
  23. int indent; /* Current indentation index */
  24. int indstack[MAXINDENT]; /* Stack of indents */
  25. int atbol; /* Nonzero if at begin of new line */
  26. int pendin; /* Pending indents (if > 0) or dedents (if < 0) */
  27. char *prompt, *nextprompt; /* For interactive prompting */
  28. int lineno; /* Current line number */
  29. int level; /* () [] {} Parentheses nesting level */
  30. /* Used to allow free continuations inside them */
  31. /* Stuff for checking on different tab sizes */
  32. const char *filename; /* For error messages */
  33. int altwarning; /* Issue warning if alternate tabs don't match */
  34. int alterror; /* Issue error if alternate tabs don't match */
  35. int alttabsize; /* Alternate tab spacing */
  36. int altindstack[MAXINDENT]; /* Stack of alternate indents */
  37. /* Stuff for PEP 0263 */
  38. int decoding_state; /* -1:decoding, 0:init, 1:raw */
  39. int decoding_erred; /* whether erred in decoding */
  40. int read_coding_spec; /* whether 'coding:...' has been read */
  41. char *encoding;
  42. int cont_line; /* whether we are in a continuation line. */
  43. const char* line_start; /* pointer to start of current line */
  44. #ifndef PGEN
  45. PyObject *decoding_readline; /* codecs.open(...).readline */
  46. PyObject *decoding_buffer;
  47. #endif
  48. const char* enc;
  49. const char* str;
  50. };
  51. extern struct tok_state *PyTokenizer_FromString(const char *);
  52. extern struct tok_state *PyTokenizer_FromFile(FILE *, char *, char *);
  53. extern void PyTokenizer_Free(struct tok_state *);
  54. extern int PyTokenizer_Get(struct tok_state *, char **, char **);
  55. #if defined(PGEN) || defined(Py_USING_UNICODE)
  56. extern char * PyTokenizer_RestoreEncoding(struct tok_state* tok,
  57. int len, int *offset);
  58. #endif
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* !Py_TOKENIZER_H */