nokolexbor 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (486) hide show
  1. checksums.yaml +7 -0
  2. data/ext/nokolexbor/config.h +186 -0
  3. data/ext/nokolexbor/extconf.rb +131 -0
  4. data/ext/nokolexbor/libxml/HTMLparser.h +320 -0
  5. data/ext/nokolexbor/libxml/SAX2.h +173 -0
  6. data/ext/nokolexbor/libxml/chvalid.h +230 -0
  7. data/ext/nokolexbor/libxml/debugXML.h +217 -0
  8. data/ext/nokolexbor/libxml/dict.h +81 -0
  9. data/ext/nokolexbor/libxml/encoding.h +232 -0
  10. data/ext/nokolexbor/libxml/entities.h +153 -0
  11. data/ext/nokolexbor/libxml/globals.h +529 -0
  12. data/ext/nokolexbor/libxml/hash.h +236 -0
  13. data/ext/nokolexbor/libxml/list.h +137 -0
  14. data/ext/nokolexbor/libxml/parser.h +1264 -0
  15. data/ext/nokolexbor/libxml/parserInternals.h +641 -0
  16. data/ext/nokolexbor/libxml/pattern.h +100 -0
  17. data/ext/nokolexbor/libxml/threads.h +94 -0
  18. data/ext/nokolexbor/libxml/tree.h +1315 -0
  19. data/ext/nokolexbor/libxml/uri.h +94 -0
  20. data/ext/nokolexbor/libxml/valid.h +448 -0
  21. data/ext/nokolexbor/libxml/xmlIO.h +369 -0
  22. data/ext/nokolexbor/libxml/xmlautomata.h +146 -0
  23. data/ext/nokolexbor/libxml/xmlerror.h +919 -0
  24. data/ext/nokolexbor/libxml/xmlexports.h +79 -0
  25. data/ext/nokolexbor/libxml/xmlmemory.h +226 -0
  26. data/ext/nokolexbor/libxml/xmlregexp.h +222 -0
  27. data/ext/nokolexbor/libxml/xmlstring.h +140 -0
  28. data/ext/nokolexbor/libxml/xmlversion.h +526 -0
  29. data/ext/nokolexbor/libxml/xpath.h +575 -0
  30. data/ext/nokolexbor/libxml/xpathInternals.h +632 -0
  31. data/ext/nokolexbor/libxml/xpointer.h +137 -0
  32. data/ext/nokolexbor/libxml.h +76 -0
  33. data/ext/nokolexbor/memory.c +39 -0
  34. data/ext/nokolexbor/nl_document.c +51 -0
  35. data/ext/nokolexbor/nl_node.c +790 -0
  36. data/ext/nokolexbor/nl_node_set.c +368 -0
  37. data/ext/nokolexbor/nl_xpath_context.c +200 -0
  38. data/ext/nokolexbor/nokolexbor.c +63 -0
  39. data/ext/nokolexbor/nokolexbor.h +37 -0
  40. data/ext/nokolexbor/private/buf.h +70 -0
  41. data/ext/nokolexbor/private/dict.h +11 -0
  42. data/ext/nokolexbor/private/enc.h +17 -0
  43. data/ext/nokolexbor/private/error.h +21 -0
  44. data/ext/nokolexbor/private/globals.h +9 -0
  45. data/ext/nokolexbor/private/memory.h +9 -0
  46. data/ext/nokolexbor/private/parser.h +27 -0
  47. data/ext/nokolexbor/private/string.h +9 -0
  48. data/ext/nokolexbor/private/threads.h +50 -0
  49. data/ext/nokolexbor/private/tree.h +18 -0
  50. data/ext/nokolexbor/private/xpath.h +7 -0
  51. data/ext/nokolexbor/timsort.h +601 -0
  52. data/ext/nokolexbor/xml_SAX2.c +80 -0
  53. data/ext/nokolexbor/xml_buf.c +363 -0
  54. data/ext/nokolexbor/xml_chvalid.c +334 -0
  55. data/ext/nokolexbor/xml_dict.c +1264 -0
  56. data/ext/nokolexbor/xml_encoding.c +124 -0
  57. data/ext/nokolexbor/xml_error.c +134 -0
  58. data/ext/nokolexbor/xml_globals.c +1085 -0
  59. data/ext/nokolexbor/xml_hash.c +1141 -0
  60. data/ext/nokolexbor/xml_memory.c +203 -0
  61. data/ext/nokolexbor/xml_parser.c +127 -0
  62. data/ext/nokolexbor/xml_parserInternals.c +338 -0
  63. data/ext/nokolexbor/xml_pattern.c +2375 -0
  64. data/ext/nokolexbor/xml_string.c +1051 -0
  65. data/ext/nokolexbor/xml_threads.c +881 -0
  66. data/ext/nokolexbor/xml_tree.c +148 -0
  67. data/ext/nokolexbor/xml_xpath.c +14743 -0
  68. data/lib/nokolexbor/attribute.rb +18 -0
  69. data/lib/nokolexbor/document.rb +6 -0
  70. data/lib/nokolexbor/node.rb +264 -0
  71. data/lib/nokolexbor/node_set.rb +124 -0
  72. data/lib/nokolexbor/version.rb +5 -0
  73. data/lib/nokolexbor/xpath_context.rb +14 -0
  74. data/lib/nokolexbor.rb +17 -0
  75. data/patches/0001-lexbor-support-text-pseudo-element.patch +137 -0
  76. data/patches/0002-lexbor-match-id-class-case-sensitive.patch +22 -0
  77. data/patches/0003-lexbor-attach-template-content-to-self.patch +13 -0
  78. data/vendor/lexbor/CMakeLists.txt +331 -0
  79. data/vendor/lexbor/config.cmake +890 -0
  80. data/vendor/lexbor/feature.cmake +134 -0
  81. data/vendor/lexbor/source/lexbor/core/array.c +208 -0
  82. data/vendor/lexbor/source/lexbor/core/array.h +100 -0
  83. data/vendor/lexbor/source/lexbor/core/array_obj.c +216 -0
  84. data/vendor/lexbor/source/lexbor/core/array_obj.h +134 -0
  85. data/vendor/lexbor/source/lexbor/core/avl.c +442 -0
  86. data/vendor/lexbor/source/lexbor/core/avl.h +82 -0
  87. data/vendor/lexbor/source/lexbor/core/base.h +86 -0
  88. data/vendor/lexbor/source/lexbor/core/bst.c +468 -0
  89. data/vendor/lexbor/source/lexbor/core/bst.h +108 -0
  90. data/vendor/lexbor/source/lexbor/core/bst_map.c +238 -0
  91. data/vendor/lexbor/source/lexbor/core/bst_map.h +87 -0
  92. data/vendor/lexbor/source/lexbor/core/config.cmake +12 -0
  93. data/vendor/lexbor/source/lexbor/core/conv.c +203 -0
  94. data/vendor/lexbor/source/lexbor/core/conv.h +53 -0
  95. data/vendor/lexbor/source/lexbor/core/core.h +35 -0
  96. data/vendor/lexbor/source/lexbor/core/def.h +57 -0
  97. data/vendor/lexbor/source/lexbor/core/diyfp.c +153 -0
  98. data/vendor/lexbor/source/lexbor/core/diyfp.h +258 -0
  99. data/vendor/lexbor/source/lexbor/core/dobject.c +187 -0
  100. data/vendor/lexbor/source/lexbor/core/dobject.h +92 -0
  101. data/vendor/lexbor/source/lexbor/core/dtoa.c +404 -0
  102. data/vendor/lexbor/source/lexbor/core/dtoa.h +28 -0
  103. data/vendor/lexbor/source/lexbor/core/fs.h +60 -0
  104. data/vendor/lexbor/source/lexbor/core/hash.c +476 -0
  105. data/vendor/lexbor/source/lexbor/core/hash.h +218 -0
  106. data/vendor/lexbor/source/lexbor/core/in.c +267 -0
  107. data/vendor/lexbor/source/lexbor/core/in.h +172 -0
  108. data/vendor/lexbor/source/lexbor/core/lexbor.h +35 -0
  109. data/vendor/lexbor/source/lexbor/core/mem.c +228 -0
  110. data/vendor/lexbor/source/lexbor/core/mem.h +141 -0
  111. data/vendor/lexbor/source/lexbor/core/mraw.c +428 -0
  112. data/vendor/lexbor/source/lexbor/core/mraw.h +114 -0
  113. data/vendor/lexbor/source/lexbor/core/perf.h +45 -0
  114. data/vendor/lexbor/source/lexbor/core/plog.c +73 -0
  115. data/vendor/lexbor/source/lexbor/core/plog.h +102 -0
  116. data/vendor/lexbor/source/lexbor/core/print.c +168 -0
  117. data/vendor/lexbor/source/lexbor/core/print.h +39 -0
  118. data/vendor/lexbor/source/lexbor/core/sbst.h +59 -0
  119. data/vendor/lexbor/source/lexbor/core/serialize.c +27 -0
  120. data/vendor/lexbor/source/lexbor/core/serialize.h +32 -0
  121. data/vendor/lexbor/source/lexbor/core/shs.c +118 -0
  122. data/vendor/lexbor/source/lexbor/core/shs.h +82 -0
  123. data/vendor/lexbor/source/lexbor/core/str.c +617 -0
  124. data/vendor/lexbor/source/lexbor/core/str.h +247 -0
  125. data/vendor/lexbor/source/lexbor/core/str_res.h +369 -0
  126. data/vendor/lexbor/source/lexbor/core/strtod.c +326 -0
  127. data/vendor/lexbor/source/lexbor/core/strtod.h +28 -0
  128. data/vendor/lexbor/source/lexbor/core/types.h +39 -0
  129. data/vendor/lexbor/source/lexbor/core/utils.c +43 -0
  130. data/vendor/lexbor/source/lexbor/core/utils.h +36 -0
  131. data/vendor/lexbor/source/lexbor/css/base.h +44 -0
  132. data/vendor/lexbor/source/lexbor/css/config.cmake +2 -0
  133. data/vendor/lexbor/source/lexbor/css/css.h +25 -0
  134. data/vendor/lexbor/source/lexbor/css/log.c +336 -0
  135. data/vendor/lexbor/source/lexbor/css/log.h +103 -0
  136. data/vendor/lexbor/source/lexbor/css/node.h +29 -0
  137. data/vendor/lexbor/source/lexbor/css/parser.c +473 -0
  138. data/vendor/lexbor/source/lexbor/css/parser.h +368 -0
  139. data/vendor/lexbor/source/lexbor/css/selectors/base.h +48 -0
  140. data/vendor/lexbor/source/lexbor/css/selectors/pseudo.c +91 -0
  141. data/vendor/lexbor/source/lexbor/css/selectors/pseudo.h +66 -0
  142. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_const.h +109 -0
  143. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_res.h +302 -0
  144. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.c +279 -0
  145. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.h +85 -0
  146. data/vendor/lexbor/source/lexbor/css/selectors/selector.c +927 -0
  147. data/vendor/lexbor/source/lexbor/css/selectors/selector.h +200 -0
  148. data/vendor/lexbor/source/lexbor/css/selectors/selectors.c +340 -0
  149. data/vendor/lexbor/source/lexbor/css/selectors/selectors.h +137 -0
  150. data/vendor/lexbor/source/lexbor/css/selectors/state.c +1718 -0
  151. data/vendor/lexbor/source/lexbor/css/selectors/state.h +79 -0
  152. data/vendor/lexbor/source/lexbor/css/stylesheet.h +37 -0
  153. data/vendor/lexbor/source/lexbor/css/syntax/anb.c +443 -0
  154. data/vendor/lexbor/source/lexbor/css/syntax/anb.h +45 -0
  155. data/vendor/lexbor/source/lexbor/css/syntax/base.h +33 -0
  156. data/vendor/lexbor/source/lexbor/css/syntax/parser.c +9 -0
  157. data/vendor/lexbor/source/lexbor/css/syntax/parser.h +25 -0
  158. data/vendor/lexbor/source/lexbor/css/syntax/res.h +48 -0
  159. data/vendor/lexbor/source/lexbor/css/syntax/state.c +2603 -0
  160. data/vendor/lexbor/source/lexbor/css/syntax/state.h +140 -0
  161. data/vendor/lexbor/source/lexbor/css/syntax/state_res.h +273 -0
  162. data/vendor/lexbor/source/lexbor/css/syntax/syntax.c +67 -0
  163. data/vendor/lexbor/source/lexbor/css/syntax/token.c +618 -0
  164. data/vendor/lexbor/source/lexbor/css/syntax/token.h +298 -0
  165. data/vendor/lexbor/source/lexbor/css/syntax/token_res.h +68 -0
  166. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.c +30 -0
  167. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.h +58 -0
  168. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.c +278 -0
  169. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.h +121 -0
  170. data/vendor/lexbor/source/lexbor/dom/base.h +32 -0
  171. data/vendor/lexbor/source/lexbor/dom/collection.c +97 -0
  172. data/vendor/lexbor/source/lexbor/dom/collection.h +112 -0
  173. data/vendor/lexbor/source/lexbor/dom/config.cmake +3 -0
  174. data/vendor/lexbor/source/lexbor/dom/dom.h +29 -0
  175. data/vendor/lexbor/source/lexbor/dom/exception.c +18 -0
  176. data/vendor/lexbor/source/lexbor/dom/exception.h +73 -0
  177. data/vendor/lexbor/source/lexbor/dom/interface.c +110 -0
  178. data/vendor/lexbor/source/lexbor/dom/interface.h +88 -0
  179. data/vendor/lexbor/source/lexbor/dom/interfaces/attr.c +445 -0
  180. data/vendor/lexbor/source/lexbor/dom/interfaces/attr.h +152 -0
  181. data/vendor/lexbor/source/lexbor/dom/interfaces/attr_const.h +62 -0
  182. data/vendor/lexbor/source/lexbor/dom/interfaces/attr_res.h +143 -0
  183. data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.c +55 -0
  184. data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.h +38 -0
  185. data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.c +110 -0
  186. data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.h +51 -0
  187. data/vendor/lexbor/source/lexbor/dom/interfaces/comment.c +64 -0
  188. data/vendor/lexbor/source/lexbor/dom/interfaces/comment.h +42 -0
  189. data/vendor/lexbor/source/lexbor/dom/interfaces/document.c +536 -0
  190. data/vendor/lexbor/source/lexbor/dom/interfaces/document.h +243 -0
  191. data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.c +36 -0
  192. data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.h +36 -0
  193. data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.c +125 -0
  194. data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.h +108 -0
  195. data/vendor/lexbor/source/lexbor/dom/interfaces/element.c +1411 -0
  196. data/vendor/lexbor/source/lexbor/dom/interfaces/element.h +319 -0
  197. data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.c +32 -0
  198. data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.h +34 -0
  199. data/vendor/lexbor/source/lexbor/dom/interfaces/node.c +661 -0
  200. data/vendor/lexbor/source/lexbor/dom/interfaces/node.h +192 -0
  201. data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.c +87 -0
  202. data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.h +66 -0
  203. data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.c +36 -0
  204. data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.h +44 -0
  205. data/vendor/lexbor/source/lexbor/dom/interfaces/text.c +63 -0
  206. data/vendor/lexbor/source/lexbor/dom/interfaces/text.h +42 -0
  207. data/vendor/lexbor/source/lexbor/encoding/base.h +218 -0
  208. data/vendor/lexbor/source/lexbor/encoding/big5.c +42839 -0
  209. data/vendor/lexbor/source/lexbor/encoding/config.cmake +12 -0
  210. data/vendor/lexbor/source/lexbor/encoding/const.h +65 -0
  211. data/vendor/lexbor/source/lexbor/encoding/decode.c +3193 -0
  212. data/vendor/lexbor/source/lexbor/encoding/decode.h +370 -0
  213. data/vendor/lexbor/source/lexbor/encoding/encode.c +1931 -0
  214. data/vendor/lexbor/source/lexbor/encoding/encode.h +377 -0
  215. data/vendor/lexbor/source/lexbor/encoding/encoding.c +252 -0
  216. data/vendor/lexbor/source/lexbor/encoding/encoding.h +475 -0
  217. data/vendor/lexbor/source/lexbor/encoding/euc_kr.c +53883 -0
  218. data/vendor/lexbor/source/lexbor/encoding/gb18030.c +47905 -0
  219. data/vendor/lexbor/source/lexbor/encoding/iso_2022_jp_katakana.c +159 -0
  220. data/vendor/lexbor/source/lexbor/encoding/jis0208.c +22477 -0
  221. data/vendor/lexbor/source/lexbor/encoding/jis0212.c +15787 -0
  222. data/vendor/lexbor/source/lexbor/encoding/multi.h +53 -0
  223. data/vendor/lexbor/source/lexbor/encoding/range.c +71 -0
  224. data/vendor/lexbor/source/lexbor/encoding/range.h +34 -0
  225. data/vendor/lexbor/source/lexbor/encoding/res.c +222 -0
  226. data/vendor/lexbor/source/lexbor/encoding/res.h +34 -0
  227. data/vendor/lexbor/source/lexbor/encoding/single.c +13748 -0
  228. data/vendor/lexbor/source/lexbor/encoding/single.h +116 -0
  229. data/vendor/lexbor/source/lexbor/html/base.h +44 -0
  230. data/vendor/lexbor/source/lexbor/html/config.cmake +3 -0
  231. data/vendor/lexbor/source/lexbor/html/encoding.c +574 -0
  232. data/vendor/lexbor/source/lexbor/html/encoding.h +106 -0
  233. data/vendor/lexbor/source/lexbor/html/html.h +107 -0
  234. data/vendor/lexbor/source/lexbor/html/interface.c +165 -0
  235. data/vendor/lexbor/source/lexbor/html/interface.h +186 -0
  236. data/vendor/lexbor/source/lexbor/html/interface_res.h +4449 -0
  237. data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.c +36 -0
  238. data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.h +34 -0
  239. data/vendor/lexbor/source/lexbor/html/interfaces/area_element.c +36 -0
  240. data/vendor/lexbor/source/lexbor/html/interfaces/area_element.h +34 -0
  241. data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.c +36 -0
  242. data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.h +34 -0
  243. data/vendor/lexbor/source/lexbor/html/interfaces/base_element.c +36 -0
  244. data/vendor/lexbor/source/lexbor/html/interfaces/base_element.h +34 -0
  245. data/vendor/lexbor/source/lexbor/html/interfaces/body_element.c +36 -0
  246. data/vendor/lexbor/source/lexbor/html/interfaces/body_element.h +34 -0
  247. data/vendor/lexbor/source/lexbor/html/interfaces/br_element.c +36 -0
  248. data/vendor/lexbor/source/lexbor/html/interfaces/br_element.h +34 -0
  249. data/vendor/lexbor/source/lexbor/html/interfaces/button_element.c +36 -0
  250. data/vendor/lexbor/source/lexbor/html/interfaces/button_element.h +34 -0
  251. data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.c +36 -0
  252. data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.h +34 -0
  253. data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.c +36 -0
  254. data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.h +34 -0
  255. data/vendor/lexbor/source/lexbor/html/interfaces/data_element.c +36 -0
  256. data/vendor/lexbor/source/lexbor/html/interfaces/data_element.h +34 -0
  257. data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.c +36 -0
  258. data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.h +34 -0
  259. data/vendor/lexbor/source/lexbor/html/interfaces/details_element.c +36 -0
  260. data/vendor/lexbor/source/lexbor/html/interfaces/details_element.h +34 -0
  261. data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.c +36 -0
  262. data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.h +34 -0
  263. data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.c +36 -0
  264. data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.h +34 -0
  265. data/vendor/lexbor/source/lexbor/html/interfaces/div_element.c +36 -0
  266. data/vendor/lexbor/source/lexbor/html/interfaces/div_element.h +34 -0
  267. data/vendor/lexbor/source/lexbor/html/interfaces/document.c +444 -0
  268. data/vendor/lexbor/source/lexbor/html/interfaces/document.h +256 -0
  269. data/vendor/lexbor/source/lexbor/html/interfaces/element.c +64 -0
  270. data/vendor/lexbor/source/lexbor/html/interfaces/element.h +54 -0
  271. data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.c +36 -0
  272. data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.h +34 -0
  273. data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.c +36 -0
  274. data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.h +34 -0
  275. data/vendor/lexbor/source/lexbor/html/interfaces/font_element.c +36 -0
  276. data/vendor/lexbor/source/lexbor/html/interfaces/font_element.h +34 -0
  277. data/vendor/lexbor/source/lexbor/html/interfaces/form_element.c +36 -0
  278. data/vendor/lexbor/source/lexbor/html/interfaces/form_element.h +34 -0
  279. data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.c +36 -0
  280. data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.h +34 -0
  281. data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.c +36 -0
  282. data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.h +34 -0
  283. data/vendor/lexbor/source/lexbor/html/interfaces/head_element.c +36 -0
  284. data/vendor/lexbor/source/lexbor/html/interfaces/head_element.h +34 -0
  285. data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.c +36 -0
  286. data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.h +34 -0
  287. data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.c +36 -0
  288. data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.h +34 -0
  289. data/vendor/lexbor/source/lexbor/html/interfaces/html_element.c +36 -0
  290. data/vendor/lexbor/source/lexbor/html/interfaces/html_element.h +34 -0
  291. data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.c +36 -0
  292. data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.h +34 -0
  293. data/vendor/lexbor/source/lexbor/html/interfaces/image_element.c +36 -0
  294. data/vendor/lexbor/source/lexbor/html/interfaces/image_element.h +34 -0
  295. data/vendor/lexbor/source/lexbor/html/interfaces/input_element.c +36 -0
  296. data/vendor/lexbor/source/lexbor/html/interfaces/input_element.h +34 -0
  297. data/vendor/lexbor/source/lexbor/html/interfaces/label_element.c +36 -0
  298. data/vendor/lexbor/source/lexbor/html/interfaces/label_element.h +34 -0
  299. data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.c +36 -0
  300. data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.h +34 -0
  301. data/vendor/lexbor/source/lexbor/html/interfaces/li_element.c +36 -0
  302. data/vendor/lexbor/source/lexbor/html/interfaces/li_element.h +34 -0
  303. data/vendor/lexbor/source/lexbor/html/interfaces/link_element.c +36 -0
  304. data/vendor/lexbor/source/lexbor/html/interfaces/link_element.h +34 -0
  305. data/vendor/lexbor/source/lexbor/html/interfaces/map_element.c +36 -0
  306. data/vendor/lexbor/source/lexbor/html/interfaces/map_element.h +34 -0
  307. data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.c +36 -0
  308. data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.h +34 -0
  309. data/vendor/lexbor/source/lexbor/html/interfaces/media_element.c +36 -0
  310. data/vendor/lexbor/source/lexbor/html/interfaces/media_element.h +34 -0
  311. data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.c +36 -0
  312. data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.h +34 -0
  313. data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.c +36 -0
  314. data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.h +34 -0
  315. data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.c +36 -0
  316. data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.h +34 -0
  317. data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.c +36 -0
  318. data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.h +34 -0
  319. data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.c +36 -0
  320. data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.h +34 -0
  321. data/vendor/lexbor/source/lexbor/html/interfaces/object_element.c +36 -0
  322. data/vendor/lexbor/source/lexbor/html/interfaces/object_element.h +34 -0
  323. data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.c +36 -0
  324. data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.h +34 -0
  325. data/vendor/lexbor/source/lexbor/html/interfaces/option_element.c +36 -0
  326. data/vendor/lexbor/source/lexbor/html/interfaces/option_element.h +34 -0
  327. data/vendor/lexbor/source/lexbor/html/interfaces/output_element.c +36 -0
  328. data/vendor/lexbor/source/lexbor/html/interfaces/output_element.h +34 -0
  329. data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.c +36 -0
  330. data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.h +34 -0
  331. data/vendor/lexbor/source/lexbor/html/interfaces/param_element.c +36 -0
  332. data/vendor/lexbor/source/lexbor/html/interfaces/param_element.h +34 -0
  333. data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.c +36 -0
  334. data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.h +34 -0
  335. data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.c +36 -0
  336. data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.h +34 -0
  337. data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.c +36 -0
  338. data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.h +34 -0
  339. data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.c +36 -0
  340. data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.h +34 -0
  341. data/vendor/lexbor/source/lexbor/html/interfaces/script_element.c +36 -0
  342. data/vendor/lexbor/source/lexbor/html/interfaces/script_element.h +34 -0
  343. data/vendor/lexbor/source/lexbor/html/interfaces/select_element.c +36 -0
  344. data/vendor/lexbor/source/lexbor/html/interfaces/select_element.h +34 -0
  345. data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.c +36 -0
  346. data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.h +34 -0
  347. data/vendor/lexbor/source/lexbor/html/interfaces/source_element.c +36 -0
  348. data/vendor/lexbor/source/lexbor/html/interfaces/source_element.h +34 -0
  349. data/vendor/lexbor/source/lexbor/html/interfaces/span_element.c +36 -0
  350. data/vendor/lexbor/source/lexbor/html/interfaces/span_element.h +34 -0
  351. data/vendor/lexbor/source/lexbor/html/interfaces/style_element.c +36 -0
  352. data/vendor/lexbor/source/lexbor/html/interfaces/style_element.h +34 -0
  353. data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.c +36 -0
  354. data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.h +34 -0
  355. data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.c +36 -0
  356. data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.h +34 -0
  357. data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.c +36 -0
  358. data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.h +34 -0
  359. data/vendor/lexbor/source/lexbor/html/interfaces/table_element.c +36 -0
  360. data/vendor/lexbor/source/lexbor/html/interfaces/table_element.h +34 -0
  361. data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.c +36 -0
  362. data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.h +34 -0
  363. data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.c +36 -0
  364. data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.h +34 -0
  365. data/vendor/lexbor/source/lexbor/html/interfaces/template_element.c +46 -0
  366. data/vendor/lexbor/source/lexbor/html/interfaces/template_element.h +38 -0
  367. data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.c +36 -0
  368. data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.h +34 -0
  369. data/vendor/lexbor/source/lexbor/html/interfaces/time_element.c +36 -0
  370. data/vendor/lexbor/source/lexbor/html/interfaces/time_element.h +34 -0
  371. data/vendor/lexbor/source/lexbor/html/interfaces/title_element.c +133 -0
  372. data/vendor/lexbor/source/lexbor/html/interfaces/title_element.h +42 -0
  373. data/vendor/lexbor/source/lexbor/html/interfaces/track_element.c +36 -0
  374. data/vendor/lexbor/source/lexbor/html/interfaces/track_element.h +34 -0
  375. data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.c +36 -0
  376. data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.h +34 -0
  377. data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.c +36 -0
  378. data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.h +34 -0
  379. data/vendor/lexbor/source/lexbor/html/interfaces/video_element.c +36 -0
  380. data/vendor/lexbor/source/lexbor/html/interfaces/video_element.h +34 -0
  381. data/vendor/lexbor/source/lexbor/html/interfaces/window.c +36 -0
  382. data/vendor/lexbor/source/lexbor/html/interfaces/window.h +34 -0
  383. data/vendor/lexbor/source/lexbor/html/node.c +14 -0
  384. data/vendor/lexbor/source/lexbor/html/node.h +67 -0
  385. data/vendor/lexbor/source/lexbor/html/parser.c +469 -0
  386. data/vendor/lexbor/source/lexbor/html/parser.h +170 -0
  387. data/vendor/lexbor/source/lexbor/html/serialize.c +1510 -0
  388. data/vendor/lexbor/source/lexbor/html/serialize.h +93 -0
  389. data/vendor/lexbor/source/lexbor/html/tag.h +103 -0
  390. data/vendor/lexbor/source/lexbor/html/tag_res.h +2262 -0
  391. data/vendor/lexbor/source/lexbor/html/token.c +386 -0
  392. data/vendor/lexbor/source/lexbor/html/token.h +130 -0
  393. data/vendor/lexbor/source/lexbor/html/token_attr.c +44 -0
  394. data/vendor/lexbor/source/lexbor/html/token_attr.h +67 -0
  395. data/vendor/lexbor/source/lexbor/html/tokenizer/error.c +28 -0
  396. data/vendor/lexbor/source/lexbor/html/tokenizer/error.h +141 -0
  397. data/vendor/lexbor/source/lexbor/html/tokenizer/res.h +4956 -0
  398. data/vendor/lexbor/source/lexbor/html/tokenizer/state.c +2171 -0
  399. data/vendor/lexbor/source/lexbor/html/tokenizer/state.h +225 -0
  400. data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.c +489 -0
  401. data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.h +27 -0
  402. data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.c +1654 -0
  403. data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.h +27 -0
  404. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.c +303 -0
  405. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.h +32 -0
  406. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.c +311 -0
  407. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.h +32 -0
  408. data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.c +1209 -0
  409. data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.h +32 -0
  410. data/vendor/lexbor/source/lexbor/html/tokenizer.c +499 -0
  411. data/vendor/lexbor/source/lexbor/html/tokenizer.h +343 -0
  412. data/vendor/lexbor/source/lexbor/html/tree/active_formatting.c +241 -0
  413. data/vendor/lexbor/source/lexbor/html/tree/active_formatting.h +117 -0
  414. data/vendor/lexbor/source/lexbor/html/tree/error.c +26 -0
  415. data/vendor/lexbor/source/lexbor/html/tree/error.h +114 -0
  416. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_body.c +62 -0
  417. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_frameset.c +63 -0
  418. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_body.c +82 -0
  419. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_frameset.c +88 -0
  420. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_head.c +222 -0
  421. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_head.c +144 -0
  422. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_html.c +166 -0
  423. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/foreign_content.c +358 -0
  424. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_body.c +1974 -0
  425. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_caption.c +158 -0
  426. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_cell.c +187 -0
  427. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_column_group.c +194 -0
  428. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_frameset.c +149 -0
  429. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head.c +374 -0
  430. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head_noscript.c +121 -0
  431. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_row.c +211 -0
  432. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select.c +341 -0
  433. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select_in_table.c +115 -0
  434. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table.c +451 -0
  435. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_body.c +208 -0
  436. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_text.c +127 -0
  437. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_template.c +189 -0
  438. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/initial.c +411 -0
  439. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/text.c +61 -0
  440. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode.h +135 -0
  441. data/vendor/lexbor/source/lexbor/html/tree/open_elements.c +251 -0
  442. data/vendor/lexbor/source/lexbor/html/tree/open_elements.h +105 -0
  443. data/vendor/lexbor/source/lexbor/html/tree/template_insertion.c +10 -0
  444. data/vendor/lexbor/source/lexbor/html/tree/template_insertion.h +100 -0
  445. data/vendor/lexbor/source/lexbor/html/tree.c +1726 -0
  446. data/vendor/lexbor/source/lexbor/html/tree.h +431 -0
  447. data/vendor/lexbor/source/lexbor/html/tree_res.h +111 -0
  448. data/vendor/lexbor/source/lexbor/ns/base.h +32 -0
  449. data/vendor/lexbor/source/lexbor/ns/config.cmake +2 -0
  450. data/vendor/lexbor/source/lexbor/ns/const.h +37 -0
  451. data/vendor/lexbor/source/lexbor/ns/ns.c +154 -0
  452. data/vendor/lexbor/source/lexbor/ns/ns.h +66 -0
  453. data/vendor/lexbor/source/lexbor/ns/res.h +97 -0
  454. data/vendor/lexbor/source/lexbor/ports/posix/config.cmake +11 -0
  455. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/fs.c +236 -0
  456. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/memory.c +33 -0
  457. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/perf.c +158 -0
  458. data/vendor/lexbor/source/lexbor/ports/windows_nt/config.cmake +18 -0
  459. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/fs.c +239 -0
  460. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/memory.c +33 -0
  461. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/perf.c +81 -0
  462. data/vendor/lexbor/source/lexbor/selectors/base.h +30 -0
  463. data/vendor/lexbor/source/lexbor/selectors/config.cmake +2 -0
  464. data/vendor/lexbor/source/lexbor/selectors/selectors.c +1591 -0
  465. data/vendor/lexbor/source/lexbor/selectors/selectors.h +71 -0
  466. data/vendor/lexbor/source/lexbor/tag/base.h +32 -0
  467. data/vendor/lexbor/source/lexbor/tag/config.cmake +2 -0
  468. data/vendor/lexbor/source/lexbor/tag/const.h +225 -0
  469. data/vendor/lexbor/source/lexbor/tag/res.h +562 -0
  470. data/vendor/lexbor/source/lexbor/tag/tag.c +144 -0
  471. data/vendor/lexbor/source/lexbor/tag/tag.h +123 -0
  472. data/vendor/lexbor/source/lexbor/utils/base.h +32 -0
  473. data/vendor/lexbor/source/lexbor/utils/config.cmake +2 -0
  474. data/vendor/lexbor/source/lexbor/utils/http.c +534 -0
  475. data/vendor/lexbor/source/lexbor/utils/http.h +90 -0
  476. data/vendor/lexbor/source/lexbor/utils/utils.h +15 -0
  477. data/vendor/lexbor/source/lexbor/utils/warc.c +817 -0
  478. data/vendor/lexbor/source/lexbor/utils/warc.h +126 -0
  479. data/vendor/lexbor/utils/lexbor/css/selectors/pseudo.py +231 -0
  480. data/vendor/lexbor/utils/lexbor/css/selectors/tmp/const.h +21 -0
  481. data/vendor/lexbor/utils/lexbor/css/selectors/tmp/res.h +26 -0
  482. data/vendor/lexbor/utils/lexbor/css/syntax/definitions.py +49 -0
  483. data/vendor/lexbor/utils/lexbor/css/syntax/token_res.py +54 -0
  484. data/vendor/lexbor/utils/lexbor/css/syntax/tokenizer_code_map.py +36 -0
  485. data/vendor/lexbor/version +1 -0
  486. metadata +542 -0
