diff options
author | Dodji Seketeli <dodji@seketeli.org> | 2003-06-20 20:58:33 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2003-06-20 20:58:33 +0000 |
commit | a3fc5bcd8c60ade057d7569932fb4c189484dd4f (patch) | |
tree | 0c5fda3ffdf71ea076c040b2ff4261226d101bd5 | |
parent | 97f56f0bfd289fdd3bd586ea13ed93517f8a6d9e (diff) | |
download | libcroco-a3fc5bcd8c60ade057d7569932fb4c189484dd4f.tar.gz |
fixed some typos. added the function
2003-06-20 Dodji Seketeli <dodji@seketeli.org>
* src/parser/cr-statement.[ch]:
fixed some typos.
added the function cr_statement_does_buf_parses_against_core() and
cr_statement_ruleset_get_declarations().
* src/parser/cr-parser.[ch]:
made cr_parser_parse_statement_core() public.
* src/parser/cr-om-parser.c:
fixed a small typo.
* src/parser/cr-declaration.[ch]
added a new cr_declaration_unlink() function.
Dodji.
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | src/parser/cr-declaration.c | 83 | ||||
-rw-r--r-- | src/parser/cr-declaration.h | 8 | ||||
-rw-r--r-- | src/parser/cr-om-parser.c | 8 | ||||
-rw-r--r-- | src/parser/cr-parser.c | 122 | ||||
-rw-r--r-- | src/parser/cr-parser.h | 3 | ||||
-rw-r--r-- | src/parser/cr-statement.c | 121 | ||||
-rw-r--r-- | src/parser/cr-statement.h | 12 |
8 files changed, 272 insertions, 101 deletions
@@ -1,3 +1,19 @@ +2003-06-20 Dodji Seketeli <dodji@seketeli.org> + + * src/parser/cr-statement.[ch]: + fixed some typos. + added the function cr_statement_does_buf_parses_against_core() and + cr_statement_ruleset_get_declarations(). + + * src/parser/cr-parser.[ch]: + made cr_parser_parse_statement_core() public. + + * src/parser/cr-om-parser.c: + fixed a small typo. + + * src/parser/cr-declaration.[ch] + added a new cr_declaration_unlink() function. + 2003-06-19 Dodji Seketeli <dodji@seketeli.org> * tests/test4-main.[ch]: updated this to test diff --git a/src/parser/cr-declaration.c b/src/parser/cr-declaration.c index 91bc2a6..e78aa75 100644 --- a/src/parser/cr-declaration.c +++ b/src/parser/cr-declaration.c @@ -242,6 +242,89 @@ cr_declaration_append (CRDeclaration *a_this, CRDeclaration *a_new) } /** + *Unlinks the declaration from the declaration list. + *@param a_decl the declaration to unlink. + *@return a pointer to the unlinked declaration in + *case of a successfull completion, NULL otherwise. + */ +CRDeclaration * +cr_declaration_unlink (CRDeclaration * a_decl) +{ + CRDeclaration *result = a_decl ; + + g_return_val_if_fail (result, NULL) ; + + /* + *some sanity checks first + */ + if (a_decl->prev) + { + g_return_val_if_fail (a_decl->prev->next == a_decl, NULL) ; + + } + if (a_decl->next) + { + g_return_val_if_fail (a_decl->next->prev == a_decl, NULL) ; + } + + /* + *now, the real unlinking job. + */ + if (a_decl->prev) + { + a_decl->prev->next = a_decl->next ; + } + if (a_decl->next) + { + a_decl->next->prev = a_decl->prev ; + } + if (a_decl->parent_statement) + { + CRDeclaration **children_decl_ptr = NULL ; + switch (a_decl->parent_statement->type) + { + case RULESET_STMT: + if (a_decl->parent_statement->kind.ruleset) + { + children_decl_ptr = + &a_decl->parent_statement-> + kind.ruleset->decl_list ; + } + + break ; + + case AT_FONT_FACE_RULE_STMT: + if (a_decl->parent_statement->kind.font_face_rule) + { + children_decl_ptr = + &a_decl->parent_statement-> + kind.font_face_rule->decl_list ; + } + break ; + case AT_PAGE_RULE_STMT: + if (a_decl->parent_statement->kind.page_rule) + { + children_decl_ptr = + &a_decl->parent_statement-> + kind.page_rule->decl_list ; + } + + default: + break ; + } + if (children_decl_ptr && *children_decl_ptr) + *children_decl_ptr = + (*children_decl_ptr)->next ; + } + + a_decl->next = NULL ; + a_decl->prev = NULL ; + a_decl->parent_statement = NULL ; + + return result ; +} + +/** *prepends a declaration to the current declaration list. *@param a_this the current declaration list. *@param a_new the declaration to prepend. diff --git a/src/parser/cr-declaration.h b/src/parser/cr-declaration.h index 4be7761..779abdf 100644 --- a/src/parser/cr-declaration.h +++ b/src/parser/cr-declaration.h @@ -82,11 +82,14 @@ CRDeclaration * cr_declaration_append (CRDeclaration *a_this, CRDeclaration *a_new) ; CRDeclaration * +cr_declaration_append2 (CRDeclaration *a_this, GString *a_prop, + CRTerm *a_value) ; + +CRDeclaration * cr_declaration_prepend (CRDeclaration *a_this, CRDeclaration *a_new) ; CRDeclaration * -cr_declaration_append2 (CRDeclaration *a_this, GString *a_prop, - CRTerm *a_value) ; +cr_declaration_unlink (CRDeclaration * a_decl) ; void cr_declaration_dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent, @@ -95,7 +98,6 @@ cr_declaration_dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent, guchar * cr_declaration_to_string (CRDeclaration *a_this, gulong a_indent) ; - void cr_declaration_ref (CRDeclaration *a_this) ; diff --git a/src/parser/cr-om-parser.c b/src/parser/cr-om-parser.c index 19d9708..da9cf01 100644 --- a/src/parser/cr-om-parser.c +++ b/src/parser/cr-om-parser.c @@ -728,7 +728,7 @@ property (CRDocHandler *a_this, case AT_FONT_FACE_RULE_STMT: decl2 = cr_declaration_append - (ctxt->cur_stmt->kind.font_face_rule->decls_list, + (ctxt->cur_stmt->kind.font_face_rule->decl_list, decl) ; if (!decl2) { @@ -737,12 +737,12 @@ property (CRDocHandler *a_this, ("Could not append decl to ruleset"); goto error ; } - ctxt->cur_stmt->kind.font_face_rule->decls_list = decl2 ; + ctxt->cur_stmt->kind.font_face_rule->decl_list = decl2 ; decl = NULL ; decl2 = NULL ; break ; case AT_PAGE_RULE_STMT: decl2 = cr_declaration_append - (ctxt->cur_stmt->kind.page_rule->decls_list, + (ctxt->cur_stmt->kind.page_rule->decl_list, decl) ; if (!decl2) { @@ -751,7 +751,7 @@ property (CRDocHandler *a_this, ("Could not append decl to ruleset"); goto error ; } - ctxt->cur_stmt->kind.page_rule->decls_list = decl2 ; + ctxt->cur_stmt->kind.page_rule->decl_list = decl2 ; decl = NULL ; decl2 = NULL ; break ; diff --git a/src/parser/cr-parser.c b/src/parser/cr-parser.c index 58454c7..0a395fc 100644 --- a/src/parser/cr-parser.c +++ b/src/parser/cr-parser.c @@ -366,9 +366,6 @@ static enum CRStatus cr_parser_parse_ruleset_core (CRParser *a_this) ; static enum CRStatus -cr_parser_parse_statement_core (CRParser *a_this) ; - -static enum CRStatus cr_parser_parse_selector_core (CRParser *a_this) ; static enum CRStatus @@ -1177,65 +1174,6 @@ cr_parser_parse_stylesheet_core (CRParser *a_this) } /** - *Parses a statement as defined by the css core grammar in - *chapter 4.1 of the css2 spec. - *statement : ruleset | at-rule; - *@param a_this the current instance of #CRParser. - *@return CR_OK upon successfull completion, an error code otherwise. - */ -static enum CRStatus -cr_parser_parse_statement_core (CRParser *a_this) -{ - CRToken *token = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; - - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK && token) ; - - switch (token->type) - { - case ATKEYWORD_TK: - case IMPORT_SYM_TK: - case PAGE_SYM_TK: - case MEDIA_SYM_TK: - case FONT_FACE_SYM_TK: - case CHARSET_SYM_TK: - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - status = cr_parser_parse_atrule_core (a_this) ; - CHECK_PARSING_STATUS (status, TRUE) ; - break ; - - default: - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - status = cr_parser_parse_ruleset_core (a_this) ; - cr_parser_clear_errors (a_this) ; - CHECK_PARSING_STATUS (status, TRUE) ; - } - - return CR_OK ; - - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } - - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; - - return status ; -} - -/** *Parses an at-rule as defined by the css core grammar *in chapter 4.1 in the css2 spec. *at-rule : ATKEYWORD S* any* [ block | ';' S* ]; @@ -3909,6 +3847,66 @@ cr_parser_parse_declaration (CRParser *a_this, GString **a_property, } /** + *Parses a statement as defined by the css core grammar in + *chapter 4.1 of the css2 spec. + *statement : ruleset | at-rule; + *@param a_this the current instance of #CRParser. + *@return CR_OK upon successfull completion, an error code otherwise. + */ +enum CRStatus +cr_parser_parse_statement_core (CRParser *a_this) +{ + CRToken *token = NULL ; + CRInputPos init_pos ; + enum CRStatus status = CR_ERROR ; + + g_return_val_if_fail (a_this && PRIVATE (a_this), + CR_BAD_PARAM_ERROR) ; + + RECORD_INITIAL_POS (a_this, &init_pos) ; + + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, + &token) ; + + ENSURE_PARSING_COND (status == CR_OK && token) ; + + switch (token->type) + { + case ATKEYWORD_TK: + case IMPORT_SYM_TK: + case PAGE_SYM_TK: + case MEDIA_SYM_TK: + case FONT_FACE_SYM_TK: + case CHARSET_SYM_TK: + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; + token = NULL ; + status = cr_parser_parse_atrule_core (a_this) ; + CHECK_PARSING_STATUS (status, TRUE) ; + break ; + + default: + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; + token = NULL ; + status = cr_parser_parse_ruleset_core (a_this) ; + cr_parser_clear_errors (a_this) ; + CHECK_PARSING_STATUS (status, TRUE) ; + } + + return CR_OK ; + + error: + if (token) + { + cr_token_destroy (token) ; + token = NULL ; + } + + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + + return status ; +} + +/** *Parses a "ruleset" as defined in the css2 spec at appendix D.1. *ruleset ::= selector [ ',' S* selector ]* *'{' S* declaration? [ ';' S* declaration? ]* '}' S*; diff --git a/src/parser/cr-parser.h b/src/parser/cr-parser.h index 93d71fe..1b79528 100644 --- a/src/parser/cr-parser.h +++ b/src/parser/cr-parser.h @@ -111,6 +111,9 @@ enum CRStatus cr_parser_parse_declaration (CRParser *a_this, GString **a_property, CRTerm **a_expr) ; enum CRStatus +cr_parser_parse_statement_core (CRParser *a_this) ; + +enum CRStatus cr_parser_parse_ruleset (CRParser *a_this) ; enum CRStatus diff --git a/src/parser/cr-statement.c b/src/parser/cr-statement.c index 947ea4c..55a65c0 100644 --- a/src/parser/cr-statement.c +++ b/src/parser/cr-statement.c @@ -96,10 +96,10 @@ parse_font_face_property_cb (CRDocHandler *a_this, } name = NULL ; - stmt->kind.font_face_rule->decls_list = - cr_declaration_append (stmt->kind.font_face_rule->decls_list, + stmt->kind.font_face_rule->decl_list = + cr_declaration_append (stmt->kind.font_face_rule->decl_list, decl) ; - if (!stmt->kind.font_face_rule->decls_list) + if (!stmt->kind.font_face_rule->decl_list) goto error ; decl = NULL ; @@ -167,10 +167,10 @@ parse_page_property_cb (CRDocHandler *a_this, decl = cr_declaration_new (stmt, name, a_expression) ; g_return_if_fail (decl) ; - stmt->kind.page_rule->decls_list = - cr_declaration_append (stmt->kind.page_rule->decls_list, + stmt->kind.page_rule->decl_list = + cr_declaration_append (stmt->kind.page_rule->decl_list, decl) ; - g_return_if_fail (stmt->kind.page_rule->decls_list) ; + g_return_if_fail (stmt->kind.page_rule->decl_list) ; } static void @@ -439,11 +439,11 @@ cr_statement_clear (CRStatement *a_this) if (!a_this->kind.page_rule) return ; - if (a_this->kind.page_rule->decls_list) + if (a_this->kind.page_rule->decl_list) { cr_declaration_destroy - (a_this->kind.page_rule->decls_list) ; - a_this->kind.page_rule->decls_list = NULL ; + (a_this->kind.page_rule->decl_list) ; + a_this->kind.page_rule->decl_list = NULL ; } if (a_this->kind.page_rule->name) { @@ -481,11 +481,11 @@ cr_statement_clear (CRStatement *a_this) if (!a_this->kind.font_face_rule) return ; - if (a_this->kind.font_face_rule->decls_list) + if (a_this->kind.font_face_rule->decl_list) { cr_declaration_unref - (a_this->kind.font_face_rule->decls_list); - a_this->kind.font_face_rule->decls_list = NULL ; + (a_this->kind.font_face_rule->decl_list); + a_this->kind.font_face_rule->decl_list = NULL ; } g_free (a_this->kind.font_face_rule) ; a_this->kind.font_face_rule = NULL ; @@ -553,7 +553,7 @@ cr_statement_dump_font_face_rule (CRStatement *a_this , FILE *a_fp, g_return_if_fail (a_this && a_this->type == AT_FONT_FACE_RULE_STMT) ; - if (a_this->kind.font_face_rule->decls_list) + if (a_this->kind.font_face_rule->decl_list) { cr_utils_dump_n_chars (' ', a_fp, a_indent) ; @@ -562,7 +562,7 @@ cr_statement_dump_font_face_rule (CRStatement *a_this , FILE *a_fp, fprintf (a_fp,"@font-face {\n") ; cr_declaration_dump - (a_this->kind.font_face_rule->decls_list, + (a_this->kind.font_face_rule->decl_list, a_fp, a_indent + DECLARATION_INDENT_NB, TRUE) ; fprintf (a_fp,"\n}") ; } @@ -649,11 +649,11 @@ cr_statement_dump_page (CRStatement *a_this, FILE *a_fp, gulong a_indent) } } - if (a_this->kind.page_rule->decls_list) + if (a_this->kind.page_rule->decl_list) { fprintf (a_fp," {\n") ; cr_declaration_dump - (a_this->kind.page_rule->decls_list, + (a_this->kind.page_rule->decl_list, a_fp, a_indent + DECLARATION_INDENT_NB, TRUE) ; fprintf (a_fp,"\n}\n") ; } @@ -768,6 +768,47 @@ cr_statement_dump_import_rule (CRStatement *a_this, FILE *a_fp, ******************/ /** + *Tries to parse a buffer and says whether if the content of the buffer + *is a css statement as defined by the "Core CSS Grammar" (chapter 4 of the + *css spec) or not. + *@param a_buf the buffer to parse. + *@param a_encoding the character encoding of a_buf. + *@return TRUE if the buffer parses against the core grammar, false otherwise. + */ +gboolean +cr_statement_does_buf_parses_against_core (const guchar *a_buf, + enum CREncoding a_encoding) +{ + CRParser *parser = NULL ; + enum CRStatus status = CR_OK ; + gboolean result = FALSE ; + + parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + a_encoding, FALSE) ; + g_return_val_if_fail (parser, FALSE) ; + + status = cr_parser_set_use_core_grammar (parser, TRUE) ; + if (status != CR_OK) + { + goto cleanup ; + } + + status = cr_parser_parse_statement_core (parser) ; + if (status == CR_OK) + { + result = TRUE ; + } + + cleanup: + if (parser) + { + cr_parser_destroy (parser) ; + } + + return result ; +} + +/** *Parses a buffer that contains a css statement and returns *an instance of #CRStatement in case of successfull parsing. *TODO: at support of "@import" rules. @@ -1295,7 +1336,7 @@ cr_statement_new_at_page_rule (CRStyleSheet *a_sheet, memset (result->kind.page_rule, 0, sizeof (CRAtPageRule)) ; if (a_decl_list) { - result->kind.page_rule->decls_list = a_decl_list; + result->kind.page_rule->decl_list = a_decl_list; cr_declaration_ref (a_decl_list) ; } result->kind.page_rule->name = a_name ; @@ -1510,7 +1551,7 @@ cr_statement_new_at_font_face_rule (CRStyleSheet *a_sheet, memset (result->kind.font_face_rule, 0, sizeof (CRAtFontFaceRule)); - result->kind.font_face_rule->decls_list = a_font_decls ; + result->kind.font_face_rule->decl_list = a_font_decls ; if (a_sheet) cr_statement_set_parent_sheet (result, a_sheet) ; @@ -1732,6 +1773,28 @@ cr_statement_ruleset_set_sel_list (CRStatement *a_this, } /** + *Gets a pointer to the list of declaration contained + *in the ruleset statement. + *@param a_this the current instance of #CRStatement. + *@a_decl_list out parameter. A pointer to the the returned + *list of declaration. Must not be NULL. + *@return CR_OK upon successfull completion, an error code if something + *bad happened. + */ +enum CRStatus +cr_statement_ruleset_get_declarations (CRStatement *a_this, + CRDeclaration **a_decl_list) +{ + g_return_val_if_fail (a_this + && a_this->type == RULESET_STMT + && a_this->kind.ruleset + && a_decl_list, + CR_BAD_PARAM_ERROR) ; + + *a_decl_list = a_this->kind.ruleset->decl_list ; +} + +/** *Gets a pointer to the selector list contained in *the current ruleset statement. *@param a_this the current ruleset statement. @@ -1936,12 +1999,12 @@ cr_statement_at_page_rule_set_declarations (CRStatement *a_this, && a_this->kind.page_rule, CR_BAD_PARAM_ERROR) ; - if (a_this->kind.page_rule->decls_list) + if (a_this->kind.page_rule->decl_list) { - cr_declaration_unref (a_this->kind.page_rule->decls_list); + cr_declaration_unref (a_this->kind.page_rule->decl_list); } - a_this->kind.page_rule->decls_list = a_decl_list ; + a_this->kind.page_rule->decl_list = a_decl_list ; if (a_decl_list) { @@ -1968,7 +2031,7 @@ cr_statement_at_page_rule_get_declarations (CRStatement *a_this, && a_this->kind.page_rule, CR_BAD_PARAM_ERROR) ; - *a_decl_list = a_this->kind.page_rule->decls_list ; + *a_decl_list = a_this->kind.page_rule->decl_list ; return CR_OK ; } @@ -2037,13 +2100,13 @@ cr_statement_at_font_face_rule_set_decls (CRStatement *a_this, && a_this->kind.font_face_rule, CR_BAD_PARAM_ERROR) ; - if (a_this->kind.font_face_rule->decls_list) + if (a_this->kind.font_face_rule->decl_list) { cr_declaration_unref - (a_this->kind.font_face_rule->decls_list) ; + (a_this->kind.font_face_rule->decl_list) ; } - a_this->kind.font_face_rule->decls_list = a_decls; + a_this->kind.font_face_rule->decl_list = a_decls; cr_declaration_ref (a_decls) ; return CR_OK ; @@ -2067,7 +2130,7 @@ cr_statement_at_font_face_rule_get_decls (CRStatement *a_this, && a_this->kind.font_face_rule, CR_BAD_PARAM_ERROR) ; - *a_decls = a_this->kind.font_face_rule->decls_list ; + *a_decls = a_this->kind.font_face_rule->decl_list ; return CR_OK ; } @@ -2094,15 +2157,15 @@ cr_statement_at_font_face_rule_add_decl (CRStatement *a_this, CR_BAD_PARAM_ERROR) ; decls = cr_declaration_append2 - (a_this->kind.font_face_rule->decls_list, + (a_this->kind.font_face_rule->decl_list, a_prop, a_value) ; g_return_val_if_fail (decls, CR_ERROR) ; - if (a_this->kind.font_face_rule->decls_list == NULL) + if (a_this->kind.font_face_rule->decl_list == NULL) cr_declaration_ref (decls) ; - a_this->kind.font_face_rule->decls_list = decls ; + a_this->kind.font_face_rule->decl_list = decls ; return CR_OK ; } diff --git a/src/parser/cr-statement.h b/src/parser/cr-statement.h index eccb927..3a2f31f 100644 --- a/src/parser/cr-statement.h +++ b/src/parser/cr-statement.h @@ -118,7 +118,7 @@ typedef struct _CRAtPageRule CRAtPageRule ; struct _CRAtPageRule { /**a list of instances of #CRDeclaration*/ - CRDeclaration *decls_list ; + CRDeclaration *decl_list ; /**page selector. Is a pseudo selector*/ GString *name ; @@ -137,7 +137,7 @@ typedef struct _CRAtFontFaceRule CRAtFontFaceRule ; struct _CRAtFontFaceRule { /*a list of instanaces of #CRDeclaration*/ - CRDeclaration *decls_list ; + CRDeclaration *decl_list ; } ; @@ -232,10 +232,12 @@ struct _CRStatement } ; +gboolean +cr_statement_does_buf_parses_against_core (const guchar *a_buf, + enum CREncoding a_encoding) ; CRStatement * cr_statement_parse_from_buf (const guchar *a_buf, enum CREncoding a_encoding) ; - CRStatement* cr_statement_new_ruleset (CRStyleSheet *a_sheet, CRSelector *a_sel_list, @@ -321,6 +323,10 @@ cr_statement_ruleset_set_decl_list (CRStatement *a_this, CRDeclaration *a_list) ; enum CRStatus +cr_statement_ruleset_get_declarations (CRStatement *a_this, + CRDeclaration **a_decl_list) ; + +enum CRStatus cr_statement_ruleset_append_decl2 (CRStatement *a_this, GString *a_prop, CRTerm *a_value) ; |