summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDodji Seketeli <dodji at seketeli dot org>2003-06-22 21:19:01 +0000
committerDodji Seketeli <dodji@src.gnome.org>2003-06-22 21:19:01 +0000
commit975b9f0823f4a38d2a7651d497738d7f56e72d67 (patch)
tree6f8e54c553a709f9256e242cbe8ad86df56bf7ce
parentefaaa9bded9dbec657fa75cfd04a9cdfdc1b8b02 (diff)
downloadlibcroco-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.
-rw-r--r--ChangeLog21
-rw-r--r--TODO8
-rw-r--r--csslint/csslint.c29
-rw-r--r--docs/design/parser-architecture.txt6
-rw-r--r--src/parser/cr-doc-handler.h3
-rw-r--r--src/parser/cr-input.h6
-rw-r--r--src/parser/cr-parser.c2
-rw-r--r--src/parser/cr-statement.c113
-rw-r--r--src/parser/cr-tknzr.c33
-rw-r--r--src/parser/cr-tknzr.h8
10 files changed, 185 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index aec93db..fb19d9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+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.
+
2003-06-21 dodji <dodji@seketeli.org>
* src/parser/cr-statement.[ch]:
diff --git a/TODO b/TODO
index 9b801de..fbcee64 100644
--- a/TODO
+++ b/TODO
@@ -3,8 +3,12 @@
Well, in the cr_statement_xxx_parse_functions, memleaks
occur (the parsing result set in the sac callback is not freed)
-when a parsing fails. This is because I haven't implemented
-the "error" SAC callbacks yet. I must do it !!!
+when a parsing fails. This is because the unrecoverable error
+does not get called when the standalone parsing functions exported
+by CRParser are called independently.
+I have now to support 2 modes of parsing. Normal and standalone.
+In standalone mode, the standalone parsing functions must
+call the "unrecoverable_error" sac callback when they fail.
More debug of the test case for cr_statement_parse_from_buf ().
diff --git a/csslint/csslint.c b/csslint/csslint.c
index 0451970..8ba591a 100644
--- a/csslint/csslint.c
+++ b/csslint/csslint.c
@@ -34,8 +34,8 @@
*/
struct Options
{
- gboolean param_version ;
- gboolean param_cssom ;
+ gboolean show_version ;
+ gboolean use_cssom ;
gchar ** files_list ;
};
@@ -66,26 +66,25 @@ csslint_parse_cmd_line (int a_argc, char **a_argv,
int i= 0 ;
g_return_if_fail (a_options) ;
- memset (a_options, 0, sizeof (struct Options)) ;
-
- if (a_argc <= 1)
- {
- csslint_usage(a_argv[0]);
- }
+
+ if (a_argc <= 1)
+ {
+ csslint_usage(a_argv[0]);
+ }
for (i = 1 ; i < a_argc ; i++)
{
if (a_argv[i][0] != '-') break ;
if ((!strcmp (a_argv[i], "-version")) ||
- (!strcmp (a_argv[i], "--version")))
+ (!strcmp (a_argv[i], "--version")))
{
- a_options->param_version = TRUE ;
+ a_options->show_version = TRUE ;
}
if ((!strcmp (a_argv[i], "-cssom")) ||
- (!strcmp (a_argv[i], "--cssom")))
+ (!strcmp (a_argv[i], "--cssom")))
{
- a_options->param_cssom = TRUE ;
+ a_options->use_cssom = TRUE ;
}
}
@@ -178,15 +177,17 @@ main (int argc, char **argv)
struct Options options;
enum CRStatus status = CR_OK;
+ memset (&options, 0, sizeof (struct Options)) ;
+ options.use_cssom = TRUE ;
csslint_parse_cmd_line (argc, argv, &options);
- if (options.param_version == TRUE)
+ if (options.show_version == TRUE)
{
csslint_show_version(argv[0]);
return 0;
}
- if (options.param_cssom == TRUE)
+ if (options.use_cssom == TRUE)
{
if (options.files_list != NULL)
{
diff --git a/docs/design/parser-architecture.txt b/docs/design/parser-architecture.txt
index 96e94d1..1462296 100644
--- a/docs/design/parser-architecture.txt
+++ b/docs/design/parser-architecture.txt
@@ -131,8 +131,14 @@ to:
the a_property and a_value out parameter are valid if and only
if the function return value is CR_OK.
+ * whenever the function is parsing a construct that must
+ be notified to the user as part of the SAC api spec, notify
+ the user by calling the right SAC callback.
+
* if the parsing failed, leave the position in the stream unchanged.
That is the position in the character stream should be as if
the parsing function hasn't been called at all.
+
+
\ No newline at end of file
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 ;
} ;