diff options
author | Dodji Seketeli <dodji at seketeli dot org> | 2003-06-22 21:19:01 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2003-06-22 21:19:01 +0000 |
commit | 975b9f0823f4a38d2a7651d497738d7f56e72d67 (patch) | |
tree | 6f8e54c553a709f9256e242cbe8ad86df56bf7ce /src/parser | |
parent | efaaa9bded9dbec657fa75cfd04a9cdfdc1b8b02 (diff) | |
download | libcroco-975b9f0823f4a38d2a7651d497738d7f56e72d67.tar.gz |
added parse_font_face_unrecoverable_error_cb(),
2003-06-22 Dodji Seketeli <dodji at seketeli dot org>
* src/parser/cr-statement.c: added
parse_font_face_unrecoverable_error_cb(),
parse_page_unrecoverable_error_cb() ... to handle
parsing error in the cr_statement_xxx_parse() method.
These callback method are not called yet.
* src/parser/cr-tknzr.c: made the cr_tknzr_parse_important() look
somewhat better.
* src/parser/cr-parser.c: fixed some bugs in the parser.
It does now parse the w3c forward compatible parsing test sheet
at http://www.w3.org/Style/CSS/Test/CSS1/current/sec71.htm .
* docs/design/parser-architecture.txt: updated this doc.
A lot more is still needed.
* csslint/csslint.c: fixed some small bugs in csslint. Now, --cssom is
set by default.
Dodji.
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/cr-doc-handler.h | 3 | ||||
-rw-r--r-- | src/parser/cr-input.h | 6 | ||||
-rw-r--r-- | src/parser/cr-parser.c | 2 | ||||
-rw-r--r-- | src/parser/cr-statement.c | 113 | ||||
-rw-r--r-- | src/parser/cr-tknzr.c | 33 | ||||
-rw-r--r-- | src/parser/cr-tknzr.h | 8 |
6 files changed, 137 insertions, 28 deletions
diff --git a/src/parser/cr-doc-handler.h b/src/parser/cr-doc-handler.h index 0d654d9..9a5a3b2 100644 --- a/src/parser/cr-doc-handler.h +++ b/src/parser/cr-doc-handler.h @@ -251,7 +251,8 @@ struct _CRDocHandler /** *Is called to notify an unrecoverable parsing error. - * + *This is the place to put emergency routines that free allocated + *resources. */ void (*unrecoverable_error) (CRDocHandler *a_this) ; diff --git a/src/parser/cr-input.h b/src/parser/cr-input.h index d82959c..3c450a5 100644 --- a/src/parser/cr-input.h +++ b/src/parser/cr-input.h @@ -36,13 +36,17 @@ G_BEGIN_DECLS /** *@file - *The libcroco basic input source + *The libcroco basic input stream class *declaration file. */ typedef struct _CRInput CRInput ; typedef struct _CRInputPriv CRInputPriv ; +/** + *The #CRInput class provides the abstraction of + *an utf8-encoded character stream. + */ struct _CRInput { CRInputPriv *priv ; diff --git a/src/parser/cr-parser.c b/src/parser/cr-parser.c index 8bc75e0..6f0015e 100644 --- a/src/parser/cr-parser.c +++ b/src/parser/cr-parser.c @@ -1671,6 +1671,8 @@ cr_parser_parse_any_core (CRParser *a_this) case INCLUDES_TK: case DASHMATCH_TK: case S_TK: + case IMPORTANT_SYM_TK: + case SEMICOLON_TK: status = CR_OK ; break ; case FUNCTION_TK: diff --git a/src/parser/cr-statement.c b/src/parser/cr-statement.c index 1bec2fe..36458c9 100644 --- a/src/parser/cr-statement.c +++ b/src/parser/cr-statement.c @@ -71,6 +71,29 @@ parse_font_face_start_font_face_cb (CRDocHandler *a_this) } static void +parse_font_face_unrecoverable_error_cb (CRDocHandler *a_this) +{ + CRStatement *stmt = NULL ; + enum CRStatus status = CR_OK ; + + g_return_if_fail (a_this) ; + + status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; + if (status != CR_OK) + { + cr_utils_trace_info ("Couldn't get parsing context. " + "This may lead to some memory leaks.") ; + return ; + } + if (stmt) + { + cr_statement_destroy (stmt) ; + cr_doc_handler_set_ctxt (a_this, NULL) ; + return ; + } +} + +static void parse_font_face_property_cb (CRDocHandler *a_this, GString *a_name, CRTerm *a_value) @@ -81,11 +104,11 @@ parse_font_face_property_cb (CRDocHandler *a_this, CRStatement *stmt = NULL ; g_return_if_fail (a_this && a_name) ; - + status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; g_return_if_fail (status == CR_OK && stmt) ; g_return_if_fail (stmt->type == AT_FONT_FACE_RULE_STMT) ; - + name = g_string_new_len (a_name->str, a_name->len) ; g_return_if_fail (name) ; decl = cr_declaration_new (stmt, name, a_value) ; @@ -149,6 +172,29 @@ parse_page_start_page_cb (CRDocHandler *a_this, } static void +parse_page_unrecoverable_error_cb (CRDocHandler *a_this) +{ + CRStatement *stmt = NULL ; + enum CRStatus status = CR_OK ; + + g_return_if_fail (a_this) ; + + status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; + if (status != CR_OK) + { + cr_utils_trace_info ("Couldn't get parsing context. " + "This may lead to some memory leaks.") ; + return ; + } + if (stmt) + { + cr_statement_destroy (stmt) ; + stmt = NULL ; + cr_doc_handler_set_ctxt (a_this, NULL) ; + } +} + +static void parse_page_property_cb (CRDocHandler *a_this, GString *a_name, CRTerm *a_expression) @@ -184,8 +230,9 @@ parse_page_end_page_cb (CRDocHandler *a_this, status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; g_return_if_fail (status == CR_OK && stmt); g_return_if_fail (stmt->type == AT_PAGE_RULE_STMT); - + status = cr_doc_handler_set_result (a_this, stmt) ; + status = cr_doc_handler_set_result (a_this, NULL) ; g_return_if_fail (status == CR_OK) ; } @@ -211,8 +258,34 @@ parse_at_media_start_media_cb (CRDocHandler *a_this, at_media = cr_statement_new_at_media_rule (NULL, NULL, media_list) ; - status = cr_doc_handler_set_ctxt (a_this, at_media) ; - g_return_if_fail (status == CR_OK) ; + status = cr_doc_handler_set_ctxt (a_this, at_media) ; + g_return_if_fail (status == CR_OK) ; + status = cr_doc_handler_set_result (a_this, at_media) ; + g_return_if_fail (status == CR_OK) ; +} + +static void +parse_at_media_unrecoverable_error_cb (CRDocHandler *a_this) +{ + enum CRStatus status = CR_OK ; + CRStatement * stmt = NULL ; + + g_return_if_fail (a_this) ; + + status = cr_doc_handler_get_result (a_this, (gpointer*)&stmt) ; + if (status != CR_OK) + { + cr_utils_trace_info ("Couldn't get parsing context. " + "This may lead to some memory leaks.") ; + return ; + } + if (stmt) + { + cr_statement_destroy (stmt) ; + stmt = NULL ; + cr_doc_handler_set_ctxt (a_this, NULL) ; + cr_doc_handler_set_result (a_this, NULL) ; + } } static void @@ -324,6 +397,27 @@ parse_ruleset_start_selector_cb (CRDocHandler *a_this, } static void +parse_ruleset_unrecoverable_error_cb (CRDocHandler *a_this) +{ + CRStatement *stmt = NULL ; + enum CRStatus status = CR_OK ; + + status = cr_doc_handler_get_result (a_this, (gpointer*)&stmt) ; + if (status != CR_OK) + { + cr_utils_trace_info ("Couldn't get parsing context. " + "This may lead to some memory leaks.") ; + return ; + } + if (stmt) + { + cr_statement_destroy (stmt) ; + stmt = NULL ; + cr_doc_handler_set_result (a_this, NULL) ; + } +} + +static void parse_ruleset_property_cb (CRDocHandler *a_this, GString *a_name, CRTerm *a_value) { @@ -927,7 +1021,8 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf, sac_handler->start_selector = parse_ruleset_start_selector_cb ; sac_handler->end_selector = parse_ruleset_end_selector_cb ; sac_handler->property = parse_ruleset_property_cb ; - + sac_handler->unrecoverable_error = + parse_ruleset_unrecoverable_error_cb ; cr_parser_set_sac_handler (parser, sac_handler) ; cr_parser_try_to_skip_spaces_and_comments (parser) ; @@ -1076,6 +1171,8 @@ cr_statement_at_media_rule_parse_from_buf (const guchar *a_buf, parse_at_media_end_selector_cb ; sac_handler->end_media = parse_at_media_end_media_cb ; + sac_handler->unrecoverable_error = + parse_at_media_unrecoverable_error_cb ; status = cr_parser_set_sac_handler (parser, sac_handler) ; if (status != CR_OK) @@ -1388,6 +1485,8 @@ cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf, parse_page_property_cb ; sac_handler->end_page = parse_page_end_page_cb ; + sac_handler->unrecoverable_error = + parse_page_unrecoverable_error_cb ; status = cr_parser_set_sac_handler (parser, sac_handler) ; if (status != CR_OK) @@ -1590,6 +1689,8 @@ cr_statement_font_face_rule_parse_from_buf (const guchar *a_buf, sac_handler->start_font_face = parse_font_face_start_font_face_cb ; sac_handler->property = parse_font_face_property_cb ; sac_handler->end_font_face = parse_font_face_end_font_face_cb ; + sac_handler->unrecoverable_error = + parse_font_face_unrecoverable_error_cb ; status = cr_parser_set_sac_handler (parser, sac_handler) ; if (status != CR_OK) diff --git a/src/parser/cr-tknzr.c b/src/parser/cr-tknzr.c index 258b3bd..4315460 100644 --- a/src/parser/cr-tknzr.c +++ b/src/parser/cr-tknzr.c @@ -1524,7 +1524,6 @@ static enum CRStatus cr_tknzr_parse_important (CRTknzr *a_this) { guint32 cur_char = 0 ; - guchar next_bytes [9] ; CRInputPos init_pos ; enum CRStatus status = CR_OK ; @@ -1540,29 +1539,23 @@ cr_tknzr_parse_important (CRTknzr *a_this) cr_tknzr_try_to_skip_spaces (a_this) ; - PEEK_BYTE (a_this, 1, &next_bytes[0]) ; - PEEK_BYTE (a_this, 2, &next_bytes[1]) ; - PEEK_BYTE (a_this, 3, &next_bytes[2]) ; - PEEK_BYTE (a_this, 4, &next_bytes[3]) ; - PEEK_BYTE (a_this, 5, &next_bytes[4]) ; - PEEK_BYTE (a_this, 6, &next_bytes[5]) ; - PEEK_BYTE (a_this, 7, &next_bytes[6]) ; - PEEK_BYTE (a_this, 8, &next_bytes[7]) ; - PEEK_BYTE (a_this, 9, &next_bytes[9]) ; - - if (next_bytes[0] == 'i' - && next_bytes[1] == 'm' - && next_bytes[2] == 'p' - && next_bytes[3] == 'o' - && next_bytes[4] == 'r' - && next_bytes[5] == 't' - && next_bytes[6] == 'a' - && next_bytes[7] == 'n' - && next_bytes[8] == 't') + if (BYTE (PRIVATE (a_this)->input, 1, NULL) == 'i' + && BYTE (PRIVATE (a_this)->input, 2, NULL) == 'm' + && BYTE (PRIVATE (a_this)->input, 3, NULL) == 'p' + && BYTE (PRIVATE (a_this)->input, 4, NULL) == 'o' + && BYTE (PRIVATE (a_this)->input, 5, NULL) == 'r' + && BYTE (PRIVATE (a_this)->input, 6, NULL) == 't' + && BYTE (PRIVATE (a_this)->input, 7, NULL) == 'a' + && BYTE (PRIVATE (a_this)->input, 8, NULL) == 'n' + && BYTE (PRIVATE (a_this)->input, 9, NULL) == 't') { SKIP_BYTES (a_this, 9) ; return CR_OK ; } + else + { + status = CR_PARSING_ERROR ; + } error: cr_tknzr_set_cur_pos (a_this, &init_pos) ; diff --git a/src/parser/cr-tknzr.h b/src/parser/cr-tknzr.h index 6ba7d6b..5658151 100644 --- a/src/parser/cr-tknzr.h +++ b/src/parser/cr-tknzr.h @@ -29,6 +29,7 @@ *The declaration of the #CRTknzr (tokenizer) *class. */ + #ifndef __CR_TKNZR_H__ #define __CR_TKNZR_H__ @@ -42,8 +43,15 @@ G_BEGIN_DECLS typedef struct _CRTknzr CRTknzr ; typedef struct _CRTknzrPriv CRTknzrPriv ; +/** + *The tokenizer is the class that knows + *about all the css token. Its main job is + *to return the next token found in the character + *input stream. + */ struct _CRTknzr { + /*the private data of the tokenizer.*/ CRTknzrPriv *priv ; } ; |