1 /*
2 * Copyright (C) 2018-2020 Alexander Borisov
3 *
4 * Author: Alexander Borisov <borisov@lexbor.com>
5 */
6
7 #ifndef LEXBOR_HTML_TOKEN_H
8 #define LEXBOR_HTML_TOKEN_H
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 #include "lexbor/core/dobject.h"
15 #include "lexbor/core/str.h"
16
17 #include "lexbor/html/base.h"
18 #include "lexbor/html/token_attr.h"
19 #include "lexbor/tag/tag.h"
20
21
22 typedef int lxb_html_token_type_t;
23
24
25 enum lxb_html_token_type {
26 LXB_HTML_TOKEN_TYPE_OPEN = 0x0000,
27 LXB_HTML_TOKEN_TYPE_CLOSE = 0x0001,
28 LXB_HTML_TOKEN_TYPE_CLOSE_SELF = 0x0002,
29 LXB_HTML_TOKEN_TYPE_FORCE_QUIRKS = 0x0004,
30 LXB_HTML_TOKEN_TYPE_DONE = 0x0008
31 };
32
33 typedef struct {
34 const lxb_char_t *begin;
35 const lxb_char_t *end;
36 size_t line;
37 size_t column;
38
39 const lxb_char_t *text_start;
40 const lxb_char_t *text_end;
41
42 lxb_html_token_attr_t *attr_first;
43 lxb_html_token_attr_t *attr_last;
44
45 void *base_element;
46
47 size_t null_count;
48 lxb_tag_id_t tag_id;
49 lxb_html_token_type_t type;
50 }
51 lxb_html_token_t;
52
53
54 LXB_API lxb_html_token_t *
55 lxb_html_token_create(lexbor_dobject_t *dobj);
56
57 LXB_API lxb_html_token_t *
58 lxb_html_token_destroy(lxb_html_token_t *token, lexbor_dobject_t *dobj);
59
60 LXB_API lxb_html_token_attr_t *
61 lxb_html_token_attr_append(lxb_html_token_t *token, lexbor_dobject_t *dobj);
62
63 LXB_API void
64 lxb_html_token_attr_remove(lxb_html_token_t *token,
65 lxb_html_token_attr_t *attr);
66
67 LXB_API void
68 lxb_html_token_attr_delete(lxb_html_token_t *token,
69 lxb_html_token_attr_t *attr, lexbor_dobject_t *dobj);
70
71 LXB_API lxb_status_t
72 lxb_html_token_make_text(lxb_html_token_t *token, lexbor_str_t *str,
73 lexbor_mraw_t *mraw);
74
75 LXB_API lxb_status_t
76 lxb_html_token_make_text_drop_null(lxb_html_token_t *token, lexbor_str_t *str,
77 lexbor_mraw_t *mraw);
78
79 LXB_API lxb_status_t
80 lxb_html_token_make_text_replace_null(lxb_html_token_t *token,
81 lexbor_str_t *str, lexbor_mraw_t *mraw);
82
83 LXB_API lxb_status_t
84 lxb_html_token_data_skip_ws_begin(lxb_html_token_t *token);
85
86 LXB_API lxb_status_t
87 lxb_html_token_data_skip_one_newline_begin(lxb_html_token_t *token);
88
89 LXB_API lxb_status_t
90 lxb_html_token_data_split_ws_begin(lxb_html_token_t *token,
91 lxb_html_token_t *ws_token);
92
93 LXB_API lxb_status_t
94 lxb_html_token_doctype_parse(lxb_html_token_t *token,
95 lxb_dom_document_type_t *doc_type);
96
97 LXB_API lxb_html_token_attr_t *
98 lxb_html_token_find_attr(lxb_html_tokenizer_t *tkz, lxb_html_token_t *token,
99 const lxb_char_t *name, size_t name_len);
100
101
102 /*
103 * Inline functions
104 */
105 lxb_inline void
lxb_html_token_clean(lxb_html_token_t * token)106 lxb_html_token_clean(lxb_html_token_t *token)
107 {
108 memset(token, 0, sizeof(lxb_html_token_t));
109 }
110
111 lxb_inline lxb_html_token_t *
lxb_html_token_create_eof(lexbor_dobject_t * dobj)112 lxb_html_token_create_eof(lexbor_dobject_t *dobj)
113 {
114 return (lxb_html_token_t *) lexbor_dobject_calloc(dobj);
115 }
116
117 /*
118 * No inline functions for ABI.
119 */
120 LXB_API void
121 lxb_html_token_clean_noi(lxb_html_token_t *token);
122
123 LXB_API lxb_html_token_t *
124 lxb_html_token_create_eof_noi(lexbor_dobject_t *dobj);
125
126
127 #ifdef __cplusplus
128 } /* extern "C" */
129 #endif
130
131 #endif /* LEXBOR_HTML_TOKEN_H */
132
133