Lines Matching refs:parser
22 lxb_html_parse_fragment_chunk_destroy(lxb_html_parser_t *parser);
32 lxb_html_parser_init(lxb_html_parser_t *parser) in lxb_html_parser_init() argument
34 if (parser == NULL) { in lxb_html_parser_init()
39 parser->tkz = lxb_html_tokenizer_create(); in lxb_html_parser_init()
40 lxb_status_t status = lxb_html_tokenizer_init(parser->tkz); in lxb_html_parser_init()
47 parser->tree = lxb_html_tree_create(); in lxb_html_parser_init()
48 status = lxb_html_tree_init(parser->tree, parser->tkz); in lxb_html_parser_init()
54 parser->original_tree = NULL; in lxb_html_parser_init()
55 parser->form = NULL; in lxb_html_parser_init()
56 parser->root = NULL; in lxb_html_parser_init()
58 parser->state = LXB_HTML_PARSER_STATE_BEGIN; in lxb_html_parser_init()
60 parser->ref_count = 1; in lxb_html_parser_init()
66 lxb_html_parser_clean(lxb_html_parser_t *parser) in lxb_html_parser_clean() argument
68 parser->original_tree = NULL; in lxb_html_parser_clean()
69 parser->form = NULL; in lxb_html_parser_clean()
70 parser->root = NULL; in lxb_html_parser_clean()
72 parser->state = LXB_HTML_PARSER_STATE_BEGIN; in lxb_html_parser_clean()
74 lxb_html_tokenizer_clean(parser->tkz); in lxb_html_parser_clean()
75 lxb_html_tree_clean(parser->tree); in lxb_html_parser_clean()
79 lxb_html_parser_destroy(lxb_html_parser_t *parser) in lxb_html_parser_destroy() argument
81 if (parser == NULL) { in lxb_html_parser_destroy()
85 parser->tkz = lxb_html_tokenizer_unref(parser->tkz); in lxb_html_parser_destroy()
86 parser->tree = lxb_html_tree_unref(parser->tree); in lxb_html_parser_destroy()
88 return lexbor_free(parser); in lxb_html_parser_destroy()
92 lxb_html_parser_ref(lxb_html_parser_t *parser) in lxb_html_parser_ref() argument
94 if (parser == NULL) { in lxb_html_parser_ref()
98 parser->ref_count++; in lxb_html_parser_ref()
100 return parser; in lxb_html_parser_ref()
104 lxb_html_parser_unref(lxb_html_parser_t *parser) in lxb_html_parser_unref() argument
106 if (parser == NULL || parser->ref_count == 0) { in lxb_html_parser_unref()
110 parser->ref_count--; in lxb_html_parser_unref()
112 if (parser->ref_count == 0) { in lxb_html_parser_unref()
113 lxb_html_parser_destroy(parser); in lxb_html_parser_unref()
121 lxb_html_parse(lxb_html_parser_t *parser, const lxb_char_t *html, size_t size) in lxb_html_parse() argument
123 lxb_html_document_t *document = lxb_html_parse_chunk_begin(parser); in lxb_html_parse()
128 lxb_html_parse_chunk_process(parser, html, size); in lxb_html_parse()
129 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse()
133 lxb_html_parse_chunk_end(parser); in lxb_html_parse()
134 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse()
148 lxb_html_parse_fragment(lxb_html_parser_t *parser, lxb_html_element_t *element, in lxb_html_parse_fragment() argument
151 return lxb_html_parse_fragment_by_tag_id(parser, in lxb_html_parse_fragment()
152 parser->tree->document, in lxb_html_parse_fragment()
159 lxb_html_parse_fragment_by_tag_id(lxb_html_parser_t *parser, in lxb_html_parse_fragment_by_tag_id() argument
164 lxb_html_parse_fragment_chunk_begin(parser, document, tag_id, ns); in lxb_html_parse_fragment_by_tag_id()
165 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_fragment_by_tag_id()
169 lxb_html_parse_fragment_chunk_process(parser, html, size); in lxb_html_parse_fragment_by_tag_id()
170 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_fragment_by_tag_id()
174 return lxb_html_parse_fragment_chunk_end(parser); in lxb_html_parse_fragment_by_tag_id()
178 lxb_html_parse_fragment_chunk_begin(lxb_html_parser_t *parser, in lxb_html_parse_fragment_chunk_begin() argument
185 if (parser->state != LXB_HTML_PARSER_STATE_BEGIN) { in lxb_html_parse_fragment_chunk_begin()
186 lxb_html_parser_clean(parser); in lxb_html_parse_fragment_chunk_begin()
189 parser->state = LXB_HTML_PARSER_STATE_FRAGMENT_PROCESS; in lxb_html_parse_fragment_chunk_begin()
193 parser->state = LXB_HTML_PARSER_STATE_ERROR; in lxb_html_parse_fragment_chunk_begin()
194 return parser->status; in lxb_html_parse_fragment_chunk_begin()
200 doc->scripting = parser->tree->scripting; in lxb_html_parse_fragment_chunk_begin()
204 lxb_html_tokenizer_set_state_by_tag(parser->tkz, doc->scripting, tag_id, ns); in lxb_html_parse_fragment_chunk_begin()
205 lxb_html_tokenizer_tmp_tag_id_set(parser->tkz, LXB_TAG__UNDEF); in lxb_html_parse_fragment_chunk_begin()
207 parser->root = lxb_html_interface_create(new_doc, LXB_TAG_HTML, LXB_NS_HTML); in lxb_html_parse_fragment_chunk_begin()
208 if (parser->root == NULL) { in lxb_html_parse_fragment_chunk_begin()
209 parser->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; in lxb_html_parse_fragment_chunk_begin()
215 parser->root); in lxb_html_parse_fragment_chunk_begin()
216 lxb_dom_document_attach_element(doc, lxb_dom_interface_element(parser->root)); in lxb_html_parse_fragment_chunk_begin()
218 parser->tree->fragment = lxb_html_interface_create(new_doc, tag_id, ns); in lxb_html_parse_fragment_chunk_begin()
219 if (parser->tree->fragment == NULL) { in lxb_html_parse_fragment_chunk_begin()
220 parser->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; in lxb_html_parse_fragment_chunk_begin()
226 parser->status = lxb_html_tree_open_elements_push(parser->tree, parser->root); in lxb_html_parse_fragment_chunk_begin()
227 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_fragment_chunk_begin()
232 parser->status = lxb_html_tree_template_insertion_push(parser->tree, in lxb_html_parse_fragment_chunk_begin()
234 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_fragment_chunk_begin()
239 lxb_html_tree_attach_document(parser->tree, new_doc); in lxb_html_parse_fragment_chunk_begin()
240 lxb_html_tree_reset_insertion_mode_appropriately(parser->tree); in lxb_html_parse_fragment_chunk_begin()
243 parser->form = lxb_html_interface_create(new_doc, in lxb_html_parse_fragment_chunk_begin()
245 if (parser->form == NULL) { in lxb_html_parse_fragment_chunk_begin()
246 parser->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; in lxb_html_parse_fragment_chunk_begin()
251 parser->tree->form = lxb_html_interface_form(parser->form); in lxb_html_parse_fragment_chunk_begin()
254 parser->original_tree = lxb_html_tokenizer_tree(parser->tkz); in lxb_html_parse_fragment_chunk_begin()
255 lxb_html_tokenizer_tree_set(parser->tkz, parser->tree); in lxb_html_parse_fragment_chunk_begin()
257 lxb_html_tokenizer_tags_set(parser->tkz, doc->tags); in lxb_html_parse_fragment_chunk_begin()
258 lxb_html_tokenizer_attrs_set(parser->tkz, doc->attrs); in lxb_html_parse_fragment_chunk_begin()
259 lxb_html_tokenizer_attrs_mraw_set(parser->tkz, doc->text); in lxb_html_parse_fragment_chunk_begin()
261 parser->status = lxb_html_tree_begin(parser->tree, new_doc); in lxb_html_parse_fragment_chunk_begin()
265 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_fragment_chunk_begin()
266 if (parser->root != NULL) { in lxb_html_parse_fragment_chunk_begin()
267 lxb_html_html_element_interface_destroy(lxb_html_interface_html(parser->root)); in lxb_html_parse_fragment_chunk_begin()
270 parser->state = LXB_HTML_PARSER_STATE_ERROR; in lxb_html_parse_fragment_chunk_begin()
271 parser->root = NULL; in lxb_html_parse_fragment_chunk_begin()
273 lxb_html_parse_fragment_chunk_destroy(parser); in lxb_html_parse_fragment_chunk_begin()
276 return parser->status; in lxb_html_parse_fragment_chunk_begin()
280 lxb_html_parse_fragment_chunk_process(lxb_html_parser_t *parser, in lxb_html_parse_fragment_chunk_process() argument
283 if (parser->state != LXB_HTML_PARSER_STATE_FRAGMENT_PROCESS) { in lxb_html_parse_fragment_chunk_process()
287 parser->status = lxb_html_tree_chunk(parser->tree, html, size); in lxb_html_parse_fragment_chunk_process()
288 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_fragment_chunk_process()
289 lxb_html_html_element_interface_destroy(lxb_html_interface_html(parser->root)); in lxb_html_parse_fragment_chunk_process()
291 parser->state = LXB_HTML_PARSER_STATE_ERROR; in lxb_html_parse_fragment_chunk_process()
292 parser->root = NULL; in lxb_html_parse_fragment_chunk_process()
294 lxb_html_parse_fragment_chunk_destroy(parser); in lxb_html_parse_fragment_chunk_process()
297 return parser->status; in lxb_html_parse_fragment_chunk_process()
301 lxb_html_parse_fragment_chunk_end(lxb_html_parser_t *parser) in lxb_html_parse_fragment_chunk_end() argument
303 if (parser->state != LXB_HTML_PARSER_STATE_FRAGMENT_PROCESS) { in lxb_html_parse_fragment_chunk_end()
304 parser->status = LXB_STATUS_ERROR_WRONG_STAGE; in lxb_html_parse_fragment_chunk_end()
309 parser->status = lxb_html_tree_end(parser->tree); in lxb_html_parse_fragment_chunk_end()
310 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_fragment_chunk_end()
311 lxb_html_html_element_interface_destroy(lxb_html_interface_html(parser->root)); in lxb_html_parse_fragment_chunk_end()
313 parser->root = NULL; in lxb_html_parse_fragment_chunk_end()
316 lxb_html_parse_fragment_chunk_destroy(parser); in lxb_html_parse_fragment_chunk_end()
318 lxb_html_tokenizer_tree_set(parser->tkz, parser->original_tree); in lxb_html_parse_fragment_chunk_end()
320 parser->state = LXB_HTML_PARSER_STATE_END; in lxb_html_parse_fragment_chunk_end()
322 return parser->root; in lxb_html_parse_fragment_chunk_end()
326 lxb_html_parse_fragment_chunk_destroy(lxb_html_parser_t *parser) in lxb_html_parse_fragment_chunk_destroy() argument
330 if (parser->form != NULL) { in lxb_html_parse_fragment_chunk_destroy()
331 lxb_html_form_element_interface_destroy(lxb_html_interface_form(parser->form)); in lxb_html_parse_fragment_chunk_destroy()
333 parser->form = NULL; in lxb_html_parse_fragment_chunk_destroy()
336 if (parser->tree->fragment != NULL) { in lxb_html_parse_fragment_chunk_destroy()
337 lxb_html_interface_destroy(parser->tree->fragment); in lxb_html_parse_fragment_chunk_destroy()
339 parser->tree->fragment = NULL; in lxb_html_parse_fragment_chunk_destroy()
342 if (lxb_html_document_is_original(parser->tree->document) == false) { in lxb_html_parse_fragment_chunk_destroy()
343 if (parser->root != NULL) { in lxb_html_parse_fragment_chunk_destroy()
344 doc = lxb_dom_interface_node(parser->tree->document)->owner_document; in lxb_html_parse_fragment_chunk_destroy()
345 parser->root->parent = &doc->node; in lxb_html_parse_fragment_chunk_destroy()
348 lxb_html_document_interface_destroy(parser->tree->document); in lxb_html_parse_fragment_chunk_destroy()
350 parser->tree->document = NULL; in lxb_html_parse_fragment_chunk_destroy()
355 lxb_html_parse_chunk_prepare(lxb_html_parser_t *parser, in lxb_html_parse_chunk_prepare() argument
358 parser->state = LXB_HTML_PARSER_STATE_PROCESS; in lxb_html_parse_chunk_prepare()
360 parser->original_tree = lxb_html_tokenizer_tree(parser->tkz); in lxb_html_parse_chunk_prepare()
361 lxb_html_tokenizer_tree_set(parser->tkz, parser->tree); in lxb_html_parse_chunk_prepare()
363 lxb_html_tokenizer_tags_set(parser->tkz, document->dom_document.tags); in lxb_html_parse_chunk_prepare()
364 lxb_html_tokenizer_attrs_set(parser->tkz, document->dom_document.attrs); in lxb_html_parse_chunk_prepare()
365 lxb_html_tokenizer_attrs_mraw_set(parser->tkz, document->dom_document.text); in lxb_html_parse_chunk_prepare()
367 parser->status = lxb_html_tree_begin(parser->tree, document); in lxb_html_parse_chunk_prepare()
368 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_chunk_prepare()
369 parser->state = LXB_HTML_PARSER_STATE_ERROR; in lxb_html_parse_chunk_prepare()
372 return parser->status; in lxb_html_parse_chunk_prepare()
376 lxb_html_parse_chunk_begin(lxb_html_parser_t *parser) in lxb_html_parse_chunk_begin() argument
380 if (parser->state != LXB_HTML_PARSER_STATE_BEGIN) { in lxb_html_parse_chunk_begin()
381 lxb_html_parser_clean(parser); in lxb_html_parse_chunk_begin()
386 parser->state = LXB_HTML_PARSER_STATE_ERROR; in lxb_html_parse_chunk_begin()
387 parser->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; in lxb_html_parse_chunk_begin()
392 document->dom_document.scripting = parser->tree->scripting; in lxb_html_parse_chunk_begin()
394 parser->status = lxb_html_parse_chunk_prepare(parser, document); in lxb_html_parse_chunk_begin()
395 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_chunk_begin()
403 lxb_html_parse_chunk_process(lxb_html_parser_t *parser, in lxb_html_parse_chunk_process() argument
406 if (parser->state != LXB_HTML_PARSER_STATE_PROCESS) { in lxb_html_parse_chunk_process()
410 parser->status = lxb_html_tree_chunk(parser->tree, html, size); in lxb_html_parse_chunk_process()
411 if (parser->status != LXB_STATUS_OK) { in lxb_html_parse_chunk_process()
412 parser->state = LXB_HTML_PARSER_STATE_ERROR; in lxb_html_parse_chunk_process()
415 return parser->status; in lxb_html_parse_chunk_process()
419 lxb_html_parse_chunk_end(lxb_html_parser_t *parser) in lxb_html_parse_chunk_end() argument
421 if (parser->state != LXB_HTML_PARSER_STATE_PROCESS) { in lxb_html_parse_chunk_end()
425 parser->status = lxb_html_tree_end(parser->tree); in lxb_html_parse_chunk_end()
427 lxb_html_tokenizer_tree_set(parser->tkz, parser->original_tree); in lxb_html_parse_chunk_end()
429 parser->state = LXB_HTML_PARSER_STATE_END; in lxb_html_parse_chunk_end()
431 return parser->status; in lxb_html_parse_chunk_end()
438 lxb_html_parser_tokenizer_noi(lxb_html_parser_t *parser) in lxb_html_parser_tokenizer_noi() argument
440 return lxb_html_parser_tokenizer(parser); in lxb_html_parser_tokenizer_noi()
444 lxb_html_parser_tree_noi(lxb_html_parser_t *parser) in lxb_html_parser_tree_noi() argument
446 return lxb_html_parser_tree(parser); in lxb_html_parser_tree_noi()
450 lxb_html_parser_status_noi(lxb_html_parser_t *parser) in lxb_html_parser_status_noi() argument
452 return lxb_html_parser_status(parser); in lxb_html_parser_status_noi()
456 lxb_html_parser_state_noi(lxb_html_parser_t *parser) in lxb_html_parser_state_noi() argument
458 return lxb_html_parser_state(parser); in lxb_html_parser_state_noi()
462 lxb_html_parser_scripting_noi(lxb_html_parser_t *parser) in lxb_html_parser_scripting_noi() argument
464 return lxb_html_parser_scripting(parser); in lxb_html_parser_scripting_noi()
468 lxb_html_parser_scripting_set_noi(lxb_html_parser_t *parser, bool scripting) in lxb_html_parser_scripting_set_noi() argument
470 lxb_html_parser_scripting_set(parser, scripting); in lxb_html_parser_scripting_set_noi()