diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/parser/cr-declaration.c | 7 | ||||
-rw-r--r-- | src/parser/cr-declaration.h | 6 | ||||
-rw-r--r-- | src/parser/cr-parser.c | 220 | ||||
-rw-r--r-- | src/parser/cr-parser.h | 2 | ||||
-rw-r--r-- | src/parser/cr-statement.c | 2 | ||||
-rw-r--r-- | src/parser/cr-term.c | 47 | ||||
-rw-r--r-- | src/parser/cr-term.h | 3 | ||||
-rw-r--r-- | tests/test4-main.c | 4 |
9 files changed, 183 insertions, 119 deletions
@@ -1,5 +1,16 @@ 2003-06-20 Dodji Seketeli <dodji@seketeli.org> + * src/parser/cr-term.[ch]: + added the cr_term_parse_expression_from_buf() function. + this is new and still needs to be tested. + + * src/parser/cr-parser.[hc]: + made cr_parser_parse_expr() public. + + * src/parser/cr-declaration.[ch]: + changed cr_declaration_parse() into + cr_declaration_parse_parse_from_buf(). + * src/parser/cr-statement.[ch]: fixed some typos. added the function cr_statement_does_buf_parses_against_core() and diff --git a/src/parser/cr-declaration.c b/src/parser/cr-declaration.c index e78aa75..cd8ac99 100644 --- a/src/parser/cr-declaration.c +++ b/src/parser/cr-declaration.c @@ -157,9 +157,9 @@ cr_declaration_new (CRStatement *a_statement, *@return the parsed declaration, or NULL in case of error. */ CRDeclaration * -cr_declaration_parse (CRStatement *a_statement, - const guchar *a_str, - enum CREncoding a_enc) +cr_declaration_parse_from_buf (CRStatement *a_statement, + const guchar *a_str, + enum CREncoding a_enc) { enum CRStatus status = CR_OK ; CRTerm *value = NULL ; @@ -216,6 +216,7 @@ cr_declaration_parse (CRStatement *a_statement, return result ; } + /** *Appends a new declaration to the current declarations list. *@param a_this the current declaration list. diff --git a/src/parser/cr-declaration.h b/src/parser/cr-declaration.h index 779abdf..acc7c8a 100644 --- a/src/parser/cr-declaration.h +++ b/src/parser/cr-declaration.h @@ -75,9 +75,9 @@ cr_declaration_new (CRStatement *a_statement, CRDeclaration * -cr_declaration_parse (CRStatement *a_statement, - const guchar *a_str, - enum CREncoding a_enc) ; +cr_declaration_parse_from_buf (CRStatement *a_statement, + const guchar *a_str, + enum CREncoding a_enc) ; CRDeclaration * cr_declaration_append (CRDeclaration *a_this, CRDeclaration *a_new) ; diff --git a/src/parser/cr-parser.c b/src/parser/cr-parser.c index 0a395fc..8bc75e0 100644 --- a/src/parser/cr-parser.c +++ b/src/parser/cr-parser.c @@ -407,9 +407,6 @@ cr_parser_parse_simple_selector (CRParser *a_this, CRSimpleSel **a_sel) ; static enum CRStatus cr_parser_parse_simple_sels (CRParser *a_this, CRSimpleSel **a_sel) ; -static enum CRStatus -cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) ; - static CRParserError * cr_parser_error_new (const guchar * a_msg, enum CRStatus) ; @@ -2166,114 +2163,6 @@ cr_parser_parse_term (CRParser *a_this, CRTerm **a_term) return status ; } -/** - *Parses an expression as defined by the css2 spec in appendix - *D.1: - *expr: term [ operator term ]* - */ -static enum CRStatus -cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) -{ - enum CRStatus status = CR_ERROR ; - CRInputPos init_pos ; - CRTerm *expr = NULL, *expr2 = NULL ; - guchar next_byte = 0 ; - gulong nb_terms = 0 ; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_expr, - CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - status = cr_parser_parse_term (a_this, &expr) ; - - CHECK_PARSING_STATUS (status, FALSE) ; - - for (;;) - { - guchar operator = 0 ; - status = cr_tknzr_peek_byte (PRIVATE (a_this)->tknzr, - 1, &next_byte) ; - if (status != CR_OK) - { - if (status == CR_END_OF_INPUT_ERROR) - { - if (!nb_terms) - { - goto error ; - } - status = CR_OK ; - break ; - } - else - { - goto error ; - } - } - - if (next_byte == '/' || next_byte == ',') - { - READ_NEXT_BYTE (a_this, &operator) ; - } - - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; - - status = cr_parser_parse_term (a_this, &expr2) ; - - if (status != CR_OK || expr2 == NULL) - { - status = CR_OK ; - break ; - } - - switch (operator) - { - case '/': - expr2->operator = DIVIDE ; - break ; - case ',': - expr2->operator = COMMA ; - - default: - break ; - } - - expr = cr_term_append_term (expr, expr2) ; - expr2 = NULL ; - operator = 0 ; - nb_terms ++ ; - } - - if (status == CR_OK) - { - *a_expr = cr_term_append_term (*a_expr, expr) ; - expr = NULL ; - - cr_parser_clear_errors (a_this) ; - return CR_OK ; - } - - error: - - if (expr) - { - cr_term_destroy (expr) ; - expr = NULL ; - } - - if (expr2) - { - cr_term_destroy (expr2) ; - expr2 = NULL ; - } - - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, - &init_pos) ; - - return status ; -} /** @@ -3759,6 +3648,115 @@ cr_parser_parse_file (CRParser *a_this, } /** + *Parses an expression as defined by the css2 spec in appendix + *D.1: + *expr: term [ operator term ]* + */ +enum CRStatus +cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) +{ + enum CRStatus status = CR_ERROR ; + CRInputPos init_pos ; + CRTerm *expr = NULL, *expr2 = NULL ; + guchar next_byte = 0 ; + gulong nb_terms = 0 ; + + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_expr, + CR_BAD_PARAM_ERROR) ; + + RECORD_INITIAL_POS (a_this, &init_pos) ; + + status = cr_parser_parse_term (a_this, &expr) ; + + CHECK_PARSING_STATUS (status, FALSE) ; + + for (;;) + { + guchar operator = 0 ; + status = cr_tknzr_peek_byte (PRIVATE (a_this)->tknzr, + 1, &next_byte) ; + if (status != CR_OK) + { + if (status == CR_END_OF_INPUT_ERROR) + { + if (!nb_terms) + { + goto error ; + } + status = CR_OK ; + break ; + } + else + { + goto error ; + } + } + + if (next_byte == '/' || next_byte == ',') + { + READ_NEXT_BYTE (a_this, &operator) ; + } + + cr_parser_try_to_skip_spaces_and_comments + (a_this) ; + + status = cr_parser_parse_term (a_this, &expr2) ; + + if (status != CR_OK || expr2 == NULL) + { + status = CR_OK ; + break ; + } + + switch (operator) + { + case '/': + expr2->operator = DIVIDE ; + break ; + case ',': + expr2->operator = COMMA ; + + default: + break ; + } + + expr = cr_term_append_term (expr, expr2) ; + expr2 = NULL ; + operator = 0 ; + nb_terms ++ ; + } + + if (status == CR_OK) + { + *a_expr = cr_term_append_term (*a_expr, expr) ; + expr = NULL ; + + cr_parser_clear_errors (a_this) ; + return CR_OK ; + } + + error: + + if (expr) + { + cr_term_destroy (expr) ; + expr = NULL ; + } + + if (expr2) + { + cr_term_destroy (expr2) ; + expr2 = NULL ; + } + + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, + &init_pos) ; + + return status ; +} + +/** *Parses a "declaration" as defined by the css2 spec in appendix D.1: *declaration ::= [property ':' S* expr prio?]? * diff --git a/src/parser/cr-parser.h b/src/parser/cr-parser.h index 1b79528..2d30aa9 100644 --- a/src/parser/cr-parser.h +++ b/src/parser/cr-parser.h @@ -106,6 +106,8 @@ cr_parser_parse_buf (CRParser *a_this, const guchar *a_buf, enum CRStatus cr_parser_set_default_sac_handler (CRParser *a_this) ; +enum CRStatus +cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) ; enum CRStatus cr_parser_parse_declaration (CRParser *a_this, GString **a_property, diff --git a/src/parser/cr-statement.c b/src/parser/cr-statement.c index 55a65c0..46dc188 100644 --- a/src/parser/cr-statement.c +++ b/src/parser/cr-statement.c @@ -1792,6 +1792,8 @@ cr_statement_ruleset_get_declarations (CRStatement *a_this, CR_BAD_PARAM_ERROR) ; *a_decl_list = a_this->kind.ruleset->decl_list ; + + return CR_OK ; } /** diff --git a/src/parser/cr-term.c b/src/parser/cr-term.c index 4efb11d..59e2348 100644 --- a/src/parser/cr-term.c +++ b/src/parser/cr-term.c @@ -27,6 +27,7 @@ #include <string.h> #include "cr-term.h" #include "cr-num.h" +#include "cr-parser.h" /** *@file @@ -104,6 +105,52 @@ cr_term_new (void) return result ; } +/** + *Parses an expresion as defined by the css2 spec + *and builds the expression as a list of terms. + *@param a_buf the buffer to parse. + *@return a pointer to the first term of the expression or + *NULL if parsing failed. + */ +CRTerm * +cr_term_parse_expression_from_buf (const guchar *a_buf, + enum CREncoding a_encoding) +{ + CRParser *parser = NULL ; + CRTerm *result = NULL ; + enum CRStatus status = CR_OK ; + + g_return_val_if_fail (a_buf, NULL) ; + + parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + a_encoding, FALSE) ; + g_return_val_if_fail (parser, NULL) ; + + status = cr_parser_try_to_skip_spaces_and_comments (parser) ; + if (status != CR_OK) + { + goto cleanup ; + } + + status = cr_parser_parse_expr (parser, &result) ; + if (status != CR_OK) + { + if (result) + { + cr_term_destroy (result) ; + result = NULL ; + } + } + + cleanup: + if (parser) + { + cr_parser_destroy (parser) ; + parser = NULL ; + } + + return result ; +} enum CRStatus cr_term_set_number (CRTerm *a_this, CRNum *a_num) diff --git a/src/parser/cr-term.h b/src/parser/cr-term.h index 3194d0a..68f6cb4 100644 --- a/src/parser/cr-term.h +++ b/src/parser/cr-term.h @@ -147,6 +147,9 @@ struct _CRTerm } ; CRTerm * +cr_term_parse_expression_from_buf (const guchar *a_buf, + enum CREncoding a_encoding) ; +CRTerm * cr_term_new (void) ; enum CRStatus diff --git a/tests/test4-main.c b/tests/test4-main.c index 4dc7ca4..3733ad5 100644 --- a/tests/test4-main.c +++ b/tests/test4-main.c @@ -152,8 +152,8 @@ test_cr_declaration_parse (void) guchar * tmp_str = NULL ; CRDeclaration * decl = NULL ; - decl = cr_declaration_parse (NULL, gv_decl_buf, - CR_UTF_8) ; + decl = cr_declaration_parse_from_buf (NULL, gv_decl_buf, + CR_UTF_8) ; tmp_str = cr_declaration_to_string (decl, 2) ; if (decl) |