gml_scanner.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2021
  3. * (C) Universitaet Passau 1986-1991
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * These are the four essential freedoms with GNU GPL software:
  19. * 1: freedom to run the program, for any purpose
  20. * 2: freedom to study how the program works, and change it to make it do what you wish
  21. * 3: freedom to redistribute copies to help your Free Software friends
  22. * 4: freedom to distribute copies of your modified versions to your Free Software friends
  23. * , ,
  24. * / \
  25. * ((__-^^-,-^^-__))
  26. * `-_---' `---_-'
  27. * `--|o` 'o|--'
  28. * \ ` /
  29. * ): :(
  30. * :o_o:
  31. * "-"
  32. *
  33. * SPDX-License-Identifier: GPL-3.0+
  34. * License-Filename: LICENSE
  35. */
  36. #ifndef GML_SCANNER_H
  37. #define GML_SCANNER_H 1
  38. /*
  39. * start-size of buffers for reading strings. If too small it will be enlarged
  40. * dynamically
  41. */
  42. #define INITIAL_SIZE 1024
  43. typedef enum {
  44. GML_KEY, GML_INT, GML_DOUBLE, GML_STRING, GML_L_BRACKET,
  45. GML_R_BRACKET, GML_END, GML_LIST, GML_ERROR
  46. } GML_value;
  47. typedef enum {
  48. GML_UNEXPECTED, GML_SYNTAX, GML_PREMATURE_EOF, GML_TOO_MANY_DIGITS,
  49. GML_OPEN_BRACKET, GML_TOO_MANY_BRACKETS, GML_OK
  50. } GML_error_value;
  51. struct GML_error {
  52. GML_error_value err_num;
  53. unsigned int line;
  54. unsigned int column;
  55. };
  56. union GML_tok_val {
  57. long integer;
  58. double floating;
  59. char *string;
  60. struct GML_error err;
  61. };
  62. struct GML_token {
  63. GML_value kind;
  64. union GML_tok_val value;
  65. };
  66. /*
  67. * global variables
  68. */
  69. extern unsigned int GML_line;
  70. extern unsigned int GML_column;
  71. /*
  72. * if you are interested in the position where an error occured it is a good
  73. * idea to set GML_line and GML_column back.
  74. * This is what GML_init does.
  75. */
  76. extern void GML_init(void);
  77. /*
  78. * returns the next token in file. If an error occured it will be stored in
  79. * GML_token.
  80. */
  81. extern struct GML_token GML_scanner(gzFile stream);
  82. extern int GML_search_ISO(char *str, int len);
  83. #endif
  84. /* end */