summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@gnome.org>2004-02-12 22:49:12 +0000
committerDodji Seketeli <dodji@src.gnome.org>2004-02-12 22:49:12 +0000
commit63f60598e030911846c399c3aab45e0cc8ee2993 (patch)
tree2b98e90197ccdd63766166ad88bd849915778c64 /src
parente8f702b7cdd74a0be61123c6bf5fae5e0a0587b5 (diff)
downloadlibcroco-63f60598e030911846c399c3aab45e0cc8ee2993.tar.gz
added this new api entry point to parse comma separated list of property
2004-02-12 Dodji Seketeli <dodji@gnome.org> * src/cr-declaration.[ch]: (cr_declaration_parse_list_from_buf): added this new api entry point to parse comma separated list of property declarations. * src/cr-parser.c: (cr_parser_parse_expr): dont return an error when we encounter EOF immediately at the end of an expression. (cr_parser_get_tknzr): added this new api entry point to get the parser's underlying tokenizer. * src/cr-statement.h: fixed a comment here. * tests/test4-main.c: wrote a test for the new cr_declaration_parse_list_from_buf() function.
Diffstat (limited to 'src')
-rw-r--r--src/cr-declaration.c116
-rw-r--r--src/cr-declaration.h5
-rw-r--r--src/cr-parser.c29
-rw-r--r--src/cr-parser.h3
-rw-r--r--src/cr-statement.h4
5 files changed, 155 insertions, 2 deletions
diff --git a/src/cr-declaration.c b/src/cr-declaration.c
index 096759c..352bebe 100644
--- a/src/cr-declaration.c
+++ b/src/cr-declaration.c
@@ -216,6 +216,122 @@ cr_declaration_parse_from_buf (CRStatement *a_statement,
return result ;
}
+/**
+ *Parses a ';' separated list of properties declaration.
+ *@param a_str the input buffer that contains the list of declaration to
+ *parse.
+ *@param a_enc the encoding of a_str
+ *@return the parsed list of declaration, NULL if parsing failed.
+ */
+CRDeclaration *
+cr_declaration_parse_list_from_buf (const guchar *a_str, enum CREncoding a_enc)
+{
+
+ enum CRStatus status = CR_OK ;
+ CRTerm *value = NULL ;
+ GString *property = NULL;
+ CRDeclaration *result = NULL, *cur_decl = NULL ;
+ CRParser * parser = NULL ;
+ CRTknzr *tokenizer = NULL ;
+
+ g_return_val_if_fail (a_str, NULL) ;
+
+ parser = cr_parser_new_from_buf (a_str,
+ strlen (a_str),
+ a_enc, FALSE) ;
+ g_return_val_if_fail (parser, NULL) ;
+ status = cr_parser_get_tknzr (parser, &tokenizer) ;
+ if (status != CR_OK || !tokenizer)
+ {
+ if (status == CR_OK)
+ status = CR_ERROR ;
+ goto cleanup ;
+ }
+ status = cr_parser_try_to_skip_spaces_and_comments (parser) ;
+ if (status != CR_OK)
+ goto cleanup ;
+
+ status = cr_parser_parse_declaration (parser, &property,
+ &value) ;
+ if (status != CR_OK || !property)
+ {
+ if (status != CR_OK)
+ status = CR_ERROR ;
+ goto cleanup ;
+ }
+ result = cr_declaration_new (NULL, property, value) ;
+ if (result)
+ {
+ property = NULL ;
+ value = NULL ;
+ }
+ /*now, go parse the other declarations*/
+ for (;;)
+ {
+ guint32 c = 0 ;
+ cr_parser_try_to_skip_spaces_and_comments (parser) ;
+ status = cr_tknzr_peek_char (tokenizer, &c) ;
+ if (status != CR_OK)
+ {
+ if (status == CR_END_OF_INPUT_ERROR)
+ status = CR_OK ;
+ goto cleanup ;
+ }
+ if (c == ';')
+ {
+ status = cr_tknzr_read_char (tokenizer, &c) ;
+ }
+ else
+ {
+ break ;
+ }
+ cr_parser_try_to_skip_spaces_and_comments (parser) ;
+ status = cr_parser_parse_declaration (parser, &property,
+ &value) ;
+ if (status != CR_OK || !property)
+ break ;
+ cur_decl = cr_declaration_new (NULL, property, value) ;
+ if (cur_decl)
+ {
+ result = cr_declaration_append (result, cur_decl) ;
+ property = NULL ;
+ value = NULL ;
+ cur_decl = NULL;
+ }
+ else
+ {
+ break ;
+ }
+ }
+
+ cleanup:
+
+ if (parser)
+ {
+ cr_parser_destroy (parser) ;
+ parser = NULL ;
+ }
+
+ if (property)
+ {
+ g_string_free (property, TRUE) ;
+ property = NULL ;
+ }
+
+ if (value)
+ {
+ cr_term_destroy (value) ;
+ value = NULL ;
+ }
+
+ if (status != CR_OK && result)
+ {
+ cr_declaration_destroy (result) ;
+ result = NULL ;
+ }
+ return result ;
+}
+
/**
*Appends a new declaration to the current declarations list.
diff --git a/src/cr-declaration.h b/src/cr-declaration.h
index acc7c8a..c96c551 100644
--- a/src/cr-declaration.h
+++ b/src/cr-declaration.h
@@ -78,6 +78,11 @@ CRDeclaration *
cr_declaration_parse_from_buf (CRStatement *a_statement,
const guchar *a_str,
enum CREncoding a_enc) ;
+
+CRDeclaration *
+cr_declaration_parse_list_from_buf (const guchar *a_str,
+ enum CREncoding a_enc) ;
+
CRDeclaration *
cr_declaration_append (CRDeclaration *a_this, CRDeclaration *a_new) ;
diff --git a/src/cr-parser.c b/src/cr-parser.c
index c580799..6cb5219 100644
--- a/src/cr-parser.c
+++ b/src/cr-parser.c
@@ -3682,10 +3682,12 @@ cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr)
{
if (status == CR_END_OF_INPUT_ERROR)
{
+ /*
if (!nb_terms)
{
goto error ;
- }
+ }
+ */
status = CR_OK ;
break ;
}
@@ -5124,7 +5126,32 @@ cr_parser_set_tknzr (CRParser *a_this, CRTknzr *a_tknzr)
return CR_OK ;
}
+/**
+ *Getter of the parser's underlying tokenizer
+ *@param a_this the current instance of #CRParser
+ *@param a_tknzr out parameter. The returned tokenizer
+ *@return CR_OK upon succesful completion, an error code
+ *otherwise
+ */
+enum CRStatus
+cr_parser_get_tknzr (CRParser *a_this, CRTknzr **a_tknzr)
+{
+ g_return_val_if_fail (a_this && PRIVATE (a_this)
+ && a_tknzr,
+ CR_BAD_PARAM_ERROR) ;
+
+ *a_tknzr = PRIVATE (a_this)->tknzr ;
+ return CR_OK ;
+}
+/**
+ *Parses a stylesheet from a buffer
+ *@param a_this the current instance of #CRparser
+ *@param a_buf the input buffer
+ *@param a_len the length of the input buffer
+ *@param a_enc the encoding of the buffer
+ *@return CR_OK upon successful completion, an error code otherwise.
+ */
enum CRStatus
cr_parser_parse_buf (CRParser *a_this, const guchar *a_buf,
gulong a_len, enum CREncoding a_enc)
diff --git a/src/cr-parser.h b/src/cr-parser.h
index 4dc80cb..9339c9a 100644
--- a/src/cr-parser.h
+++ b/src/cr-parser.h
@@ -74,6 +74,9 @@ enum CRStatus
cr_parser_set_tknzr (CRParser *a_this, CRTknzr *a_tknzr) ;
enum CRStatus
+cr_parser_get_tknzr (CRParser *a_this, CRTknzr **a_tknzr) ;
+
+enum CRStatus
cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) ;
diff --git a/src/cr-statement.h b/src/cr-statement.h
index 9f893be..b052c26 100644
--- a/src/cr-statement.h
+++ b/src/cr-statement.h
@@ -151,9 +151,11 @@ enum CRStatementType
*each unknown at-rule will
*be of this type.
*/
+
+ /**A css at-rule*/
AT_RULE_STMT = 0,
- /**A css at-rule*/
+ /*A css ruleset*/
RULESET_STMT,
/**A css2 import rule*/