@@ -0,0 +1,1718 @@
1
+ /*
2
+ * Copyright (C) 2020-2021 Alexander Borisov
3
+ *
4
+ * Author: Alexander Borisov <borisov@lexbor.com>
5
+ */
6
+
7
+ #include "lexbor/css/parser.h"
8
+ #include "lexbor/css/selectors/state.h"
9
+ #include "lexbor/css/selectors/selectors.h"
10
+ #include "lexbor/css/selectors/pseudo.h"
11
+ #include "lexbor/css/selectors/pseudo_const.h"
12
+
13
+
14
+ static const char lxb_css_selectors_module_name[] = "Selectors";
15
+
16
+
17
+ #define lxb_css_selectors_state_string_dup_m(selectors, name) \
18
+ do { \
19
+ (status) = lxb_css_syntax_token_string_dup( \
20
+ lxb_css_syntax_token_string(token), (name), \
21
+ (selectors)->memory->mraw); \
22
+ if ((status) != LXB_STATUS_OK) { \
23
+ return (status); \
24
+ } \
25
+ } \
26
+ while (false)
27
+
28
+ #define lxb_css_selectors_state_append(parser, selectors, selector) \
29
+ do { \
30
+ (selector) = lxb_css_selector_create((selectors)->list_last); \
31
+ if ((selector) == NULL) { \
32
+ return lxb_css_parser_memory_fail(parser); \
33
+ } \
34
+ \
35
+ lxb_css_selectors_append_next((selectors), (selector)); \
36
+ \
37
+ (selector)->combinator = (selectors)->combinator; \
38
+ (selectors)->combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE; \
39
+ } \
40
+ while (false)
41
+
42
+ #define lxb_css_selectors_state_list_append(parser, selectors, list) \
43
+ do { \
44
+ (list) = lxb_css_selector_list_create((selectors)->memory); \
45
+ if ((list) == NULL) { \
46
+ return lxb_css_parser_memory_fail(parser); \
47
+ } \
48
+ \
49
+ lxb_css_selectors_list_append_next((selectors), (list)); \
50
+ \
51
+ (list)->parent = selectors->parent; \
52
+ } \
53
+ while (false)
54
+
55
+
56
+ lxb_css_syntax_token_t *
57
+ lxb_css_selectors_close_parenthesis(lxb_css_parser_t *parser,
58
+ lxb_css_syntax_token_t *token);
59
+
60
+ static bool
61
+ lxb_css_selectors_state_complex_list_end(lxb_css_parser_t *parser,
62
+ lxb_css_syntax_token_t *token, void *ctx);
63
+
64
+ static bool
65
+ lxb_css_selectors_state_relative_list_end(lxb_css_parser_t *parser,
66
+ lxb_css_syntax_token_t *token, void *ctx);
67
+
68
+ static bool
69
+ lxb_css_selectors_state_complex_end(lxb_css_parser_t *parser,
70
+ lxb_css_syntax_token_t *token, void *ctx);
71
+
72
+ static bool
73
+ lxb_css_selectors_state_compound_list_end(lxb_css_parser_t *parser,
74
+ lxb_css_syntax_token_t *token, void *ctx);
75
+
76
+ static bool
77
+ lxb_css_selectors_state_compound_handler(lxb_css_parser_t *parser,
78
+ lxb_css_syntax_token_t *token, void *ctx);
79
+
80
+ static bool
81
+ lxb_css_selectors_state_compound_sub(lxb_css_parser_t *parser,
82
+ lxb_css_syntax_token_t *token, void *ctx);
83
+
84
+ static bool
85
+ lxb_css_selectors_state_compound_pseudo(lxb_css_parser_t *parser,
86
+ lxb_css_syntax_token_t *token, void *ctx);
87
+
88
+ static bool
89
+ lxb_css_selectors_state_simple_list_end(lxb_css_parser_t *parser,
90
+ lxb_css_syntax_token_t *token, void *ctx);
91
+
92
+ static bool
93
+ lxb_css_selectors_state_simple_handler(lxb_css_parser_t *parser,
94
+ lxb_css_syntax_token_t *token, void *ctx);
95
+
96
+ static lxb_status_t
97
+ lxb_css_selectors_state_hash(lxb_css_parser_t *parser,
98
+ lxb_css_syntax_token_t *token);
99
+
100
+ static lxb_status_t
101
+ lxb_css_selectors_state_class(lxb_css_parser_t *parser,
102
+ lxb_css_syntax_token_t *token);
103
+
104
+ static lxb_status_t
105
+ lxb_css_selectors_state_element_ns(lxb_css_parser_t *parser,
106
+ lxb_css_syntax_token_t *token);
107
+
108
+ static lxb_status_t
109
+ lxb_css_selectors_state_element(lxb_css_parser_t *parser,
110
+ lxb_css_syntax_token_t *token);
111
+
112
+ static lxb_status_t
113
+ lxb_css_selectors_state_attribute(lxb_css_parser_t *parser);
114
+
115
+ static lxb_status_t
116
+ lxb_css_selectors_state_ns(lxb_css_parser_t *parser,
117
+ lxb_css_selector_t *selector);
118
+
119
+ static lxb_status_t
120
+ lxb_css_selectors_state_ns_ident(lxb_css_parser_t *parser,
121
+ lxb_css_selector_t *selector);
122
+
123
+ static lxb_status_t
124
+ lxb_css_selectors_state_pseudo_class(lxb_css_parser_t *parser,
125
+ lxb_css_syntax_token_t *token);
126
+
127
+ static lxb_status_t
128
+ lxb_css_selectors_state_pseudo_class_function(lxb_css_parser_t *parser,
129
+ lxb_css_syntax_token_t *token,
130
+ lxb_css_parser_state_f success);
131
+
132
+ static lxb_status_t
133
+ lxb_css_selectors_state_pseudo_element(lxb_css_parser_t *parser,
134
+ lxb_css_syntax_token_t *token);
135
+
136
+ static lxb_status_t
137
+ lxb_css_selectors_state_pseudo_element_function(lxb_css_parser_t *parser,
138
+ lxb_css_syntax_token_t *token,
139
+ lxb_css_parser_state_f success);
140
+
141
+ static bool
142
+ lxb_css_selectors_state_forgiving_cb(lxb_css_parser_t *parser,
143
+ lxb_css_syntax_token_t *token, void *ctx,
144
+ lxb_css_parser_state_f state);
145
+
146
+ static void
147
+ lxb_css_selectors_state_restore_parent(lxb_css_selectors_t *selectors,
148
+ lxb_css_selector_list_t *last);
149
+
150
+ static bool
151
+ lxb_css_selectors_state_list_end(lxb_css_parser_t *parser,
152
+ lxb_css_syntax_token_t *token,
153
+ lxb_css_parser_state_f state);
154
+
155
+
156
+ lxb_inline bool
157
+ lxb_css_selectors_done(lxb_css_parser_t *parser)
158
+ {
159
+ (void) lxb_css_parser_stack_pop(parser);
160
+
161
+ return true;
162
+ }
163
+
164
+
165
+ /*
166
+ * <complex-selector-list>
167
+ */
168
+ bool
169
+ lxb_css_selectors_state_complex_list(lxb_css_parser_t *parser,
170
+ lxb_css_syntax_token_t *token, void *ctx)
171
+ {
172
+ lxb_css_parser_stack_t *stack;
173
+
174
+ stack = lxb_css_parser_stack_push(parser, lxb_css_selectors_state_complex_list_end,
175
+ ctx, false);
176
+ if (stack == NULL) {
177
+ return lxb_css_parser_memory_fail(parser);
178
+ }
179
+
180
+ parser->state = lxb_css_selectors_state_complex;
181
+
182
+ return false;
183
+ }
184
+
185
+ static bool
186
+ lxb_css_selectors_state_complex_list_end(lxb_css_parser_t *parser,
187
+ lxb_css_syntax_token_t *token, void *ctx)
188
+ {
189
+ return lxb_css_selectors_state_list_end(parser, token,
190
+ lxb_css_selectors_state_complex);
191
+ }
192
+
193
+ /*
194
+ * <relative-selector-list>
195
+ */
196
+ bool
197
+ lxb_css_selectors_state_relative_list(lxb_css_parser_t *parser,
198
+ lxb_css_syntax_token_t *token, void *ctx)
199
+ {
200
+ lxb_css_parser_stack_t *stack;
201
+
202
+ stack = lxb_css_parser_stack_push(parser, lxb_css_selectors_state_relative_list_end,
203
+ ctx, false);
204
+ if (stack == NULL) {
205
+ return lxb_css_parser_memory_fail(parser);
206
+ }
207
+
208
+ parser->state = lxb_css_selectors_state_relative;
209
+
210
+ return false;
211
+ }
212
+
213
+ static bool
214
+ lxb_css_selectors_state_relative_list_end(lxb_css_parser_t *parser,
215
+ lxb_css_syntax_token_t *token, void *ctx)
216
+ {
217
+ return lxb_css_selectors_state_list_end(parser, token,
218
+ lxb_css_selectors_state_relative);
219
+ }
220
+
221
+ /*
222
+ * <relative-selector>
223
+ */
224
+ bool
225
+ lxb_css_selectors_state_relative(lxb_css_parser_t *parser,
226
+ lxb_css_syntax_token_t *token, void *ctx)
227
+ {
228
+ lxb_css_parser_stack_t *stack;
229
+ lxb_css_selectors_t *selectors = parser->selectors;
230
+
231
+ /* <combinator> */
232
+
233
+ switch (token->type) {
234
+ case LXB_CSS_SYNTAX_TOKEN_WHITESPACE:
235
+ lxb_css_syntax_token_consume(parser->tkz);
236
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT;
237
+ return true;
238
+
239
+ case LXB_CSS_SYNTAX_TOKEN_DELIM:
240
+ switch (lxb_css_syntax_token_delim_char(token)) {
241
+ case '>':
242
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_CHILD;
243
+ break;
244
+
245
+ case '+':
246
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_SIBLING;
247
+ break;
248
+
249
+ case '~':
250
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING;
251
+ break;
252
+
253
+ case '|':
254
+ lxb_css_parser_token_next_m(parser, token);
255
+
256
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_DELIM
257
+ && lxb_css_syntax_token_delim_char(token) == '|')
258
+ {
259
+ lxb_css_syntax_token_consume(parser->tkz);
260
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_CELL;
261
+ break;
262
+ }
263
+
264
+ goto done;
265
+
266
+ default:
267
+ goto done;
268
+ }
269
+
270
+ break;
271
+
272
+ default:
273
+ goto done;
274
+ }
275
+
276
+ lxb_css_syntax_token_consume(parser->tkz);
277
+
278
+ done:
279
+
280
+ stack = lxb_css_parser_stack_push(parser, lxb_css_selectors_state_complex_end,
281
+ ctx, false);
282
+ if (stack == NULL) {
283
+ return lxb_css_parser_memory_fail(parser);
284
+ }
285
+
286
+ parser->state = lxb_css_selectors_state_compound;
287
+
288
+ return true;
289
+ }
290
+
291
+ /*
292
+ * <complex-selector>
293
+ */
294
+ bool
295
+ lxb_css_selectors_state_complex(lxb_css_parser_t *parser,
296
+ lxb_css_syntax_token_t *token, void *ctx)
297
+ {
298
+ lxb_css_parser_stack_t *stack;
299
+
300
+ stack = lxb_css_parser_stack_push(parser, lxb_css_selectors_state_complex_end,
301
+ ctx, false);
302
+ if (stack == NULL) {
303
+ return lxb_css_parser_memory_fail(parser);
304
+ }
305
+
306
+ parser->state = lxb_css_selectors_state_compound;
307
+
308
+ return false;
309
+ }
310
+
311
+ static bool
312
+ lxb_css_selectors_state_complex_end(lxb_css_parser_t *parser,
313
+ lxb_css_syntax_token_t *token, void *ctx)
314
+ {
315
+ lxb_css_selectors_t *selectors = parser->selectors;
316
+
317
+ /* <combinator> */
318
+
319
+ again:
320
+
321
+ switch (token->type) {
322
+ case LXB_CSS_SYNTAX_TOKEN_WHITESPACE:
323
+ lxb_css_syntax_token_consume(parser->tkz);
324
+
325
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT;
326
+
327
+ lxb_css_parser_token_m(parser, token);
328
+ goto again;
329
+
330
+ case LXB_CSS_SYNTAX_TOKEN__EOF:
331
+ return lxb_css_selectors_done(parser);
332
+
333
+ case LXB_CSS_SYNTAX_TOKEN_DELIM:
334
+ switch (lxb_css_syntax_token_delim_char(token)) {
335
+ case '>':
336
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_CHILD;
337
+ break;
338
+
339
+ case '+':
340
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_SIBLING;
341
+ break;
342
+
343
+ case '~':
344
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING;
345
+ break;
346
+
347
+ case '|':
348
+ lxb_css_parser_token_next_m(parser, token);
349
+
350
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_DELIM
351
+ && lxb_css_syntax_token_delim_char(token) == '|')
352
+ {
353
+ lxb_css_syntax_token_consume(parser->tkz);
354
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_CELL;
355
+ break;
356
+ }
357
+
358
+ goto done;
359
+
360
+ default:
361
+ if (selectors->combinator != LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT) {
362
+ return lxb_css_selectors_done(parser);
363
+ }
364
+
365
+ goto done;
366
+ }
367
+
368
+ break;
369
+
370
+ case LXB_CSS_SYNTAX_TOKEN_R_PARENTHESIS:
371
+ case LXB_CSS_SYNTAX_TOKEN_COMMA:
372
+ return lxb_css_selectors_done(parser);
373
+
374
+ default:
375
+ if (selectors->combinator != LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT) {
376
+ return lxb_css_selectors_done(parser);
377
+ }
378
+
379
+ goto done;
380
+ }
381
+
382
+ lxb_css_syntax_token_consume(parser->tkz);
383
+
384
+ done:
385
+
386
+ lxb_css_parser_stack_up(parser);
387
+
388
+ parser->state = lxb_css_selectors_state_compound_handler;
389
+
390
+ return true;
391
+ }
392
+
393
+ /*
394
+ * <compound-selector-list>
395
+ */
396
+ bool
397
+ lxb_css_selectors_state_compound_list(lxb_css_parser_t *parser,
398
+ lxb_css_syntax_token_t *token, void *ctx)
399
+ {
400
+ lxb_css_parser_stack_t *stack;
401
+
402
+ stack = lxb_css_parser_stack_push(parser, lxb_css_selectors_state_compound_list_end,
403
+ ctx, false);
404
+ if (stack == NULL) {
405
+ return lxb_css_parser_memory_fail(parser);
406
+ }
407
+
408
+ parser->state = lxb_css_selectors_state_compound;
409
+
410
+ return false;
411
+ }
412
+
413
+ static bool
414
+ lxb_css_selectors_state_compound_list_end(lxb_css_parser_t *parser,
415
+ lxb_css_syntax_token_t *token, void *ctx)
416
+ {
417
+ return lxb_css_selectors_state_list_end(parser, token,
418
+ lxb_css_selectors_state_compound);
419
+ }
420
+
421
+ /*
422
+ *
423
+ * <compound-selector>
424
+ */
425
+ bool
426
+ lxb_css_selectors_state_compound(lxb_css_parser_t *parser,
427
+ lxb_css_syntax_token_t *token, void *ctx)
428
+ {
429
+ lxb_css_selector_list_t *list;
430
+
431
+ lxb_css_selectors_state_list_append(parser, parser->selectors, list);
432
+
433
+ parser->state = lxb_css_selectors_state_compound_handler;
434
+
435
+ return false;
436
+ }
437
+
438
+ static bool
439
+ lxb_css_selectors_state_compound_handler(lxb_css_parser_t *parser,
440
+ lxb_css_syntax_token_t *token, void *ctx)
441
+ {
442
+ lxb_status_t status;
443
+ lxb_css_selectors_t *selectors;
444
+
445
+ again:
446
+
447
+ parser->state = lxb_css_selectors_state_compound_sub;
448
+
449
+ switch (token->type) {
450
+ case LXB_CSS_SYNTAX_TOKEN_HASH:
451
+ status = lxb_css_selectors_state_hash(parser, token);
452
+ break;
453
+
454
+ case LXB_CSS_SYNTAX_TOKEN_DELIM:
455
+ switch (lxb_css_syntax_token_delim_char(token)) {
456
+ case '.':
457
+ lxb_css_syntax_token_consume(parser->tkz);
458
+ status = lxb_css_selectors_state_class(parser, token);
459
+ break;
460
+
461
+ case '|':
462
+ case '*':
463
+ lxb_css_syntax_token_consume(parser->tkz);
464
+ status = lxb_css_selectors_state_element_ns(parser, token);
465
+ break;
466
+
467
+ default:
468
+ return lxb_css_parser_unexpected(parser);
469
+ }
470
+
471
+ break;
472
+
473
+ case LXB_CSS_SYNTAX_TOKEN_IDENT:
474
+ status = lxb_css_selectors_state_element(parser, token);
475
+ break;
476
+
477
+ case LXB_CSS_SYNTAX_TOKEN_LS_BRACKET:
478
+ lxb_css_syntax_token_consume(parser->tkz);
479
+ status = lxb_css_selectors_state_attribute(parser);
480
+ break;
481
+
482
+ case LXB_CSS_SYNTAX_TOKEN_COLON:
483
+ lxb_css_syntax_token_consume(parser->tkz);
484
+ lxb_css_parser_token_m(parser, token);
485
+
486
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_IDENT) {
487
+ status = lxb_css_selectors_state_pseudo_class(parser, token);
488
+ break;
489
+ }
490
+ else if (token->type == LXB_CSS_SYNTAX_TOKEN_COLON) {
491
+ lxb_css_syntax_token_consume(parser->tkz);
492
+ lxb_css_parser_token_m(parser, token);
493
+
494
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_IDENT) {
495
+ parser->state = lxb_css_selectors_state_compound_pseudo;
496
+ status = lxb_css_selectors_state_pseudo_element(parser, token);
497
+ break;
498
+ }
499
+ else if (token->type != LXB_CSS_SYNTAX_TOKEN_FUNCTION) {
500
+ return lxb_css_parser_unexpected(parser);
501
+ }
502
+
503
+ status = lxb_css_selectors_state_pseudo_element_function(parser, token,
504
+ lxb_css_selectors_state_compound_pseudo);
505
+ break;
506
+ }
507
+ else if (token->type != LXB_CSS_SYNTAX_TOKEN_FUNCTION) {
508
+ return lxb_css_parser_unexpected(parser);
509
+ }
510
+
511
+ status = lxb_css_selectors_state_pseudo_class_function(parser, token,
512
+ lxb_css_selectors_state_compound_sub);
513
+ break;
514
+
515
+ case LXB_CSS_SYNTAX_TOKEN_WHITESPACE:
516
+ lxb_css_syntax_token_consume(parser->tkz);
517
+ lxb_css_parser_token_m(parser, token);
518
+ goto again;
519
+
520
+ case LXB_CSS_SYNTAX_TOKEN__EOF:
521
+ selectors = parser->selectors;
522
+
523
+ if (selectors->combinator > LXB_CSS_SELECTOR_COMBINATOR_CLOSE
524
+ || selectors->list_last->first == NULL)
525
+ {
526
+ return lxb_css_parser_unexpected(parser);
527
+ }
528
+
529
+ return lxb_css_selectors_done(parser);
530
+
531
+ default:
532
+ return lxb_css_parser_unexpected(parser);
533
+ }
534
+
535
+ if (status == LXB_STATUS_ERROR_MEMORY_ALLOCATION) {
536
+ return lxb_css_parser_memory_fail(parser);
537
+ }
538
+
539
+ return true;
540
+ }
541
+
542
+ static bool
543
+ lxb_css_selectors_state_compound_sub(lxb_css_parser_t *parser,
544
+ lxb_css_syntax_token_t *token, void *ctx)
545
+ {
546
+ lxb_status_t status;
547
+
548
+ /* <subclass-selector> */
549
+
550
+ switch (token->type) {
551
+ case LXB_CSS_SYNTAX_TOKEN_HASH:
552
+ status = lxb_css_selectors_state_hash(parser, token);
553
+ break;
554
+
555
+ case LXB_CSS_SYNTAX_TOKEN_DELIM:
556
+ switch (lxb_css_syntax_token_delim_char(token)) {
557
+ case '.':
558
+ lxb_css_syntax_token_consume(parser->tkz);
559
+ status = lxb_css_selectors_state_class(parser, token);
560
+ break;
561
+
562
+ default:
563
+ return lxb_css_selectors_done(parser);
564
+ }
565
+
566
+ break;
567
+
568
+ case LXB_CSS_SYNTAX_TOKEN_LS_BRACKET:
569
+ lxb_css_syntax_token_consume(parser->tkz);
570
+ status = lxb_css_selectors_state_attribute(parser);
571
+ break;
572
+
573
+ case LXB_CSS_SYNTAX_TOKEN_COLON:
574
+ lxb_css_syntax_token_consume(parser->tkz);
575
+ lxb_css_parser_token_m(parser, token);
576
+
577
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_IDENT) {
578
+ status = lxb_css_selectors_state_pseudo_class(parser, token);
579
+ break;
580
+ }
581
+ else if (token->type == LXB_CSS_SYNTAX_TOKEN_COLON) {
582
+ lxb_css_syntax_token_consume(parser->tkz);
583
+ lxb_css_parser_token_m(parser, token);
584
+
585
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_IDENT) {
586
+ parser->state = lxb_css_selectors_state_compound_pseudo;
587
+ status = lxb_css_selectors_state_pseudo_element(parser, token);
588
+ break;
589
+ }
590
+ else if (token->type != LXB_CSS_SYNTAX_TOKEN_FUNCTION) {
591
+ return lxb_css_parser_unexpected(parser);
592
+ }
593
+
594
+ status = lxb_css_selectors_state_pseudo_element_function(parser, token,
595
+ lxb_css_selectors_state_compound_pseudo);
596
+ break;
597
+ }
598
+ else if (token->type != LXB_CSS_SYNTAX_TOKEN_FUNCTION) {
599
+ return lxb_css_parser_unexpected(parser);
600
+ }
601
+
602
+ status = lxb_css_selectors_state_pseudo_class_function(parser, token,
603
+ lxb_css_selectors_state_compound_sub);
604
+ break;
605
+
606
+ default:
607
+ return lxb_css_selectors_done(parser);
608
+ }
609
+
610
+ if (status == LXB_STATUS_ERROR_MEMORY_ALLOCATION) {
611
+ return lxb_css_parser_memory_fail(parser);
612
+ }
613
+
614
+ return true;
615
+ }
616
+
617
+ static bool
618
+ lxb_css_selectors_state_compound_pseudo(lxb_css_parser_t *parser,
619
+ lxb_css_syntax_token_t *token, void *ctx)
620
+ {
621
+ lxb_status_t status;
622
+
623
+ if (token->type != LXB_CSS_SYNTAX_TOKEN_COLON) {
624
+ return lxb_css_selectors_done(parser);
625
+ }
626
+
627
+ lxb_css_syntax_token_consume(parser->tkz);
628
+ lxb_css_parser_token_m(parser, token);
629
+
630
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_IDENT) {
631
+ status = lxb_css_selectors_state_pseudo_class(parser, token);
632
+ }
633
+ else if (token->type == LXB_CSS_SYNTAX_TOKEN_COLON) {
634
+ lxb_css_syntax_token_consume(parser->tkz);
635
+ lxb_css_parser_token_m(parser, token);
636
+
637
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_IDENT) {
638
+ status = lxb_css_selectors_state_pseudo_element(parser, token);
639
+ }
640
+ else if (token->type == LXB_CSS_SYNTAX_TOKEN_FUNCTION) {
641
+ status = lxb_css_selectors_state_pseudo_element_function(parser, token,
642
+ lxb_css_selectors_state_compound_pseudo);
643
+ }
644
+ else {
645
+ return lxb_css_parser_unexpected(parser);
646
+ }
647
+ }
648
+ else if (token->type != LXB_CSS_SYNTAX_TOKEN_FUNCTION) {
649
+ return lxb_css_parser_unexpected(parser);
650
+ }
651
+ else {
652
+ status = lxb_css_selectors_state_pseudo_class_function(parser, token,
653
+ lxb_css_selectors_state_compound_pseudo);
654
+ }
655
+
656
+ if (status == LXB_STATUS_ERROR_MEMORY_ALLOCATION) {
657
+ return lxb_css_parser_memory_fail(parser);
658
+ }
659
+
660
+ return true;
661
+ }
662
+
663
+ /*
664
+ * <simple-selector-list>
665
+ */
666
+ bool
667
+ lxb_css_selectors_state_simple_list(lxb_css_parser_t *parser,
668
+ lxb_css_syntax_token_t *token, void *ctx)
669
+ {
670
+ lxb_css_parser_stack_t *stack;
671
+
672
+ stack = lxb_css_parser_stack_push(parser, lxb_css_selectors_state_simple_list_end,
673
+ ctx, false);
674
+ if (stack == NULL) {
675
+ return lxb_css_parser_memory_fail(parser);
676
+ }
677
+
678
+ parser->state = lxb_css_selectors_state_simple;
679
+
680
+ return false;
681
+ }
682
+
683
+ static bool
684
+ lxb_css_selectors_state_simple_list_end(lxb_css_parser_t *parser,
685
+ lxb_css_syntax_token_t *token, void *ctx)
686
+ {
687
+ return lxb_css_selectors_state_list_end(parser, token,
688
+ lxb_css_selectors_state_simple);
689
+ }
690
+
691
+ /*
692
+ * <simple-selector>
693
+ */
694
+ bool
695
+ lxb_css_selectors_state_simple(lxb_css_parser_t *parser,
696
+ lxb_css_syntax_token_t *token, void *ctx)
697
+ {
698
+ lxb_css_selector_list_t *list;
699
+
700
+ lxb_css_selectors_state_list_append(parser, parser->selectors, list);
701
+
702
+ parser->state = lxb_css_selectors_state_simple_handler;
703
+
704
+ return false;
705
+ }
706
+
707
+ static bool
708
+ lxb_css_selectors_state_simple_handler(lxb_css_parser_t *parser,
709
+ lxb_css_syntax_token_t *token, void *ctx)
710
+ {
711
+ lxb_status_t status;
712
+
713
+ again:
714
+
715
+ parser->state = lxb_css_selectors_state_compound_sub;
716
+
717
+ switch (token->type) {
718
+ case LXB_CSS_SYNTAX_TOKEN_HASH:
719
+ status = lxb_css_selectors_state_hash(parser, token);
720
+ break;
721
+
722
+ case LXB_CSS_SYNTAX_TOKEN_DELIM:
723
+ switch (lxb_css_syntax_token_delim_char(token)) {
724
+ case '.':
725
+ lxb_css_syntax_token_consume(parser->tkz);
726
+ status = lxb_css_selectors_state_class(parser, token);
727
+ break;
728
+
729
+ case '|':
730
+ case '*':
731
+ lxb_css_syntax_token_consume(parser->tkz);
732
+ status = lxb_css_selectors_state_element_ns(parser, token);
733
+ break;
734
+
735
+ default:
736
+ return lxb_css_parser_unexpected(parser);
737
+ }
738
+
739
+ break;
740
+
741
+ case LXB_CSS_SYNTAX_TOKEN_IDENT:
742
+ status = lxb_css_selectors_state_element(parser, token);
743
+ break;
744
+
745
+ case LXB_CSS_SYNTAX_TOKEN_LS_BRACKET:
746
+ lxb_css_syntax_token_consume(parser->tkz);
747
+ status = lxb_css_selectors_state_attribute(parser);
748
+ break;
749
+
750
+ case LXB_CSS_SYNTAX_TOKEN_COLON:
751
+ lxb_css_syntax_token_consume(parser->tkz);
752
+ lxb_css_parser_token_m(parser, token);
753
+
754
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_IDENT) {
755
+ status = lxb_css_selectors_state_pseudo_class(parser, token);
756
+ break;
757
+ }
758
+ else if (token->type != LXB_CSS_SYNTAX_TOKEN_FUNCTION) {
759
+ return lxb_css_parser_unexpected(parser);
760
+ }
761
+
762
+ status = lxb_css_selectors_state_pseudo_class_function(parser, token,
763
+ NULL);
764
+ break;
765
+
766
+ case LXB_CSS_SYNTAX_TOKEN_WHITESPACE:
767
+ lxb_css_syntax_token_consume(parser->tkz);
768
+ lxb_css_parser_token_m(parser, token);
769
+ goto again;
770
+
771
+ default:
772
+ return lxb_css_parser_unexpected(parser);
773
+ }
774
+
775
+ if (status == LXB_STATUS_ERROR_MEMORY_ALLOCATION) {
776
+ return lxb_css_parser_memory_fail(parser);
777
+ }
778
+
779
+ return lxb_css_selectors_done(parser);
780
+ }
781
+
782
+ static lxb_status_t
783
+ lxb_css_selectors_state_hash(lxb_css_parser_t *parser,
784
+ lxb_css_syntax_token_t *token)
785
+ {
786
+ lxb_css_selector_t *selector;
787
+ lxb_css_selectors_t *selectors;
788
+
789
+ selectors = parser->selectors;
790
+
791
+ lxb_css_syntax_token_consume(parser->tkz);
792
+ lxb_css_selectors_state_append(parser, selectors, selector);
793
+
794
+ selector->type = LXB_CSS_SELECTOR_TYPE_ID;
795
+
796
+ return lxb_css_syntax_token_string_dup(lxb_css_syntax_token_string(token),
797
+ &selector->name, selectors->memory->mraw);
798
+ }
799
+
800
+ static lxb_status_t
801
+ lxb_css_selectors_state_class(lxb_css_parser_t *parser,
802
+ lxb_css_syntax_token_t *token)
803
+ {
804
+ lxb_css_selector_t *selector;
805
+ lxb_css_selectors_t *selectors;
806
+
807
+ lxb_css_parser_token_status_m(parser, token);
808
+
809
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_IDENT) {
810
+ selectors = parser->selectors;
811
+
812
+ lxb_css_syntax_token_consume(parser->tkz);
813
+ lxb_css_selectors_state_append(parser, selectors, selector);
814
+
815
+ selector->type = LXB_CSS_SELECTOR_TYPE_CLASS;
816
+
817
+ return lxb_css_syntax_token_string_dup(lxb_css_syntax_token_string(token),
818
+ &selector->name, selectors->memory->mraw);
819
+ }
820
+
821
+ return lxb_css_parser_unexpected_status(parser);
822
+ }
823
+
824
+ static lxb_status_t
825
+ lxb_css_selectors_state_element_ns(lxb_css_parser_t *parser,
826
+ lxb_css_syntax_token_t *token)
827
+ {
828
+ lxb_css_selector_t *selector;
829
+ lxb_css_selectors_t *selectors;
830
+
831
+ selectors = parser->selectors;
832
+
833
+ lxb_css_selectors_state_append(parser, selectors, selector);
834
+
835
+ selector->type = LXB_CSS_SELECTOR_TYPE_ANY;
836
+
837
+ selector->name.data = lexbor_mraw_alloc(selectors->memory->mraw, 2);
838
+ if (selector->name.data == NULL) {
839
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
840
+ }
841
+
842
+ selector->name.data[0] = '*';
843
+ selector->name.data[1] = '\0';
844
+ selector->name.length = 1;
845
+
846
+ if (lxb_css_syntax_token_delim_char(token) == '*') {
847
+ lxb_css_syntax_token_consume(parser->tkz);
848
+ return lxb_css_selectors_state_ns(parser, selector);
849
+ }
850
+
851
+ return lxb_css_selectors_state_ns_ident(parser, selector);
852
+ }
853
+
854
+ static lxb_status_t
855
+ lxb_css_selectors_state_element(lxb_css_parser_t *parser,
856
+ lxb_css_syntax_token_t *token)
857
+ {
858
+ lxb_status_t status;
859
+ lxb_css_selector_t *selector;
860
+ lxb_css_selectors_t *selectors;
861
+
862
+ selectors = parser->selectors;
863
+
864
+ lxb_css_selectors_state_append(parser, selectors, selector);
865
+
866
+ selector->type = LXB_CSS_SELECTOR_TYPE_ELEMENT;
867
+
868
+ lxb_css_selectors_state_string_dup_m(selectors, &selector->name);
869
+
870
+ lxb_css_syntax_token_consume(parser->tkz);
871
+
872
+ return lxb_css_selectors_state_ns(parser, selector);
873
+ }
874
+
875
+
876
+ static lxb_status_t
877
+ lxb_css_selectors_state_attribute(lxb_css_parser_t *parser)
878
+ {
879
+ lxb_char_t modifier;
880
+ lxb_status_t status;
881
+ lxb_css_selector_t *selector;
882
+ lxb_css_selectors_t *selectors;
883
+ lxb_css_syntax_token_t *token;
884
+ lxb_css_syntax_tokenizer_t *tkz;
885
+ lxb_css_selector_attribute_t *attribute;
886
+
887
+ selectors = parser->selectors;
888
+
889
+ tkz = parser->tkz;
890
+
891
+ lxb_css_selectors_state_append(parser, selectors, selector);
892
+ lxb_css_parser_token_status_wo_ws_m(parser, token);
893
+
894
+ switch (token->type) {
895
+ case LXB_CSS_SYNTAX_TOKEN_DELIM:
896
+ if (lxb_css_syntax_token_delim_char(token) != '|') {
897
+ goto failed;
898
+ }
899
+
900
+ lxb_css_syntax_token_consume(tkz);
901
+ lxb_css_parser_token_status_m(parser, token);
902
+
903
+ if (token->type != LXB_CSS_SYNTAX_TOKEN_IDENT) {
904
+ goto failed;
905
+ }
906
+
907
+ selector->type = LXB_CSS_SELECTOR_TYPE_ATTRIBUTE;
908
+
909
+ selector->ns.data = lexbor_mraw_alloc(selectors->memory->mraw, 2);
910
+ if (selector->ns.data == NULL) {
911
+ selectors->bracket = true;
912
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
913
+ }
914
+
915
+ selector->ns.data[0] = '*';
916
+ selector->ns.data[1] = '\0';
917
+ selector->ns.length = 1;
918
+
919
+ lxb_css_selectors_state_string_dup_m(parser->selectors,
920
+ &selector->name);
921
+
922
+ lxb_css_syntax_token_consume(tkz);
923
+ lxb_css_parser_token_status_wo_ws_m(parser, token);
924
+ break;
925
+
926
+ case LXB_CSS_SYNTAX_TOKEN_IDENT:
927
+ selector->type = LXB_CSS_SELECTOR_TYPE_ATTRIBUTE;
928
+
929
+ lxb_css_selectors_state_string_dup_m(selectors, &selector->name);
930
+
931
+ lxb_css_syntax_token_consume(tkz);
932
+ lxb_css_parser_token_status_m(parser, token);
933
+
934
+ if (token->type != LXB_CSS_SYNTAX_TOKEN_DELIM
935
+ || lxb_css_syntax_token_delim_char(token) != '|')
936
+ {
937
+ lxb_css_syntax_token_consume(tkz);
938
+
939
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_WHITESPACE) {
940
+ lxb_css_parser_token_status_m(parser, token);
941
+ }
942
+
943
+ break;
944
+ }
945
+
946
+ lxb_css_syntax_token_consume(tkz);
947
+ lxb_css_parser_token_status_m(parser, token);
948
+
949
+ if (token->type != LXB_CSS_SYNTAX_TOKEN_IDENT) {
950
+ goto failed;
951
+ }
952
+
953
+ selector->ns = selector->name;
954
+ lexbor_str_clean_all(&selector->name);
955
+
956
+ lxb_css_selectors_state_string_dup_m(selectors, &selector->name);
957
+
958
+ lxb_css_syntax_token_consume(tkz);
959
+ lxb_css_parser_token_status_wo_ws_m(parser, token);
960
+ break;
961
+
962
+ default:
963
+ goto failed;
964
+ }
965
+
966
+ attribute = &selector->u.attribute;
967
+
968
+ switch (token->type) {
969
+ case LXB_CSS_SYNTAX_TOKEN_RS_BRACKET:
970
+ lxb_css_syntax_token_consume(tkz);
971
+ return LXB_STATUS_OK;
972
+
973
+ case LXB_CSS_SYNTAX_TOKEN_DELIM:
974
+ switch (lxb_css_syntax_token_delim_char(token)) {
975
+ case '~':
976
+ attribute->match = LXB_CSS_SELECTOR_MATCH_INCLUDE;
977
+ break;
978
+
979
+ case '|':
980
+ attribute->match = LXB_CSS_SELECTOR_MATCH_DASH;
981
+ break;
982
+
983
+ case '^':
984
+ attribute->match = LXB_CSS_SELECTOR_MATCH_PREFIX;
985
+ break;
986
+
987
+ case '$':
988
+ attribute->match = LXB_CSS_SELECTOR_MATCH_SUFFIX;
989
+ break;
990
+
991
+ case '*':
992
+ attribute->match = LXB_CSS_SELECTOR_MATCH_SUBSTRING;
993
+ break;
994
+
995
+ case '=':
996
+ attribute->match = LXB_CSS_SELECTOR_MATCH_EQUAL;
997
+
998
+ lxb_css_syntax_token_consume(tkz);
999
+ lxb_css_parser_token_status_wo_ws_m(parser, token);
1000
+ goto string_or_ident;
1001
+
1002
+ default:
1003
+ goto failed;
1004
+ }
1005
+
1006
+ lxb_css_syntax_token_consume(tkz);
1007
+ lxb_css_parser_token_status_m(parser, token);
1008
+
1009
+ if (token->type != LXB_CSS_SYNTAX_TOKEN_DELIM
1010
+ || lxb_css_syntax_token_delim_char(token) != '=')
1011
+ {
1012
+ goto failed;
1013
+ }
1014
+
1015
+ lxb_css_syntax_token_consume(tkz);
1016
+ lxb_css_parser_token_status_wo_ws_m(parser, token);
1017
+ break;
1018
+
1019
+ default:
1020
+ goto failed;
1021
+ }
1022
+
1023
+ string_or_ident:
1024
+
1025
+ if (token->type != LXB_CSS_SYNTAX_TOKEN_STRING
1026
+ && token->type != LXB_CSS_SYNTAX_TOKEN_IDENT)
1027
+ {
1028
+ goto failed;
1029
+ }
1030
+
1031
+ lxb_css_selectors_state_string_dup_m(selectors, &attribute->value);
1032
+
1033
+ lxb_css_syntax_token_consume(tkz);
1034
+ lxb_css_parser_token_status_wo_ws_m(parser, token);
1035
+
1036
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_RS_BRACKET) {
1037
+ lxb_css_syntax_token_consume(tkz);
1038
+ return LXB_STATUS_OK;
1039
+ }
1040
+
1041
+ if (token->type != LXB_CSS_SYNTAX_TOKEN_IDENT) {
1042
+ goto failed;
1043
+ }
1044
+
1045
+ modifier = *lxb_css_syntax_token_string(token)->data;
1046
+
1047
+ switch (modifier) {
1048
+ case 'i':
1049
+ attribute->modifier = LXB_CSS_SELECTOR_MODIFIER_I;
1050
+ break;
1051
+
1052
+ case 's':
1053
+ attribute->modifier = LXB_CSS_SELECTOR_MODIFIER_S;
1054
+ break;
1055
+
1056
+ default:
1057
+ goto failed;
1058
+ }
1059
+
1060
+ lxb_css_syntax_token_consume(tkz);
1061
+ lxb_css_parser_token_status_wo_ws_m(parser, token);
1062
+
1063
+ if (token->type != LXB_CSS_SYNTAX_TOKEN_RS_BRACKET) {
1064
+ goto failed;
1065
+ }
1066
+
1067
+ lxb_css_syntax_token_consume(tkz);
1068
+
1069
+ return LXB_STATUS_OK;
1070
+
1071
+ failed:
1072
+
1073
+ selectors->bracket = true;
1074
+
1075
+ return lxb_css_parser_unexpected_status(parser);
1076
+ }
1077
+
1078
+ static lxb_status_t
1079
+ lxb_css_selectors_state_ns(lxb_css_parser_t *parser,
1080
+ lxb_css_selector_t *selector)
1081
+ {
1082
+ lxb_css_syntax_token_t *token;
1083
+
1084
+ lxb_css_parser_token_status_m(parser, token);
1085
+
1086
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_DELIM
1087
+ && lxb_css_syntax_token_delim_char(token) == '|')
1088
+ {
1089
+ lxb_css_syntax_token_consume(parser->tkz);
1090
+ return lxb_css_selectors_state_ns_ident(parser, selector);
1091
+ }
1092
+
1093
+ return LXB_STATUS_OK;
1094
+ }
1095
+
1096
+ static lxb_status_t
1097
+ lxb_css_selectors_state_ns_ident(lxb_css_parser_t *parser,
1098
+ lxb_css_selector_t *selector)
1099
+ {
1100
+ lxb_css_syntax_token_t *token;
1101
+
1102
+ lxb_css_parser_token_status_m(parser, token);
1103
+
1104
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_IDENT) {
1105
+ lxb_css_syntax_token_consume(parser->tkz);
1106
+
1107
+ selector->type = LXB_CSS_SELECTOR_TYPE_ELEMENT;
1108
+
1109
+ selector->ns = selector->name;
1110
+ lexbor_str_clean_all(&selector->name);
1111
+
1112
+ return lxb_css_syntax_token_string_dup(lxb_css_syntax_token_string(token),
1113
+ &selector->name, parser->selectors->memory->mraw);
1114
+ }
1115
+ else if (token->type == LXB_CSS_SYNTAX_TOKEN_DELIM
1116
+ && lxb_css_syntax_token_delim_char(token) == '*')
1117
+ {
1118
+ lxb_css_syntax_token_consume(parser->tkz);
1119
+
1120
+ selector->type = LXB_CSS_SELECTOR_TYPE_ANY;
1121
+
1122
+ selector->ns = selector->name;
1123
+
1124
+ selector->name.data = lexbor_mraw_alloc(parser->selectors->memory->mraw,
1125
+ 2);
1126
+ if (selector->name.data == NULL) {
1127
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
1128
+ }
1129
+
1130
+ selector->name.data[0] = '*';
1131
+ selector->name.data[1] = '\0';
1132
+ selector->name.length = 1;
1133
+
1134
+ return LXB_STATUS_OK;
1135
+ }
1136
+
1137
+ return lxb_css_parser_unexpected_status(parser);
1138
+ }
1139
+
1140
+ static lxb_status_t
1141
+ lxb_css_selectors_state_pseudo_class(lxb_css_parser_t *parser,
1142
+ lxb_css_syntax_token_t *token)
1143
+ {
1144
+ lxb_status_t status;
1145
+ lxb_css_log_message_t *msg;
1146
+ lxb_css_selector_t *selector;
1147
+ lxb_css_selectors_t *selectors;
1148
+ const lxb_css_selectors_pseudo_data_t *pseudo;
1149
+
1150
+ selectors = parser->selectors;
1151
+
1152
+ lxb_css_selectors_state_append(parser, selectors, selector);
1153
+ selector->type = LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS;
1154
+
1155
+ lxb_css_selectors_state_string_dup_m(selectors, &selector->name);
1156
+
1157
+ pseudo = lxb_css_selector_pseudo_class_by_name(selector->name.data,
1158
+ selector->name.length);
1159
+ if (pseudo == NULL) {
1160
+ return lxb_css_parser_unexpected_status(parser);
1161
+ }
1162
+
1163
+ switch (pseudo->id) {
1164
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_CURRENT:
1165
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_DEFAULT:
1166
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FOCUS_VISIBLE:
1167
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FOCUS_WITHIN:
1168
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FULLSCREEN:
1169
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUTURE:
1170
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_IN_RANGE:
1171
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_INDETERMINATE:
1172
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_INVALID:
1173
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_LOCAL_LINK:
1174
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_OUT_OF_RANGE:
1175
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_PAST:
1176
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_SCOPE:
1177
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_TARGET:
1178
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_TARGET_WITHIN:
1179
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_USER_INVALID:
1180
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_VALID:
1181
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_VISITED:
1182
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_WARNING:
1183
+ msg = lxb_css_log_not_supported(parser->log,
1184
+ lxb_css_selectors_module_name,
1185
+ (const char *) selector->name.data);
1186
+ if (msg == NULL) {
1187
+ return lxb_css_parser_memory_fail(parser);
1188
+ }
1189
+
1190
+ return lxb_css_parser_unexpected_status(parser);
1191
+
1192
+ default:
1193
+ break;
1194
+ }
1195
+
1196
+ selector->u.pseudo.type = pseudo->id;
1197
+ selector->u.pseudo.data = NULL;
1198
+
1199
+ lxb_css_syntax_token_consume(parser->tkz);
1200
+
1201
+ return LXB_STATUS_OK;
1202
+ }
1203
+
1204
+ static lxb_status_t
1205
+ lxb_css_selectors_state_pseudo_class_function(lxb_css_parser_t *parser,
1206
+ lxb_css_syntax_token_t *token,
1207
+ lxb_css_parser_state_f success)
1208
+ {
1209
+ lxb_status_t status;
1210
+ lxb_css_selector_t *selector;
1211
+ lxb_css_selectors_t *selectors;
1212
+ lxb_css_log_message_t *msg;
1213
+ lxb_css_selector_list_t *list;
1214
+ lxb_css_parser_stack_t *entry;
1215
+ const lxb_css_selectors_pseudo_data_func_t *func;
1216
+
1217
+ selectors = parser->selectors;
1218
+
1219
+ lxb_css_selectors_state_append(parser, selectors, selector);
1220
+ selector->type = LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS_FUNCTION;
1221
+
1222
+ lxb_css_selectors_state_string_dup_m(selectors, &selector->name);
1223
+
1224
+ func = lxb_css_selector_pseudo_class_function_by_name(selector->name.data,
1225
+ selector->name.length);
1226
+ if (func == NULL) {
1227
+ return lxb_css_parser_unexpected_status(parser);
1228
+ }
1229
+
1230
+ switch (func->id) {
1231
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_DIR:
1232
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_LANG:
1233
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_COL:
1234
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_COL:
1235
+ msg = lxb_css_log_not_supported(parser->log,
1236
+ lxb_css_selectors_module_name,
1237
+ (const char *) selector->name.data);
1238
+ if (msg == NULL) {
1239
+ return lxb_css_parser_memory_fail(parser);
1240
+ }
1241
+
1242
+ return lxb_css_parser_unexpected_status(parser);
1243
+
1244
+ default:
1245
+ break;
1246
+ }
1247
+
1248
+ parser->state = func->state;
1249
+
1250
+ selector->u.pseudo.type = func->id;
1251
+ selector->u.pseudo.data = NULL;
1252
+
1253
+ list = selectors->list_last;
1254
+
1255
+ if (success != NULL) {
1256
+ entry = lxb_css_parser_stack_push(parser, success, list, false);
1257
+ if (entry == NULL) {
1258
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
1259
+ }
1260
+ }
1261
+
1262
+ entry = lxb_css_parser_stack_push(parser, func->success, list, true);
1263
+ if (entry == NULL) {
1264
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
1265
+ }
1266
+
1267
+ selectors->combinator = func->combinator;
1268
+ selectors->comb_default = func->combinator;
1269
+ selectors->parent = selector;
1270
+
1271
+ lxb_css_syntax_token_consume(parser->tkz);
1272
+
1273
+ return LXB_STATUS_OK;
1274
+ }
1275
+
1276
+ static lxb_status_t
1277
+ lxb_css_selectors_state_pseudo_element(lxb_css_parser_t *parser,
1278
+ lxb_css_syntax_token_t *token)
1279
+ {
1280
+ lxb_status_t status;
1281
+ lxb_css_log_message_t *msg;
1282
+ lxb_css_selector_t *selector;
1283
+ lxb_css_selectors_t *selectors;
1284
+ const lxb_css_selectors_pseudo_data_t *pseudo;
1285
+
1286
+ selectors = parser->selectors;
1287
+
1288
+ lxb_css_selectors_state_append(parser, selectors, selector);
1289
+ selector->type = LXB_CSS_SELECTOR_TYPE_PSEUDO_ELEMENT;
1290
+
1291
+ lxb_css_selectors_state_string_dup_m(selectors, &selector->name);
1292
+
1293
+ pseudo = lxb_css_selector_pseudo_element_by_name(selector->name.data,
1294
+ selector->name.length);
1295
+ if (pseudo == NULL) {
1296
+ return lxb_css_parser_unexpected_status(parser);
1297
+ }
1298
+
1299
+ switch (pseudo->id) {
1300
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_AFTER:
1301
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_BACKDROP:
1302
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_BEFORE:
1303
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_FIRST_LETTER:
1304
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_FIRST_LINE:
1305
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_GRAMMAR_ERROR:
1306
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_INACTIVE_SELECTION:
1307
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_MARKER:
1308
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_PLACEHOLDER:
1309
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_SELECTION:
1310
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_SPELLING_ERROR:
1311
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_TARGET_TEXT:
1312
+ msg = lxb_css_log_not_supported(parser->log,
1313
+ lxb_css_selectors_module_name,
1314
+ (const char *) selector->name.data);
1315
+ if (msg == NULL) {
1316
+ return lxb_css_parser_memory_fail(parser);
1317
+ }
1318
+
1319
+ return lxb_css_parser_unexpected_status(parser);
1320
+
1321
+ default:
1322
+ break;
1323
+ }
1324
+
1325
+ selector->u.pseudo.type = pseudo->id;
1326
+ selector->u.pseudo.data = NULL;
1327
+
1328
+ lxb_css_syntax_token_consume(parser->tkz);
1329
+
1330
+ return LXB_STATUS_OK;
1331
+ }
1332
+
1333
+ static lxb_status_t
1334
+ lxb_css_selectors_state_pseudo_element_function(lxb_css_parser_t *parser,
1335
+ lxb_css_syntax_token_t *token,
1336
+ lxb_css_parser_state_f success)
1337
+ {
1338
+ lxb_status_t status;
1339
+ lxb_css_selector_t *selector;
1340
+ lxb_css_selectors_t *selectors;
1341
+ lxb_css_selector_list_t *list;
1342
+ lxb_css_parser_stack_t *entry;
1343
+ const lxb_css_selectors_pseudo_data_func_t *func;
1344
+
1345
+ selectors = parser->selectors;
1346
+
1347
+ lxb_css_selectors_state_append(parser, selectors, selector);
1348
+ selector->type = LXB_CSS_SELECTOR_TYPE_PSEUDO_ELEMENT_FUNCTION;
1349
+
1350
+ lxb_css_selectors_state_string_dup_m(selectors, &selector->name);
1351
+
1352
+ func = lxb_css_selector_pseudo_element_function_by_name(selector->name.data,
1353
+ selector->name.length);
1354
+ if (func == NULL) {
1355
+ return lxb_css_parser_unexpected_status(parser);
1356
+ }
1357
+
1358
+ parser->state = func->state;
1359
+
1360
+ selector->u.pseudo.type = func->id;
1361
+ selector->u.pseudo.data = NULL;
1362
+
1363
+ list = selectors->list_last;
1364
+
1365
+ entry = lxb_css_parser_stack_push(parser, success, list, false);
1366
+ if (entry == NULL) {
1367
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
1368
+ }
1369
+
1370
+ entry = lxb_css_parser_stack_push(parser, func->success, list, true);
1371
+ if (entry == NULL) {
1372
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
1373
+ }
1374
+
1375
+ selectors->combinator = func->combinator;
1376
+ selectors->comb_default = func->combinator;
1377
+ selectors->parent = selector;
1378
+
1379
+ lxb_css_syntax_token_consume(parser->tkz);
1380
+
1381
+ return LXB_STATUS_OK;
1382
+ }
1383
+
1384
+ lxb_inline void
1385
+ lxb_css_selectors_state_restore_combinator(lxb_css_selectors_t *selectors)
1386
+ {
1387
+ lxb_css_selector_t *parent;
1388
+ lxb_css_selector_combinator_t comb_default;
1389
+ const lxb_css_selectors_pseudo_data_func_t *data_func;
1390
+
1391
+ comb_default = LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT;
1392
+
1393
+ if (selectors->parent != NULL) {
1394
+ parent = selectors->parent;
1395
+
1396
+ if (parent->type == LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS_FUNCTION) {
1397
+ data_func = lxb_css_selector_pseudo_class_function_by_id(parent->u.pseudo.type);
1398
+ }
1399
+ else {
1400
+ data_func = lxb_css_selector_pseudo_element_function_by_id(parent->u.pseudo.type);
1401
+ }
1402
+
1403
+ comb_default = data_func->combinator;
1404
+ }
1405
+
1406
+ selectors->combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE;
1407
+ selectors->comb_default = comb_default;
1408
+ }
1409
+
1410
+ bool
1411
+ lxb_css_selectors_state_success(lxb_css_parser_t *parser,
1412
+ lxb_css_syntax_token_t *token, void *ctx)
1413
+ {
1414
+ bool cy;
1415
+ lxb_css_selector_t *selector;
1416
+ lxb_css_selectors_t *selectors = parser->selectors;
1417
+
1418
+ if (parser->status == LXB_STATUS_OK
1419
+ && token->type == LXB_CSS_SYNTAX_TOKEN_R_PARENTHESIS)
1420
+ {
1421
+ lxb_css_syntax_token_consume(parser->tkz);
1422
+ lxb_css_selectors_state_restore_parent(selectors, ctx);
1423
+ return lxb_css_selectors_done(parser);
1424
+ }
1425
+
1426
+ /* Empty function. */
1427
+ if ((selectors->list == NULL || selectors->list->first == NULL)
1428
+ && token->type == LXB_CSS_SYNTAX_TOKEN_R_PARENTHESIS
1429
+ && selectors->deep == 0)
1430
+ {
1431
+ lxb_css_selector_list_destroy_chain(selectors->list);
1432
+ selectors->list = NULL;
1433
+
1434
+ lxb_css_selectors_state_restore_parent(selectors, ctx);
1435
+
1436
+ selector = selectors->list_last->last;
1437
+
1438
+ cy = selector->type == LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS_FUNCTION;
1439
+ cy = lxb_css_selector_pseudo_function_can_empty(selector->u.pseudo.type,
1440
+ cy);
1441
+ if (!cy) {
1442
+ (void) lxb_css_log_format(parser->log, LXB_CSS_LOG_ERROR,
1443
+ "%s. Pseudo function can't be empty: %S()",
1444
+ lxb_css_selectors_module_name,
1445
+ &selector->name);
1446
+ selectors->deep++;
1447
+
1448
+ lxb_css_parser_stack_to_stop(parser);
1449
+ return false;
1450
+ }
1451
+
1452
+ parser->status = LXB_STATUS_OK;
1453
+
1454
+ lxb_css_syntax_token_consume(parser->tkz);
1455
+ return lxb_css_selectors_done(parser);
1456
+ }
1457
+
1458
+ /* Set error. */
1459
+ selectors->deep++;
1460
+
1461
+ parser->status = LXB_STATUS_ERROR_UNEXPECTED_DATA;
1462
+
1463
+ lxb_css_selector_list_destroy_chain(selectors->list);
1464
+ selectors->list = NULL;
1465
+
1466
+ lxb_css_selectors_state_restore_parent(selectors, ctx);
1467
+ lxb_css_parser_stack_to_stop(parser);
1468
+
1469
+ return false;
1470
+ }
1471
+
1472
+ bool
1473
+ lxb_css_selectors_state_forgiving(lxb_css_parser_t *parser,
1474
+ lxb_css_syntax_token_t *token, void *ctx)
1475
+ {
1476
+ return lxb_css_selectors_state_forgiving_cb(parser, token, ctx,
1477
+ lxb_css_selectors_state_complex_list);
1478
+ }
1479
+
1480
+ bool
1481
+ lxb_css_selectors_state_forgiving_relative(lxb_css_parser_t *parser,
1482
+ lxb_css_syntax_token_t *token, void *ctx)
1483
+ {
1484
+ return lxb_css_selectors_state_forgiving_cb(parser, token, ctx,
1485
+ lxb_css_selectors_state_relative_list);
1486
+ }
1487
+
1488
+ static bool
1489
+ lxb_css_selectors_state_forgiving_cb(lxb_css_parser_t *parser,
1490
+ lxb_css_syntax_token_t *token, void *ctx,
1491
+ lxb_css_parser_state_f state)
1492
+ {
1493
+ bool cy;
1494
+ lxb_css_selector_t *selector;
1495
+ lxb_css_selector_list_t *list;
1496
+ const lxb_css_selectors_pseudo_data_func_t *func;
1497
+ lxb_css_selectors_t *selectors = parser->selectors;
1498
+
1499
+ if (parser->status == LXB_STATUS_OK
1500
+ && token->type == LXB_CSS_SYNTAX_TOKEN_R_PARENTHESIS)
1501
+ {
1502
+ lxb_css_syntax_token_consume(parser->tkz);
1503
+ lxb_css_selectors_state_restore_parent(selectors, ctx);
1504
+ return lxb_css_selectors_done(parser);
1505
+ }
1506
+
1507
+ /* Emply list. */
1508
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_COMMA && selectors->deep == 0) {
1509
+ selectors->combinator = selectors->comb_default;
1510
+
1511
+ lxb_css_syntax_token_consume(parser->tkz);
1512
+
1513
+ /* Destroying a bad Selector List. */
1514
+ list = selectors->list_last;
1515
+
1516
+ lxb_css_selector_list_selectors_remove(selectors, list);
1517
+ lxb_css_selector_list_destroy(list);
1518
+
1519
+ /* Recovering the parser from the error. */
1520
+ lxb_css_parser_stack_up(parser);
1521
+
1522
+ parser->status = LXB_STATUS_OK;
1523
+ parser->state = state;
1524
+
1525
+ (void) lxb_css_log_format(parser->log, LXB_CSS_LOG_ERROR,
1526
+ "%s. Empty Selector List in pseudo function",
1527
+ lxb_css_selectors_module_name);
1528
+ return true;
1529
+ }
1530
+
1531
+ /* End Of File. */
1532
+ if (token->type == LXB_CSS_SYNTAX_TOKEN__EOF) {
1533
+ selector = selectors->list_last->last;
1534
+
1535
+ if (selector == NULL) {
1536
+ (void) lxb_css_log_format(parser->log, LXB_CSS_LOG_ERROR,
1537
+ "%s. End Of File in pseudo function",
1538
+ lxb_css_selectors_module_name);
1539
+ }
1540
+ else {
1541
+ func = NULL;
1542
+
1543
+ if (selector->type == LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS_FUNCTION) {
1544
+ func =lxb_css_selector_pseudo_class_function_by_id(selector->u.pseudo.type);
1545
+ }
1546
+ else if (selector->type == LXB_CSS_SELECTOR_TYPE_PSEUDO_ELEMENT_FUNCTION) {
1547
+ func =lxb_css_selector_pseudo_element_function_by_id(selector->u.pseudo.type);
1548
+ }
1549
+
1550
+ if (func != NULL
1551
+ && func->success != lxb_css_selectors_state_forgiving
1552
+ && func->success != lxb_css_selectors_state_forgiving_relative)
1553
+ {
1554
+ (void) lxb_css_log_format(parser->log, LXB_CSS_LOG_ERROR,
1555
+ "%s. End Of File in pseudo function",
1556
+ lxb_css_selectors_module_name);
1557
+ }
1558
+ }
1559
+
1560
+ if (parser->status == LXB_STATUS_OK) {
1561
+ lxb_css_selectors_state_restore_parent(selectors, ctx);
1562
+ lxb_css_parser_stack_to_stop(parser);
1563
+
1564
+ return false;
1565
+ }
1566
+
1567
+ goto failed;
1568
+ }
1569
+
1570
+ if (lxb_css_syntax_token_error(parser, token, "Selectors") == NULL) {
1571
+ return lxb_css_parser_memory_fail(parser);
1572
+ }
1573
+
1574
+ /* Empty function. */
1575
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_R_PARENTHESIS) {
1576
+ selectors->deep++;
1577
+ goto failed;
1578
+ }
1579
+
1580
+ /* Destroying a bad Selector List. */
1581
+ list = selectors->list_last;
1582
+
1583
+ lxb_css_selector_list_selectors_remove(selectors, list);
1584
+ lxb_css_selector_list_destroy(list);
1585
+
1586
+ /* Close all open blocks. */
1587
+ token = lxb_css_selectors_close_parenthesis(parser, token);
1588
+ if (token == NULL) {
1589
+ return lxb_css_parser_memory_fail(parser);
1590
+ }
1591
+
1592
+ /* Find ',' or end of function ')' */
1593
+ token = lxb_css_parser_find_close(parser, token, NULL,
1594
+ LXB_CSS_SYNTAX_TOKEN_R_PARENTHESIS,
1595
+ LXB_CSS_SYNTAX_TOKEN_COMMA);
1596
+ if (token == NULL) {
1597
+ return lxb_css_parser_memory_fail(parser);
1598
+ }
1599
+
1600
+ /*
1601
+ * This is only necessary in order to print the correct message to the log.
1602
+ * Example: :has(1%, div)
1603
+ */
1604
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_COMMA) {
1605
+ lxb_css_selectors_state_restore_combinator(selectors);
1606
+
1607
+ selectors->combinator = selectors->comb_default;
1608
+
1609
+ lxb_css_syntax_token_consume(parser->tkz);
1610
+
1611
+ /* Recovering the parser from the error. */
1612
+ lxb_css_parser_stack_up(parser);
1613
+
1614
+ parser->status = LXB_STATUS_OK;
1615
+ parser->state = state;
1616
+
1617
+ return true;
1618
+ }
1619
+
1620
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_R_PARENTHESIS) {
1621
+ lxb_css_syntax_token_consume(parser->tkz);
1622
+ goto failed_done;
1623
+ }
1624
+
1625
+ /* Recovering the parser from the error. */
1626
+ lxb_css_parser_stack_up(parser);
1627
+
1628
+ parser->status = LXB_STATUS_OK;
1629
+ parser->state = state;
1630
+
1631
+ return false;
1632
+
1633
+ failed:
1634
+
1635
+ /* Destroying a bad Selector List. */
1636
+ list = selectors->list_last;
1637
+
1638
+ lxb_css_selector_list_selectors_remove(selectors, list);
1639
+ lxb_css_selector_list_destroy(list);
1640
+
1641
+ /* Close all open blocks. */
1642
+ token = lxb_css_selectors_close_parenthesis(parser, token);
1643
+ if (token == NULL) {
1644
+ return lxb_css_parser_memory_fail(parser);
1645
+ }
1646
+
1647
+ failed_done:
1648
+
1649
+ cy = selectors->list == NULL;
1650
+
1651
+ lxb_css_selectors_state_restore_parent(selectors, ctx);
1652
+
1653
+ if (cy) {
1654
+ selector = selectors->list_last->last;
1655
+
1656
+ cy = selector->type == LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS_FUNCTION;
1657
+ cy = lxb_css_selector_pseudo_function_can_empty(selector->u.pseudo.type,
1658
+ cy);
1659
+ if (!cy) {
1660
+ (void) lxb_css_log_format(parser->log, LXB_CSS_LOG_ERROR,
1661
+ "%s. Pseudo function can't be empty: %S()",
1662
+ lxb_css_selectors_module_name,
1663
+ &selector->name);
1664
+
1665
+ lxb_css_parser_stack_to_stop(parser);
1666
+ return true;
1667
+ }
1668
+ }
1669
+
1670
+ parser->status = LXB_STATUS_OK;
1671
+
1672
+ return lxb_css_selectors_done(parser);
1673
+ }
1674
+
1675
+ static void
1676
+ lxb_css_selectors_state_restore_parent(lxb_css_selectors_t *selectors,
1677
+ lxb_css_selector_list_t *last)
1678
+ {
1679
+ if (selectors->list != NULL) {
1680
+ last->last->u.pseudo.data = selectors->list;
1681
+ }
1682
+
1683
+ selectors->list_last = last;
1684
+
1685
+ /* Get first Selector in chain. */
1686
+ while (last->prev != NULL) {
1687
+ last = last->prev;
1688
+ }
1689
+
1690
+ selectors->list = last;
1691
+ selectors->parent = last->parent;
1692
+
1693
+ lxb_css_selectors_state_restore_combinator(selectors);
1694
+ }
1695
+
1696
+ static bool
1697
+ lxb_css_selectors_state_list_end(lxb_css_parser_t *parser,
1698
+ lxb_css_syntax_token_t *token,
1699
+ lxb_css_parser_state_f state)
1700
+ {
1701
+ if (token->type == LXB_CSS_SYNTAX_TOKEN_WHITESPACE) {
1702
+ lxb_css_syntax_token_consume(parser->tkz);
1703
+ lxb_css_parser_token_status_m(parser, token);
1704
+ }
1705
+
1706
+ if (token->type != LXB_CSS_SYNTAX_TOKEN_COMMA) {
1707
+ return lxb_css_selectors_done(parser);
1708
+ }
1709
+
1710
+ parser->selectors->combinator = parser->selectors->comb_default;
1711
+
1712
+ lxb_css_syntax_token_consume(parser->tkz);
1713
+ lxb_css_parser_stack_up(parser);
1714
+
1715
+ parser->state = state;
1716
+
1717
+ return true;
1718
+ }