135 #define PRIVATE(obj) ((obj)->priv) 137 #define CHARS_TAB_SIZE 12 144 #define IS_NUM(a_char) (((a_char) >= '0' && (a_char) <= '9')?TRUE:FALSE) 155 #define CHECK_PARSING_STATUS(status, is_exception) \ 156 if ((status) != CR_OK) \ 158 if (is_exception == FALSE) \ 160 status = CR_PARSING_ERROR ; \ 179 #define CHECK_PARSING_STATUS_ERR(a_this, a_status, a_is_exception,\ 180 a_err_msg, a_err_status) \ 181 if ((a_status) != CR_OK) \ 183 if (a_is_exception == FALSE) a_status = CR_PARSING_ERROR ; \ 184 cr_parser_push_error (a_this, a_err_msg, a_err_status) ; \ 198 #define PEEK_NEXT_CHAR(a_this, a_to_char) \ 200 enum CRStatus pnc_status ; \ 201 pnc_status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, a_to_char) ; \ 202 CHECK_PARSING_STATUS (pnc_status, TRUE) \ 213 #define READ_NEXT_CHAR(a_this, a_to_char) \ 214 status = cr_tknzr_read_char (PRIVATE (a_this)->tknzr, a_to_char) ; \ 215 CHECK_PARSING_STATUS (status, TRUE) 227 #define RECORD_INITIAL_POS(a_this, a_pos) \ 228 status = cr_tknzr_get_cur_pos (PRIVATE \ 229 (a_this)->tknzr, a_pos) ; \ 230 g_return_val_if_fail (status == CR_OK, status) 239 #define RECORD_CUR_BYTE_ADDR(a_this, a_addr) \ 240 status = cr_tknzr_get_cur_byte_addr \ 241 (PRIVATE (a_this)->tknzr, a_addr) ; \ 242 CHECK_PARSING_STATUS (status, TRUE) 255 #define PEEK_BYTE(a_parser, a_offset, a_byte_ptr) \ 256 status = cr_tknzr_peek_byte (PRIVATE (a_this)->tknzr, \ 259 CHECK_PARSING_STATUS (status, TRUE) ; 261 #define BYTE(a_parser, a_offset, a_eof) \ 262 cr_tknzr_peek_byte2 (PRIVATE (a_this)->tknzr, a_offset, a_eof) 271 #define READ_NEXT_BYTE(a_this, a_byte_ptr) \ 272 status = cr_tknzr_read_byte (PRIVATE (a_this)->tknzr, a_byte_ptr) ; \ 273 CHECK_PARSING_STATUS (status, TRUE) ; 283 #define SKIP_BYTES(a_this, a_nb_bytes) \ 284 status = cr_tknzr_seek_index (PRIVATE (a_this)->tknzr, \ 285 CR_SEEK_CUR, a_nb_bytes) ; \ 286 CHECK_PARSING_STATUS (status, TRUE) ; 295 #define SKIP_CHARS(a_parser, a_nb_chars) \ 297 glong nb_chars = a_nb_chars ; \ 298 status = cr_tknzr_consume_chars \ 299 (PRIVATE (a_parser)->tknzr,0, &nb_chars) ; \ 300 CHECK_PARSING_STATUS (status, TRUE) ; \ 309 #define ENSURE_PARSING_COND(condition) \ 310 if (! (condition)) {status = CR_PARSING_ERROR; goto error ;} 312 #define ENSURE_PARSING_COND_ERR(a_this, a_condition, \ 313 a_err_msg, a_err_status) \ 314 if (! (a_condition)) \ 316 status = CR_PARSING_ERROR; \ 317 cr_parser_push_error (a_this, a_err_msg, a_err_status) ; \ 321 #define GET_NEXT_TOKEN(a_this, a_token_ptr) \ 322 status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, \ 324 ENSURE_PARSING_COND (status == CR_OK) ; 326 #ifdef WITH_UNICODE_ESCAPE_AND_RANGE 328 guint32 * a_unicode);
330 guint32 * a_esc_code);
377 static CRParserError *cr_parser_error_new (
const guchar * a_msg,
381 const guchar * a_msg);
385 static void cr_parser_error_set_status (
CRParserError * a_this,
390 glong a_column, glong a_byte_num);
395 const guchar * a_msg,
399 gboolean a_clear_errs);
401 cr_parser_clear_errors (
CRParser * a_this);
414 cr_parser_error_new (
const guchar * a_msg,
enum CRStatus a_status)
420 if (result == NULL) {
427 cr_parser_error_set_msg (result, a_msg);
428 cr_parser_error_set_status (result, a_status);
439 cr_parser_error_set_msg (
CRParserError * a_this,
const guchar * a_msg)
441 g_return_if_fail (a_this);
444 g_free (a_this->
msg);
447 a_this->
msg = (guchar *) g_strdup ((
const gchar *) a_msg);
459 g_return_if_fail (a_this);
461 a_this->
status = a_status;
473 glong a_line, glong a_column, glong a_byte_num)
475 g_return_if_fail (a_this);
477 a_this->
line = a_line;
478 a_this->
column = a_column;
485 g_return_if_fail (a_this);
487 g_printerr (
"parsing error: %ld:%ld:", a_this->
line, a_this->
column);
489 g_printerr (
"%s\n", a_this->
msg);
499 g_return_if_fail (a_this);
502 g_free (a_this->
msg);
517 cr_parser_push_error (
CRParser * a_this,
518 const guchar * a_msg,
enum CRStatus a_status)
525 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
528 error = cr_parser_error_new (a_msg, a_status);
530 g_return_val_if_fail (error,
CR_ERROR);
534 cr_parser_error_set_pos
538 g_list_prepend (
PRIVATE (a_this)->err_stack, error);
540 if (
PRIVATE (a_this)->err_stack == NULL)
548 cr_parser_error_destroy (error);
564 cr_parser_dump_err_stack (
CRParser * a_this, gboolean a_clear_errs)
570 if (
PRIVATE (a_this)->err_stack == NULL)
573 for (cur =
PRIVATE (a_this)->err_stack; cur; cur = cur->next) {
577 if (a_clear_errs == TRUE) {
578 cr_parser_clear_errors (a_this);
590 cr_parser_clear_errors (
CRParser * a_this)
596 for (cur =
PRIVATE (a_this)->err_stack; cur; cur = cur->next) {
603 if (
PRIVATE (a_this)->err_stack) {
604 g_list_free (
PRIVATE (a_this)->err_stack);
605 PRIVATE (a_this)->err_stack = NULL;
626 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
639 while ((token != NULL)
677 cr_parser_parse_stylesheet_core (
CRParser * a_this)
699 }
else if (status !=
CR_OK) {
703 switch (token->
type) {
707 goto continue_parsing;
715 cr_parser_clear_errors (a_this);
716 if (status ==
CR_OK) {
717 goto continue_parsing;
731 cr_parser_clear_errors (a_this);
736 (a_this, (
const guchar *)
"could not recognize next production",
CR_ERROR);
738 cr_parser_dump_err_stack (a_this, TRUE);
759 cr_parser_parse_atrule_core (
CRParser * a_this)
787 status = cr_parser_parse_any_core (a_this);
788 }
while (status ==
CR_OK);
798 status = cr_parser_parse_block_core (a_this);
834 cr_parser_parse_ruleset_core (
CRParser * a_this)
843 status = cr_parser_parse_selector_core (a_this);
856 status = cr_parser_parse_declaration_core (a_this);
858 parse_declaration_list:
876 status = cr_parser_parse_declaration_core (a_this);
877 cr_parser_clear_errors (a_this);
890 goto parse_declaration_list;
899 if (status ==
CR_OK) {
923 cr_parser_parse_selector_core (
CRParser * a_this)
933 status = cr_parser_parse_any_core (a_this);
937 status = cr_parser_parse_any_core (a_this);
939 }
while (status ==
CR_OK);
962 cr_parser_parse_block_core (
CRParser * a_this)
992 goto parse_block_content;
995 goto parse_block_content;
999 status = cr_parser_parse_block_core (a_this);
1001 goto parse_block_content;
1005 status = cr_parser_parse_any_core (a_this);
1007 goto parse_block_content;
1016 if (status ==
CR_OK)
1031 cr_parser_parse_declaration_core (
CRParser * a_this)
1042 status = cr_parser_parse_property (a_this, &prop);
1044 cr_parser_clear_errors (a_this);
1057 status = cr_parser_parse_value_core (a_this);
1087 cr_parser_parse_value_core (
CRParser * a_this)
1107 switch (token->
type) {
1112 status = cr_parser_parse_block_core (a_this);
1115 goto continue_parsing;
1120 goto continue_parsing;
1126 status = cr_parser_parse_any_core (a_this);
1127 if (status ==
CR_OK) {
1129 goto continue_parsing;
1144 if (status ==
CR_OK && ref)
1168 cr_parser_parse_any_core (
CRParser * a_this)
1183 switch (token1->
type) {
1215 status = cr_parser_parse_any_core (a_this);
1216 }
while (status ==
CR_OK);
1222 && token2 && token2->type ==
PC_TK);
1229 if (token2->type ==
PC_TK) {
1235 (
PRIVATE (a_this)->tknzr, token2);
1240 status = cr_parser_parse_any_core (a_this);
1241 }
while (status ==
CR_OK);
1248 && token2 && token2->type ==
PC_TK);
1257 if (token2->type ==
BC_TK) {
1263 (
PRIVATE (a_this)->tknzr, token2);
1268 status = cr_parser_parse_any_core (a_this);
1269 }
while (status ==
CR_OK);
1276 && token2 && token2->type ==
BC_TK);
1325 cr_parser_parse_attribute_selector (
CRParser * a_this,
1361 token->
u.
str = NULL;
1372 goto parse_right_part;
1375 goto parse_right_part;
1378 goto parse_right_part;
1398 token->
u.
str = NULL;
1401 token->
u.
str = NULL;
1431 cr_parser_clear_errors (a_this);
1465 cr_parser_parse_property (
CRParser * a_this,
1471 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
1478 status = cr_parser_parse_ident (a_this, a_property);
1483 cr_parser_clear_errors (a_this);
1525 if (status !=
CR_OK || !token)
1536 if (status !=
CR_OK || !token)
1545 if (status !=
CR_OK || !token)
1559 token->
u.
num = NULL;
1565 status = cr_parser_parse_function (a_this, &func_name,
1568 if (status ==
CR_OK) {
1578 token->
u.
str = NULL;
1582 token->
u.
str = NULL;
1586 token->
u.
str = NULL;
1590 token->
u.
rgb = NULL;
1597 token->
u.
str = NULL;
1602 if (status !=
CR_OK) {
1618 cr_parser_clear_errors (a_this);
1669 gboolean found_sel = FALSE;
1670 guint32 cur_char = 0;
1677 if (status !=
CR_OK)
1695 token->
u.
str = NULL;
1720 if (status !=
CR_OK)
1731 token->
u.
str = NULL;
1738 (add_sel_list, add_sel);
1746 (
PRIVATE (a_this)->tknzr, &token);
1747 if (status !=
CR_OK)
1757 token->
u.
str = NULL;
1761 (add_sel_list, add_sel);
1771 }
else if (token && token->
type ==
BO_TK) {
1776 (
PRIVATE (a_this)->tknzr, token);
1777 if (status !=
CR_OK)
1781 status = cr_parser_parse_attribute_selector
1782 (a_this, &attr_sel);
1794 (add_sel_list, add_sel);
1813 (
PRIVATE (a_this)->tknzr, &token);
1823 token->
u.
str = NULL;
1827 token->
u.
str = NULL;
1830 status = cr_parser_parse_ident
1831 (a_this, &pseudo->
extra);
1843 if (status ==
CR_OK) {
1855 (add_sel_list, add_sel);
1860 (
PRIVATE (a_this)->tknzr, token);
1866 if (status ==
CR_OK && found_sel == TRUE) {
1870 add_sel_list = NULL;
1872 if (*a_sel == NULL) {
1885 cr_parser_clear_errors (a_this);
1900 add_sel_list = NULL;
1929 cr_parser_parse_simple_sels (
CRParser * a_this,
1935 guint32 cur_char = 0;
1937 g_return_val_if_fail (a_this
1944 status = cr_parser_parse_simple_selector (a_this, &sel);
1950 guint32 next_char = 0;
1957 if (next_char ==
'+') {
1961 }
else if (next_char ==
'>') {
1969 status = cr_parser_parse_simple_selector (a_this, &sel);
1970 if (status !=
CR_OK)
1982 cr_parser_clear_errors (a_this);
2004 cr_parser_parse_selector (
CRParser * a_this,
2009 guint32 cur_char = 0,
2018 status = cr_parser_parse_simple_sels (a_this, &simple_sels);
2023 (selector, simple_sels);
2026 (&selector->location,
2037 if (status !=
CR_OK) {
2046 if (next_char ==
',') {
2052 if (status !=
CR_OK) {
2061 if (next_char !=
',')
2069 status = cr_parser_parse_simple_sels
2070 (a_this, &simple_sels);
2077 (selector, simple_sels);
2088 *a_selector = selector;
2127 cr_parser_parse_function (
CRParser * a_this,
2136 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
2143 if (status !=
CR_OK)
2147 *a_func_name = token->
u.
str;
2148 token->
u.
str = NULL;
2163 if (status !=
CR_OK)
2176 cr_parser_clear_errors (a_this);
2183 *a_func_name = NULL;
2218 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
2248 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
2276 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
2304 cr_parser_parse_stylesheet (
CRParser * a_this)
2311 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
2318 if (
PRIVATE (a_this)->sac_handler
2319 &&
PRIVATE (a_this)->sac_handler->start_document) {
2320 PRIVATE (a_this)->sac_handler->start_document
2321 (
PRIVATE (a_this)->sac_handler);
2342 if (status ==
CR_OK && charset) {
2343 if (
PRIVATE (a_this)->sac_handler
2344 &&
PRIVATE (a_this)->sac_handler->charset) {
2345 PRIVATE (a_this)->sac_handler->charset
2346 (
PRIVATE (a_this)->sac_handler,
2347 charset, &location);
2350 status = cr_parser_parse_atrule_core (a_this);
2367 goto parse_charset ;
2383 (
PRIVATE (a_this)->tknzr, &token);
2400 (
PRIVATE (a_this)->tknzr, &token);
2406 GList *media_list = NULL;
2411 (
PRIVATE (a_this)->tknzr, token);
2419 if (status ==
CR_OK) {
2421 &&
PRIVATE (a_this)->sac_handler
2422 &&
PRIVATE (a_this)->sac_handler->import_style) {
2423 PRIVATE (a_this)->sac_handler->import_style
2424 (
PRIVATE(a_this)->sac_handler,
2429 if ((
PRIVATE (a_this)->sac_handler->resolve_import == TRUE)) {
2436 if ((
PRIVATE (a_this)->sac_handler->import_style_result)) {
2437 PRIVATE (a_this)->sac_handler->import_style_result
2438 (
PRIVATE (a_this)->sac_handler,
2439 media_list, import_string,
2444 if (
PRIVATE (a_this)->sac_handler
2445 &&
PRIVATE (a_this)->sac_handler->error) {
2446 PRIVATE (a_this)->sac_handler->error
2447 (
PRIVATE (a_this)->sac_handler);
2449 status = cr_parser_parse_atrule_core (a_this);
2464 for (cur = media_list; cur; cur = cur->next) {
2470 g_list_free (media_list);
2474 if (import_string) {
2476 import_string = NULL;
2485 (
PRIVATE (a_this)->tknzr, token);
2495 (
PRIVATE (a_this)->tknzr, &token);
2507 (
PRIVATE (a_this)->tknzr, token);
2510 goto parse_ruleset_and_others;
2514 parse_ruleset_and_others:
2520 (
PRIVATE (a_this)->tknzr, &token);
2529 (
PRIVATE (a_this)->tknzr, token);
2541 (
PRIVATE (a_this)->tknzr, &token);
2549 (
PRIVATE (a_this)->tknzr, token);
2568 (
PRIVATE (a_this)->tknzr, token);
2574 if (status ==
CR_OK) {
2577 if (
PRIVATE (a_this)->sac_handler
2578 &&
PRIVATE (a_this)->sac_handler->error) {
2579 PRIVATE (a_this)->sac_handler->
2585 status = cr_parser_parse_ruleset_core
2588 if (status ==
CR_OK) {
2596 (
PRIVATE (a_this)->tknzr, token);
2601 if (status ==
CR_OK) {
2604 if (
PRIVATE (a_this)->sac_handler
2605 &&
PRIVATE (a_this)->sac_handler->error) {
2606 PRIVATE (a_this)->sac_handler->
2612 status = cr_parser_parse_atrule_core (a_this);
2614 if (status ==
CR_OK) {
2623 (
PRIVATE (a_this)->tknzr, token);
2628 if (status ==
CR_OK) {
2631 if (
PRIVATE (a_this)->sac_handler
2632 &&
PRIVATE (a_this)->sac_handler->error) {
2633 PRIVATE (a_this)->sac_handler->
2639 status = cr_parser_parse_atrule_core (a_this);
2641 if (status ==
CR_OK) {
2649 (
PRIVATE (a_this)->tknzr, token);
2654 if (status ==
CR_OK) {
2657 if (
PRIVATE (a_this)->sac_handler
2658 &&
PRIVATE (a_this)->sac_handler->error) {
2659 PRIVATE (a_this)->sac_handler->
2665 status = cr_parser_parse_atrule_core (a_this);
2667 if (status ==
CR_OK) {
2675 (
PRIVATE (a_this)->tknzr, token);
2680 if (status ==
CR_OK) {
2696 if (
PRIVATE (a_this)->sac_handler
2697 &&
PRIVATE (a_this)->sac_handler->end_document) {
2698 PRIVATE (a_this)->sac_handler->end_document
2699 (
PRIVATE (a_this)->sac_handler);
2705 cr_parser_push_error
2706 (a_this, (
const guchar *)
"could not recognize next production",
CR_ERROR);
2708 if (
PRIVATE (a_this)->sac_handler
2709 &&
PRIVATE (a_this)->sac_handler->unrecoverable_error) {
2710 PRIVATE (a_this)->sac_handler->
2711 unrecoverable_error (
PRIVATE (a_this)->sac_handler);
2714 cr_parser_dump_err_stack (a_this, TRUE);
2725 if (
PRIVATE (a_this)->sac_handler
2726 &&
PRIVATE (a_this)->sac_handler->unrecoverable_error) {
2727 PRIVATE (a_this)->sac_handler->
2728 unrecoverable_error (
PRIVATE (a_this)->sac_handler);
2756 result = g_malloc0 (
sizeof (
CRParser));
2764 g_return_val_if_fail (status ==
CR_OK, NULL);
2787 gboolean a_free_buf)
2792 g_return_val_if_fail (a_buf && a_len, NULL);
2795 g_return_val_if_fail (input, NULL);
2820 g_return_val_if_fail (tokenizer, NULL);
2824 g_return_val_if_fail (result, NULL);
2849 g_return_val_if_fail (result, NULL);
2867 if (
PRIVATE (a_this)->sac_handler) {
2871 PRIVATE (a_this)->sac_handler = a_handler;
2893 *a_handler =
PRIVATE (a_this)->sac_handler;
2921 if (status !=
CR_OK) {
2923 default_sac_handler = NULL;
2938 gboolean a_use_core_grammar)
2942 PRIVATE (a_this)->use_core_grammar = a_use_core_grammar;
2956 gboolean * a_use_core_grammar)
2960 *a_use_core_grammar =
PRIVATE (a_this)->use_core_grammar;
2978 const guchar * a_file_uri,
enum CREncoding a_enc)
2983 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
2988 g_return_val_if_fail (tknzr != NULL,
CR_ERROR);
3017 guchar next_byte = 0;
3018 gulong nb_terms = 0;
3020 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
3030 guchar
operator = 0;
3034 if (status !=
CR_OK) {
3049 if (next_byte ==
'/' || next_byte ==
',') {
3057 if (status !=
CR_OK || expr2 == NULL) {
3064 expr2->the_operator =
DIVIDE;
3067 expr2->the_operator =
COMMA;
3079 if (status ==
CR_OK) {
3083 cr_parser_clear_errors (a_this);
3124 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
3171 CRTerm ** a_expr, gboolean * a_important)
3175 guint32 cur_char = 0;
3179 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
3180 && a_property && a_expr
3185 status = cr_parser_parse_property (a_this, a_property);
3191 (a_this, status, FALSE,
3192 (
const guchar *)
"while parsing declaration: next property is malformed",
3197 if (cur_char !=
':') {
3199 cr_parser_push_error
3201 (
const guchar *)
"while parsing declaration: this char must be ':'",
3211 (a_this, status, FALSE,
3212 (
const guchar *)
"while parsing declaration: next expression is malformed",
3220 *a_important = TRUE;
3222 *a_important = FALSE;
3232 cr_parser_clear_errors (a_this);
3277 switch (token->
type) {
3286 status = cr_parser_parse_atrule_core (a_this);
3293 status = cr_parser_parse_ruleset_core (a_this);
3294 cr_parser_clear_errors (a_this);
3331 guint32 cur_char = 0,
3337 gboolean start_selector = FALSE,
3338 is_important = FALSE;
3345 status = cr_parser_parse_selector (a_this, &selector);
3351 (a_this, cur_char ==
'{',
3352 (
const guchar *)
"while parsing rulset: current char should be '{'",
3355 if (
PRIVATE (a_this)->sac_handler
3356 &&
PRIVATE (a_this)->sac_handler->start_selector) {
3365 PRIVATE (a_this)->sac_handler->start_selector
3366 (
PRIVATE (a_this)->sac_handler, selector);
3367 start_selector = TRUE;
3381 &&
PRIVATE (a_this)->sac_handler
3382 &&
PRIVATE (a_this)->sac_handler->property) {
3383 PRIVATE (a_this)->sac_handler->property
3384 (
PRIVATE (a_this)->sac_handler, property, expr,
3387 if (status ==
CR_OK) {
3409 if (status ==
CR_OK && c ==
'}') {
3411 goto end_of_ruleset ;
3415 (a_this, status, FALSE,
3416 (
const guchar *)
"while parsing ruleset: next construction should be a declaration",
3421 if (next_char !=
';')
3430 &expr, &is_important);
3436 &&
PRIVATE (a_this)->sac_handler
3437 &&
PRIVATE (a_this)->sac_handler->property) {
3438 PRIVATE (a_this)->sac_handler->property
3439 (
PRIVATE (a_this)->sac_handler,
3440 property, expr, is_important);
3457 (a_this, cur_char ==
'}',
3458 (
const guchar *)
"while parsing rulset: current char must be a '}'",
3461 selector->location = end_parsing_location;
3462 if (
PRIVATE (a_this)->sac_handler
3463 &&
PRIVATE (a_this)->sac_handler->end_selector) {
3464 PRIVATE (a_this)->sac_handler->end_selector
3465 (
PRIVATE (a_this)->sac_handler, selector);
3466 start_selector = FALSE;
3484 cr_parser_clear_errors (a_this);
3490 if (start_selector == TRUE
3491 &&
PRIVATE (a_this)->sac_handler
3492 &&
PRIVATE (a_this)->sac_handler->error) {
3493 PRIVATE (a_this)->sac_handler->error
3494 (
PRIVATE (a_this)->sac_handler);
3544 GList ** a_media_list,
3550 guint32 cur_char = 0,
3554 g_return_val_if_fail (a_this
3556 && (*a_import_string == NULL),
3561 if (
BYTE (a_this, 1, NULL) ==
'@' 3562 &&
BYTE (a_this, 2, NULL) ==
'i' 3563 &&
BYTE (a_this, 3, NULL) ==
'm' 3564 &&
BYTE (a_this, 4, NULL) ==
'p' 3565 &&
BYTE (a_this, 5, NULL) ==
'o' 3566 &&
BYTE (a_this, 6, NULL) ==
'r' 3567 &&
BYTE (a_this, 7, NULL) ==
't') {
3571 (a_this, a_location) ;
3586 if (next_char ==
'"' || next_char ==
'\'') {
3587 status = cr_parser_parse_string (a_this, a_import_string);
3591 status = cr_parser_parse_uri (a_this, a_import_string);
3598 status = cr_parser_parse_ident (a_this, &medium);
3600 if (status ==
CR_OK && medium) {
3601 *a_media_list = g_list_append (*a_media_list, medium);
3607 for (; status ==
CR_OK;) {
3609 &next_char)) !=
CR_OK) {
3617 if (next_char ==
',') {
3625 status = cr_parser_parse_ident (a_this, &medium);
3629 if ((status ==
CR_OK) && medium) {
3630 *a_media_list = g_list_append (*a_media_list, medium);
3643 cr_parser_clear_errors (a_this);
3650 if (*a_media_list) {
3663 for (cur = *a_media_list; cur; cur = cur->next) {
3669 g_list_free (*a_media_list);
3670 *a_media_list = NULL;
3673 if (*a_import_string) {
3675 *a_import_string = NULL;
3709 guint32 next_char = 0,
3712 GList *media_list = NULL;
3715 g_return_val_if_fail (a_this
3736 medium = token->
u.
str;
3737 token->
u.
str = NULL;
3742 media_list = g_list_append (media_list, medium);
3746 for (; status ==
CR_OK;) {
3750 if (next_char ==
',') {
3758 status = cr_parser_parse_ident (a_this, &medium);
3763 media_list = g_list_append (media_list, medium);
3775 if (
PRIVATE (a_this)->sac_handler
3776 &&
PRIVATE (a_this)->sac_handler->start_media) {
3777 PRIVATE (a_this)->sac_handler->start_media
3778 (
PRIVATE (a_this)->sac_handler, media_list,
3786 for (; status ==
CR_OK;) {
3798 if (
PRIVATE (a_this)->sac_handler
3799 &&
PRIVATE (a_this)->sac_handler->end_media) {
3800 PRIVATE (a_this)->sac_handler->end_media
3801 (
PRIVATE (a_this)->sac_handler, media_list);
3818 for (cur = media_list; cur; cur = cur->next) {
3822 g_list_free (media_list);
3826 cr_parser_clear_errors (a_this);
3846 for (cur = media_list; cur; cur = cur->next) {
3850 g_list_free (media_list);
3879 CRTerm *css_expression = NULL;
3881 *page_pseudo_class = NULL,
3883 gboolean important = TRUE;
3906 page_selector = token->
u.
str;
3907 token->
u.
str = NULL;
3925 status = cr_parser_parse_ident (a_this, &page_pseudo_class);
3949 if (
PRIVATE (a_this)->sac_handler
3950 &&
PRIVATE (a_this)->sac_handler->start_page) {
3951 PRIVATE (a_this)->sac_handler->start_page
3952 (
PRIVATE (a_this)->sac_handler,
3953 page_selector, page_pseudo_class,
3968 if (
PRIVATE (a_this)->sac_handler
3969 &&
PRIVATE (a_this)->sac_handler->property) {
3973 PRIVATE (a_this)->sac_handler->property
3974 (
PRIVATE (a_this)->sac_handler,
3975 property, css_expression, important);
3985 if (css_expression) {
3987 css_expression = NULL;
3997 (
PRIVATE (a_this)->tknzr, &token);
4016 if (status !=
CR_OK)
4022 if (
PRIVATE (a_this)->sac_handler
4023 &&
PRIVATE (a_this)->sac_handler->property) {
4025 PRIVATE (a_this)->sac_handler->property
4026 (
PRIVATE (a_this)->sac_handler,
4027 property, css_expression, important);
4037 if (css_expression) {
4039 css_expression = NULL;
4050 (
PRIVATE (a_this)->tknzr, &token);
4059 if (
PRIVATE (a_this)->sac_handler
4060 &&
PRIVATE (a_this)->sac_handler->end_page) {
4061 PRIVATE (a_this)->sac_handler->end_page
4062 (
PRIVATE (a_this)->sac_handler,
4063 page_selector, page_pseudo_class);
4066 if (page_selector) {
4068 page_selector = NULL;
4071 if (page_pseudo_class) {
4073 page_pseudo_class = NULL;
4080 cr_parser_clear_errors (a_this);
4090 if (page_selector) {
4092 page_selector = NULL;
4094 if (page_pseudo_class) {
4096 page_pseudo_class = NULL;
4102 if (css_expression) {
4104 css_expression = NULL;
4133 g_return_val_if_fail (a_this && a_value
4134 && (*a_value == NULL),
4143 if (a_charset_sym_location) {
4157 charset_str = token->
u.
str;
4158 token->
u.
str = NULL;
4172 *a_value = charset_str;
4221 CRTerm *css_expression = NULL;
4223 gboolean important = FALSE;
4224 guint32 next_char = 0,
4255 if (
PRIVATE (a_this)->sac_handler
4256 &&
PRIVATE (a_this)->sac_handler->start_font_face) {
4257 PRIVATE (a_this)->sac_handler->start_font_face
4258 (
PRIVATE (a_this)->sac_handler, &location);
4266 &css_expression, &important);
4267 if (status ==
CR_OK) {
4272 if (
PRIVATE (a_this)->sac_handler &&
4273 PRIVATE (a_this)->sac_handler->property) {
4274 PRIVATE (a_this)->sac_handler->property
4275 (
PRIVATE (a_this)->sac_handler,
4276 property, css_expression, important);
4285 if (css_expression) {
4287 css_expression = NULL;
4291 if (next_char ==
';') {
4301 if (status !=
CR_OK)
4307 if (
PRIVATE (a_this)->sac_handler->property) {
4308 PRIVATE (a_this)->sac_handler->property
4309 (
PRIVATE (a_this)->sac_handler,
4310 property, css_expression, important);
4320 if (css_expression) {
4322 css_expression = NULL;
4331 if (
PRIVATE (a_this)->sac_handler->end_font_face) {
4332 PRIVATE (a_this)->sac_handler->end_font_face
4333 (
PRIVATE (a_this)->sac_handler);
4341 cr_parser_clear_errors (a_this);
4354 if (css_expression) {
4356 css_expression = NULL;
4377 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
4380 if (
PRIVATE (a_this)->use_core_grammar == FALSE) {
4381 status = cr_parser_parse_stylesheet (a_this);
4383 status = cr_parser_parse_stylesheet_core (a_this);
4401 if (
PRIVATE (a_this)->tknzr) {
4405 PRIVATE (a_this)->tknzr = a_tknzr;
4426 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
4429 *a_tknzr =
PRIVATE (a_this)->tknzr;
4447 g_return_val_if_fail (a_this
4452 (
PRIVATE (a_this)->tknzr, a_loc) ;
4468 const guchar * a_buf,
4474 g_return_val_if_fail (a_this &&
PRIVATE (a_this)
4479 g_return_val_if_fail (tknzr != NULL,
CR_ERROR);
4500 g_return_if_fail (a_this &&
PRIVATE (a_this));
4502 if (
PRIVATE (a_this)->tknzr) {
4504 PRIVATE (a_this)->tknzr = NULL;
4507 if (
PRIVATE (a_this)->sac_handler) {
4509 PRIVATE (a_this)->sac_handler = NULL;
4512 if (
PRIVATE (a_this)->err_stack) {
4513 cr_parser_clear_errors (a_this);
4514 PRIVATE (a_this)->err_stack = NULL;
enum CRStatus cr_tknzr_set_cur_pos(CRTknzr *a_this, CRInputPos *a_pos)
CRPseudo * cr_pseudo_new(void)
@CRPseudo: The definition of the CRPseudo class.
void cr_tknzr_ref(CRTknzr *a_this)
enum CRStatus cr_tknzr_get_next_token(CRTknzr *a_this, CRToken **a_tk)
Returns the next token of the input stream.
enum CRStatus cr_parser_get_sac_handler(CRParser *a_this, CRDocHandler **a_handler)
cr_parser_get_sac_handler: @a_this: the "this pointer" of the current instance of CRParser.
#define SKIP_CHARS(a_parser, a_nb_chars)
Skip utf8 encoded characters.
enum CRStatus cr_parser_parse_ruleset(CRParser *a_this)
cr_parser_parse_ruleset: @a_this: the "this pointer" of the current instance of CRParser.
enum CRTermType type
The type of the term.
void cr_doc_handler_destroy(CRDocHandler *a_this)
cr_doc_handler_destroy: @a_this: the instance of CRDocHandler to destroy.
The implementation of the SAC parser.
enum AttrMatchWay match_way
CRParsingLocation location
void cr_additional_sel_destroy(CRAdditionalSel *a_this)
cr_additional_sel_destroy: @a_this: the "this pointer" of the current instance of CRAdditionalSel .
enum Combinator combinator
The combinator that separates this simple selector from the previous one.
The private attributes of CRParser.
enum CRStatus cr_parser_set_tknzr(CRParser *a_this, CRTknzr *a_tknzr)
cr_parser_set_tknzr: @a_this: the current instance of CRParser; @a_tknzr: the new tokenizer.
CRParsingLocation location
CRAdditionalSel * cr_additional_sel_new_with_type(enum AddSelectorType a_sel_type)
cr_additional_sel_new_with_type: @a_sel_type: the type of the newly built instance of CRAdditionalSel...
CRTknzr * tknzr
The tokenizer.
enum CRStatus cr_tknzr_peek_char(CRTknzr *a_this, guint32 *a_char)
Peeks a char from the parser input stream.
#define BYTE(a_parser, a_offset, a_eof)
gboolean use_core_grammar
enum CRStatus cr_term_set_function(CRTerm *a_this, CRString *a_func_name, CRTerm *a_func_param)
CRParser * cr_parser_new(CRTknzr *a_tknzr)
cr_parser_new: @a_tknzr: the tokenizer to use for the parsing.
enum CRStatus cr_parser_set_sac_handler(CRParser *a_this, CRDocHandler *a_handler)
cr_parser_set_sac_handler: @a_this: the "this pointer" of the current instance of CRParser.
CRDocHandler * sac_handler
The sac handlers to call to notify the parsing of the css2 constructions.
CRTknzr * cr_tknzr_new_from_uri(const guchar *a_file_uri, enum CREncoding a_enc)
enum CRStatus cr_term_set_hash(CRTerm *a_this, CRString *a_str)
enum CRStatus cr_tknzr_get_parsing_location(CRTknzr *a_this, CRParsingLocation *a_loc)
void cr_string_destroy(CRString *a_this)
enum CRStatus cr_parser_parse_file(CRParser *a_this, const guchar *a_file_uri, enum CREncoding a_enc)
cr_parser_parse_file: @a_this: a pointer to the current instance of CRParser.
CREncoding
Encoding values.
gboolean cr_selector_unref(CRSelector *a_this)
cr_selector_unref:
enum CRStatus cr_parser_try_to_skip_spaces_and_comments(CRParser *a_this)
cr_parser_try_to_skip_spaces_and_comments: @a_this: the current instance of CRParser.
This class abstracts a css2 token.
typedefG_BEGIN_DECLS struct _CRSelector CRSelector
#define RECORD_INITIAL_POS(a_this, a_pos)
Gets information about the current position in the input of the parser.
CRParsingLocation location
CRStatus
The status type returned by the methods of the croco library.
CRAdditionalSel * add_sel
The additional selector list of the current simple selector.
GList * err_stack
A stack of errors reported by the parsing routines.
typedefG_BEGIN_DECLS struct _CRDocHandler CRDocHandler
CRParser * cr_parser_new_from_input(CRInput *a_input)
cr_parser_new_from_input: @a_input: the parser input stream to use.
enum CRStatus cr_tknzr_peek_byte(CRTknzr *a_this, gulong a_offset, guchar *a_byte)
Peeks a byte ahead at a given postion in the parser input stream.
CRParser * cr_parser_new_from_file(const guchar *a_file_uri, enum CREncoding a_enc)
cr_parser_new_from_file: @a_file_uri: the uri of the file to parse.
enum CRStatus cr_parser_parse(CRParser *a_this)
cr_parser_parse: @a_this: the current instance of CRParser.
CRTerm * cr_term_append_term(CRTerm *a_this, CRTerm *a_new_term)
Appends a new term to the current list of CRTerm.
enum CRStatus cr_tknzr_parse_token(CRTknzr *a_this, enum CRTokenType a_type, enum CRTokenExtraType a_et, gpointer a_res, gpointer a_extra_res)
CRParsingLocation location
The abstraction of a css2 simple selection list as defined by the right part of the "selector" produc...
CRSelector * cr_selector_append(CRSelector *a_this, CRSelector *a_new)
cr_selector_append:
enum CRStatus cr_parser_parse_page(CRParser *a_this)
cr_parser_parse_page: @a_this: the "this pointer" of the current instance of CRParser.
#define PEEK_NEXT_CHAR(a_this, a_to_char)
Peeks the next char from the input stream of the current parser by invoking cr_tknzr_input_peek_char(...
void cr_simple_sel_destroy(CRSimpleSel *a_this)
cr_simple_sel_destroy:
CRSelector * cr_selector_append_simple_sel(CRSelector *a_this, CRSimpleSel *a_simple_sel)
cr_selector_append_simple_sel:
CRString * cr_string_new_from_string(const gchar *a_string)
Instanciate a string and initialise it to a_string.
the declaration of the CRSimpleSel class.
union CRAdditionalSelectorContent content
CRAttrSel * cr_attr_sel_new(void)
CRAttrSel:
typedefG_BEGIN_DECLS struct _CRTknzr CRTknzr
enum CRStatus cr_term_set_rgb(CRTerm *a_this, CRRgb *a_rgb)
enum CRStatus cr_term_set_string(CRTerm *a_this, CRString *a_str)
The declaration of the CRNum class.
void cr_term_ref(CRTerm *a_this)
Increments the reference counter of the current instance of CRTerm.
enum CRStatus cr_parser_parse_charset(CRParser *a_this, CRString **a_value, CRParsingLocation *a_charset_sym_location)
cr_parser_parse_charset: @a_this: the "this pointer" of the current instance of CRParser.
gboolean cr_doc_handler_unref(CRDocHandler *a_this)
cr_doc_handler_unref: @a_this: the currrent instance of CRDocHandler.
CRParser * cr_parser_new_from_buf(guchar *a_buf, gulong a_len, enum CREncoding a_enc, gboolean a_free_buf)
cr_parser_new_from_buf: @a_buf: the buffer to parse.
enum CRStatus cr_attr_sel_append_attr_sel(CRAttrSel *a_this, CRAttrSel *a_attr_sel)
cr_attr_sel_append_attr_sel: @a_this: the this pointer of the current instance of CRAttrSel.
CRTknzr * cr_tknzr_new_from_buf(guchar *a_buf, gulong a_len, enum CREncoding a_enc, gboolean a_free_at_destroy)
typedefG_BEGIN_DECLS struct _CRString CRString
enum CRStatus cr_parser_parse_expr(CRParser *a_this, CRTerm **a_expr)
cr_parser_parse_expr: @a_this: the current instance of CRParser.
enum CRStatus cr_parser_parse_statement_core(CRParser *a_this)
cr_parser_parse_statement_core: @a_this: the current instance of CRParser.
gboolean is_case_sensitive
CRAdditionalSel * cr_additional_sel_append(CRAdditionalSel *a_this, CRAdditionalSel *a_sel)
cr_additional_sel_append: @a_this: the "this pointer" of the current instance of CRAdditionalSel .
#define ENSURE_PARSING_COND_ERR(a_this, a_condition, a_err_msg, a_err_status)
CRParsingLocation location
enum CRStatus cr_tknzr_unget_token(CRTknzr *a_this, CRToken *a_token)
enum CRStatus cr_parser_parse_buf(CRParser *a_this, const guchar *a_buf, gulong a_len, enum CREncoding a_enc)
cr_parser_parse_buf: @a_this: the current instance of #CRparser @a_buf: the input buffer @a_len: the ...
enum CRStatus cr_parser_get_parsing_location(CRParser const *a_this, CRParsingLocation *a_loc)
cr_parser_get_parsing_location: @a_this: the current instance of CRParser @a_loc: the parsing locatio...
void cr_attr_sel_destroy(CRAttrSel *a_this)
cr_attr_sel_destroy: @a_this: the "this pointer" of the current instance of CRAttrSel.
enum CRStatus cr_parser_parse_term(CRParser *a_this, CRTerm **a_term)
cr_parser_parse_term: @a_term: out parameter.
enum SimpleSelectorType type_mask
CRTerm * cr_term_new(void)
Instanciate a CRTerm.
enum CRStatus cr_parser_get_use_core_grammar(CRParser const *a_this, gboolean *a_use_core_grammar)
cr_parser_get_use_core_grammar: @a_this: the current instance of CRParser.
enum UnaryOperator unary_op
The unary operator associated to the current term.
enum CRStatus cr_parser_parse_prio(CRParser *a_this, CRString **a_prio)
cr_parser_parse_prio: @a_this: the current instance of CRParser.
An abstraction of a css2 term as defined in the CSS2 spec in appendix D.1: term ::= [ NUMBER S* | PER...
void cr_selector_ref(CRSelector *a_this)
cr_selector_ref:
enum CRStatus cr_parser_parse_font_face(CRParser *a_this)
cr_parser_parse_font_face: @a_this: the current instance of CRParser.
enum CRStatus cr_parser_set_use_core_grammar(CRParser *a_this, gboolean a_use_core_grammar)
cr_parser_set_use_core_grammar: @a_this: the current instance of CRParser.
CRTknzr * cr_tknzr_new(CRInput *a_input)
void cr_doc_handler_ref(CRDocHandler *a_this)
cr_doc_handler_ref: @a_this: the current instance of CRDocHandler.
The declaration file of the CRParser class.
void cr_parser_destroy(CRParser *a_this)
cr_parser_destroy: @a_this: the current instance of CRParser to destroy.
gboolean cr_tknzr_unref(CRTknzr *a_this)
enum CRStatus cr_term_set_ident(CRTerm *a_this, CRString *a_str)
Declaration of the #CRTem class.
#define ENSURE_PARSING_COND(condition)
Tests the condition and if it is false, sets status to "CR_PARSING_ERROR" and goto the 'error' label.
#define CHECK_PARSING_STATUS_ERR(a_this, a_status, a_is_exception, a_err_msg, a_err_status)
CHECK_PARSING_STATUS_ERR: @a_this: the current instance of CRParser .
#define CHECK_PARSING_STATUS(status, is_exception)
Checks if 'status' equals CR_OK.
CRSimpleSel * cr_simple_sel_new(void)
cr_simple_sel_new:
gboolean cr_term_unref(CRTerm *a_this)
Decrements the ref count of the current instance of CRTerm.
enum CRStatus cr_term_set_uri(CRTerm *a_this, CRString *a_str)
#define READ_NEXT_BYTE(a_this, a_byte_ptr)
Reads a byte from the topmost parser input steam.
enum CRStatus cr_parser_get_tknzr(CRParser *a_this, CRTknzr **a_tknzr)
cr_parser_get_tknzr: @a_this: the current instance of CRParser @a_tknzr: out parameter.
enum CRStatus cr_parser_parse_declaration(CRParser *a_this, CRString **a_property, CRTerm **a_expr, gboolean *a_important)
cr_parser_parse_declaration: @a_this: the "this pointer" of the current instance of CRParser.
enum CRStatus cr_parsing_location_copy(CRParsingLocation *a_to, CRParsingLocation const *a_from)
cr_parsing_location_copy: @a_to: the destination of the copy.
enum CRStatus cr_parser_parse_media(CRParser *a_this)
cr_parser_parse_media: @a_this: the "this pointer" of the current instance of CRParser.
enum CRStatus cr_parser_parse_import(CRParser *a_this, GList **a_media_list, CRString **a_import_string, CRParsingLocation *a_location)
cr_parser_parse_import: @a_this: the "this pointer" of the current instance of CRParser.
CRSimpleSel * cr_simple_sel_append_simple_sel(CRSimpleSel *a_this, CRSimpleSel *a_sel)
cr_simple_sel_append_simple_sel:
enum CRStatus cr_term_set_number(CRTerm *a_this, CRNum *a_num)
#define READ_NEXT_CHAR(a_this, a_to_char)
Reads the next char from the input stream of the current parser.
void cr_term_destroy(CRTerm *a_this)
The destructor of the the CRTerm class.
void cr_token_destroy(CRToken *a_this)
The destructor of the CRToken class.
enum CRStatus cr_doc_handler_set_default_sac_handler(CRDocHandler *a_this)
cr_doc_handler_set_default_sac_handler: @a_this: a pointer to the current instance of CRDocHandler.
CRParsingLocation location
CRDocHandler * cr_doc_handler_new(void)
cr_doc_handler_new: Constructor of CRDocHandler.
#define cr_utils_trace_info(a_msg)
Traces an info message.
enum CRStatus cr_parser_set_default_sac_handler(CRParser *a_this)
cr_parser_set_default_sac_handler: @a_this: a pointer to the current instance of CRParser.
An abstraction of an error reported by by the parsing routines.