htmlparse.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* A Bison parser, made by GNU Bison 3.5.1. */
  2. /* Bison interface for Yacc-like parsers in C
  3. Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
  4. Inc.
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /* As a special exception, you may create a larger work that contains
  16. part or all of the Bison parser skeleton and distribute that work
  17. under terms of your choice, so long as that work isn't itself a
  18. parser generator using the skeleton or a modified version thereof
  19. as a parser skeleton. Alternatively, if you modify or redistribute
  20. the parser skeleton itself, you may (at your option) remove this
  21. special exception, which will cause the skeleton and the resulting
  22. Bison output files to be licensed under the GNU General Public
  23. License without this special exception.
  24. This special exception was added by the Free Software Foundation in
  25. version 2.2 of Bison. */
  26. /* Undocumented macros, especially those whose name start with YY_,
  27. are private implementation details. Do not rely on them. */
  28. #ifndef YY_HTML_HTMLPARSE_H_INCLUDED
  29. # define YY_HTML_HTMLPARSE_H_INCLUDED
  30. /* Debug traces. */
  31. #ifndef HTMLDEBUG
  32. # if defined YYDEBUG
  33. #if YYDEBUG
  34. # define HTMLDEBUG 1
  35. # else
  36. # define HTMLDEBUG 0
  37. # endif
  38. # else /* ! defined YYDEBUG */
  39. # define HTMLDEBUG 0
  40. # endif /* ! defined YYDEBUG */
  41. #endif /* ! defined HTMLDEBUG */
  42. #if HTMLDEBUG
  43. extern int htmldebug;
  44. #endif
  45. /* "%code requires" blocks. */
  46. #line 26 "../../lib/common/htmlparse.y"
  47. #include <cgraph/list.h>
  48. #include <cgraph/strview.h>
  49. #include <common/htmllex.h>
  50. #include <common/htmltable.h>
  51. #include <common/textspan.h>
  52. #include <gvc/gvcext.h>
  53. #include <util/agxbuf.h>
  54. #line 66 "htmlparse.h"
  55. /* Token type. */
  56. #ifndef HTMLTOKENTYPE
  57. # define HTMLTOKENTYPE
  58. enum htmltokentype
  59. {
  60. T_end_br = 258,
  61. T_end_img = 259,
  62. T_row = 260,
  63. T_end_row = 261,
  64. T_html = 262,
  65. T_end_html = 263,
  66. T_end_table = 264,
  67. T_end_cell = 265,
  68. T_end_font = 266,
  69. T_string = 267,
  70. T_error = 268,
  71. T_n_italic = 269,
  72. T_n_bold = 270,
  73. T_n_underline = 271,
  74. T_n_overline = 272,
  75. T_n_sup = 273,
  76. T_n_sub = 274,
  77. T_n_s = 275,
  78. T_HR = 276,
  79. T_hr = 277,
  80. T_end_hr = 278,
  81. T_VR = 279,
  82. T_vr = 280,
  83. T_end_vr = 281,
  84. T_BR = 282,
  85. T_br = 283,
  86. T_IMG = 284,
  87. T_img = 285,
  88. T_table = 286,
  89. T_cell = 287,
  90. T_font = 288,
  91. T_italic = 289,
  92. T_bold = 290,
  93. T_underline = 291,
  94. T_overline = 292,
  95. T_sup = 293,
  96. T_sub = 294,
  97. T_s = 295
  98. };
  99. #endif
  100. /* Tokens. */
  101. #define T_end_br 258
  102. #define T_end_img 259
  103. #define T_row 260
  104. #define T_end_row 261
  105. #define T_html 262
  106. #define T_end_html 263
  107. #define T_end_table 264
  108. #define T_end_cell 265
  109. #define T_end_font 266
  110. #define T_string 267
  111. #define T_error 268
  112. #define T_n_italic 269
  113. #define T_n_bold 270
  114. #define T_n_underline 271
  115. #define T_n_overline 272
  116. #define T_n_sup 273
  117. #define T_n_sub 274
  118. #define T_n_s 275
  119. #define T_HR 276
  120. #define T_hr 277
  121. #define T_end_hr 278
  122. #define T_VR 279
  123. #define T_vr 280
  124. #define T_end_vr 281
  125. #define T_BR 282
  126. #define T_br 283
  127. #define T_IMG 284
  128. #define T_img 285
  129. #define T_table 286
  130. #define T_cell 287
  131. #define T_font 288
  132. #define T_italic 289
  133. #define T_bold 290
  134. #define T_underline 291
  135. #define T_overline 292
  136. #define T_sup 293
  137. #define T_sub 294
  138. #define T_s 295
  139. /* Value type. */
  140. #if ! defined HTMLSTYPE && ! defined HTMLSTYPE_IS_DECLARED
  141. union HTMLSTYPE
  142. {
  143. #line 180 "../../lib/common/htmlparse.y"
  144. int i;
  145. htmltxt_t* txt;
  146. htmlcell_t* cell;
  147. htmltbl_t* tbl;
  148. textfont_t* font;
  149. htmlimg_t* img;
  150. row_t *p;
  151. #line 167 "htmlparse.h"
  152. };
  153. typedef union HTMLSTYPE HTMLSTYPE;
  154. # define HTMLSTYPE_IS_TRIVIAL 1
  155. # define HTMLSTYPE_IS_DECLARED 1
  156. #endif
  157. int htmlparse (htmlscan_t *scanner);
  158. /* "%code provides" blocks. */
  159. #line 36 "../../lib/common/htmlparse.y"
  160. DEFINE_LIST(sfont, textfont_t *)
  161. static inline void free_ti(textspan_t item) {
  162. free(item.str);
  163. }
  164. DEFINE_LIST_WITH_DTOR(textspans, textspan_t, free_ti)
  165. static inline void free_hi(htextspan_t item) {
  166. for (size_t i = 0; i < item.nitems; i++) {
  167. free(item.items[i].str);
  168. }
  169. free(item.items);
  170. }
  171. DEFINE_LIST_WITH_DTOR(htextspans, htextspan_t, free_hi)
  172. struct htmlparserstate_s {
  173. htmllabel_t* lbl; /* Generated label */
  174. htmltbl_t* tblstack; /* Stack of tables maintained during parsing */
  175. textspans_t fitemList;
  176. htextspans_t fspanList;
  177. agxbuf* str; /* Buffer for text */
  178. sfont_t fontstack;
  179. GVC_t* gvc;
  180. };
  181. typedef struct {
  182. #ifdef HAVE_EXPAT
  183. struct XML_ParserStruct *parser;
  184. #endif
  185. char* ptr; // input source
  186. int tok; // token type
  187. agxbuf* xb; // buffer to gather T_string data
  188. agxbuf lb; // buffer for translating lexical data
  189. int warn; // set if warning given
  190. int error; // set if error given
  191. char inCell; // set if in TD to allow T_string
  192. char mode; // for handling artificial <HTML>..</HTML>
  193. strview_t currtok; // for error reporting
  194. strview_t prevtok; // for error reporting
  195. GVC_t *gvc; // current GraphViz context
  196. HTMLSTYPE *htmllval; // generated by htmlparse.y
  197. } htmllexstate_t;
  198. struct htmlscan_s {
  199. htmllexstate_t lexer;
  200. htmlparserstate_t parser;
  201. };
  202. #line 233 "htmlparse.h"
  203. #endif /* !YY_HTML_HTMLPARSE_H_INCLUDED */