1 /* 2 * Copyright (C) 2019-2023 Alexander Borisov 3 * 4 * Author: Alexander Borisov <borisov@lexbor.com> 5 */ 6 7 #ifndef LEXBOR_CSS_BASE_H 8 #define LEXBOR_CSS_BASE_H 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 15 #include "lexbor/core/base.h" 16 #include "lexbor/core/mraw.h" 17 #include "lexbor/core/str.h" 18 19 20 #define LXB_CSS_VERSION_MAJOR 1 21 #define LXB_CSS_VERSION_MINOR 2 22 #define LXB_CSS_VERSION_PATCH 0 23 24 #define LXB_CSS_VERSION_STRING \ 25 LEXBOR_STRINGIZE(LXB_CSS_VERSION_MAJOR) "." \ 26 LEXBOR_STRINGIZE(LXB_CSS_VERSION_MINOR) "." \ 27 LEXBOR_STRINGIZE(LXB_CSS_VERSION_PATCH) 28 29 30 typedef struct lxb_css_memory { 31 lexbor_dobject_t *objs; 32 lexbor_mraw_t *mraw; 33 lexbor_mraw_t *tree; 34 35 size_t ref_count; 36 } 37 lxb_css_memory_t; 38 39 typedef uint32_t lxb_css_type_t; 40 41 typedef struct lxb_css_parser lxb_css_parser_t; 42 typedef struct lxb_css_parser_state lxb_css_parser_state_t; 43 typedef struct lxb_css_parser_error lxb_css_parser_error_t; 44 45 typedef struct lxb_css_syntax_tokenizer lxb_css_syntax_tokenizer_t; 46 typedef struct lxb_css_syntax_token lxb_css_syntax_token_t; 47 48 typedef bool 49 (*lxb_css_parser_state_f)(lxb_css_parser_t *parser, 50 const lxb_css_syntax_token_t *token, void *ctx); 51 52 typedef void * 53 (*lxb_css_style_create_f)(lxb_css_memory_t *memory); 54 55 typedef lxb_status_t 56 (*lxb_css_style_serialize_f)(const void *style, lexbor_serialize_cb_f cb, 57 void *ctx); 58 59 typedef void * 60 (*lxb_css_style_destroy_f)(lxb_css_memory_t *memory, 61 void *style, bool self_destroy); 62 63 /* StyleSheet tree structures. */ 64 65 typedef struct lxb_css_stylesheet lxb_css_stylesheet_t; 66 typedef struct lxb_css_rule_list lxb_css_rule_list_t; 67 typedef struct lxb_css_rule_style lxb_css_rule_style_t; 68 typedef struct lxb_css_rule_bad_style lxb_css_rule_bad_style_t; 69 typedef struct lxb_css_rule_declaration_list lxb_css_rule_declaration_list_t; 70 typedef struct lxb_css_rule_declaration lxb_css_rule_declaration_t; 71 typedef struct lxb_css_rule_at lxb_css_rule_at_t; 72 73 typedef struct { 74 lxb_char_t *name; 75 size_t length; 76 uintptr_t unique; 77 lxb_css_parser_state_f state; 78 lxb_css_style_create_f create; 79 lxb_css_style_destroy_f destroy; 80 lxb_css_style_serialize_f serialize; 81 void *initial; 82 } 83 lxb_css_entry_data_t; 84 85 typedef struct { 86 lxb_char_t *name; 87 size_t length; 88 uintptr_t unique; 89 } 90 lxb_css_data_t; 91 92 93 LXB_API lxb_css_memory_t * 94 lxb_css_memory_create(void); 95 96 LXB_API lxb_status_t 97 lxb_css_memory_init(lxb_css_memory_t *memory, size_t prepare_count); 98 99 LXB_API void 100 lxb_css_memory_clean(lxb_css_memory_t *memory); 101 102 LXB_API lxb_css_memory_t * 103 lxb_css_memory_destroy(lxb_css_memory_t *memory, bool self_destroy); 104 105 LXB_API lxb_css_memory_t * 106 lxb_css_memory_ref_inc(lxb_css_memory_t *memory); 107 108 LXB_API void 109 lxb_css_memory_ref_dec(lxb_css_memory_t *memory); 110 111 LXB_API lxb_css_memory_t * 112 lxb_css_memory_ref_dec_destroy(lxb_css_memory_t *memory); 113 114 115 #ifdef __cplusplus 116 } /* extern "C" */ 117 #endif 118 119 #endif /* LEXBOR_CSS_BASE_H */ 120