2
0

json-lexer.h 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * JSON lexer
  3. *
  4. * Copyright IBM, Corp. 2009
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
  10. * See the COPYING.LIB file in the top-level directory.
  11. *
  12. */
  13. #ifndef QEMU_JSON_LEXER_H
  14. #define QEMU_JSON_LEXER_H
  15. #include "qstring.h"
  16. #include "qlist.h"
  17. typedef enum json_token_type {
  18. JSON_OPERATOR = 100,
  19. JSON_INTEGER,
  20. JSON_FLOAT,
  21. JSON_KEYWORD,
  22. JSON_STRING,
  23. JSON_ESCAPE,
  24. JSON_SKIP,
  25. JSON_ERROR,
  26. } JSONTokenType;
  27. typedef struct JSONLexer JSONLexer;
  28. typedef void (JSONLexerEmitter)(JSONLexer *, QString *, JSONTokenType, int x, int y);
  29. struct JSONLexer
  30. {
  31. JSONLexerEmitter *emit;
  32. int state;
  33. QString *token;
  34. int x, y;
  35. };
  36. void json_lexer_init(JSONLexer *lexer, JSONLexerEmitter func);
  37. int json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size);
  38. int json_lexer_flush(JSONLexer *lexer);
  39. void json_lexer_destroy(JSONLexer *lexer);
  40. #endif