cr-parser.c revision 0489e8dae1154191b4fa0931545298513034ff38
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * This file is part of The Croco Library
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * This program is free software; you can redistribute it and/or
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * modify it under the terms of version 2.1 of the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * GNU Lesser General Public
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * License as published by the Free Software Foundation.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * This program is distributed in the hope that it will be useful,
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * but WITHOUT ANY WARRANTY; without even the implied warranty of
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * GNU General Public License for more details.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * You should have received a copy of the GNU Lesser General Public License
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * along with this program; if not, write to the Free Software
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * Author: Dodji Seketeli
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy * See COPYRIGHTS file for copyrights information.
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens *The definition of the #CRParser class.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *Random notes:
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *CSS core syntax vs CSS level 2 syntax
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *=====================================
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *One must keep in mind
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *that css UA must comply with two syntax.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *1/the specific syntax that defines the css language
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *for a given level of specificatin (e.g css2 syntax
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *defined in appendix D.1 of the css2 spec)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *2/the core (general) syntax that is there to allow
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy *UAs to parse style sheets written in levels of CSS that
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *didn't exist at the time the UAs were created.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy *the name of parsing functions (or methods) contained in this file
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *follows the following scheme: cr_parser_parse_<production_name> (...) ;
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *where <production_name> is the name
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *of a production of the css2 language.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *When a given production is
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *defined by the css2 level grammar *and* by the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *css core syntax, there will be two functions to parse that production:
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *one will parse the production defined by the css2 level grammar and the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *other will parse the production defined by the css core grammar.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *The css2 level grammar related parsing function will be called:
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy *cr_parser_parse_<production_name> (...) ;
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *Then css core grammar related parsing function will be called:
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy *cr_parser_parse_<production_name>_core (...) ;
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *If a production is defined only by the css core grammar, then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *it will be named:
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *cr_parser_parse_<production_name>_core (...) ;
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedytypedef struct _CRParserError CRParserError;
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *An abstraction of an error reported by by the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy *parsing routines.
struct _CRParserPriv {
goto error ; \
goto error ; \
a_offset, \
a_byte_ptr) ; \
if (! (a_condition)) \
goto error ; \
a_token_ptr) ; \
enum CRStatus);
static enum CRStatus
static CRParserError *
return NULL;
return result;
static enum CRStatus
goto error;
return CR_OK;
if (error) {
return status;
static enum CRStatus
return CR_OK;
return CR_OK;
static enum CRStatus
return CR_OK;
enum CRStatus
if (token) {
&token);
goto error;
return status;
if (token) {
return status;
static enum CRStatus
if (token) {
goto done;
goto error;
case CDO_TK:
case CDC_TK:
goto continue_parsing;
token);
goto continue_parsing;
goto done;
goto error;
done:
if (token) {
return CR_OK;
if (token) {
return status;
static enum CRStatus
&token);
&& token
&token);
token);
FALSE);
goto done;
goto done;
goto error;
done:
if (token) {
return CR_OK;
if (token) {
&init_pos);
return status;
static enum CRStatus
if (token) {
goto done;
goto done;
token);
goto parse_declaration_list;
done:
if (token) {
return CR_OK;
if (token) {
return status;
static enum CRStatus
return CR_OK;
if (token) {
return status;
static enum CRStatus
if (token) {
goto done;
goto parse_block_content;
goto parse_block_content;
goto parse_block_content;
goto parse_block_content;
done:
if (token) {
return CR_OK;
if (token) {
return status;
static enum CRStatus
&& token
return CR_OK;
if (prop) {
if (token) {
return status;
static enum CRStatus
if (token) {
case CBO_TK:
token);
ref++;
goto continue_parsing;
case ATKEYWORD_TK:
ref++;
goto continue_parsing;
token);
ref++;
goto continue_parsing;
goto done;
goto error;
done:
if (token) {
return CR_OK;
if (token) {
return status;
static enum CRStatus
case IDENT_TK:
case NUMBER_TK:
case RGB_TK:
case PERCENTAGE_TK:
case DIMEN_TK:
case EMS_TK:
case EXS_TK:
case LENGTH_TK:
case ANGLE_TK:
case FREQ_TK:
case TIME_TK:
case STRING_TK:
case DELIM_TK:
case URI_TK:
case HASH_TK:
case UNICODERANGE_TK:
case INCLUDES_TK:
case DASHMATCH_TK:
case S_TK:
case COMMENT_TK:
case IMPORTANT_SYM_TK:
case FUNCTION_TK:
&token2);
case PO_TK:
&token2);
goto done;
&token2);
case BO_TK:
&token2);
goto done;
&token2);
goto error;
done:
if (token1) {
if (token2) {
return CR_OK;
if (token1) {
if (token2) {
return status;
static enum CRStatus
if (!result) {
goto error ;
&location) ;
goto parse_right_part;
goto parse_right_part;
goto parse_right_part;
goto done;
if (token) {
goto error;
if (token) {
done:
if (token) {
if (*a_sel) {
return CR_OK;
if (result) {
if (token) {
return status;
static enum CRStatus
&& a_property,
return CR_OK;
return status;
enum CRStatus
&token);
goto error;
&token);
goto error;
&token);
goto error;
token);
¶m);
param);
goto error;
&location) ;
if (token) {
return CR_OK;
if (result) {
if (token) {
if (param) {
if (func_name) {
return status;
static enum CRStatus
goto error;
token);
if (token) {
if (token) {
&token);
goto error;
goto error;
goto error;
goto error;
if (token) {
(a_this);
goto error;
if (token) {
return CR_OK;
if (token) {
if (add_sel_list) {
if (sel) {
return status;
static enum CRStatus
&& a_sel,
int comb = 0;
comb = 0;
if (sel) {
sel) ;
return CR_OK;
return status;
static enum CRStatus
next_char = 0;
if (simple_sels) {
if (selector) {
goto error ;
&next_char);
goto okay;
goto error;
&next_char);
goto error;
if (simple_sels) {
selector =
okay:
if (!*a_selector) {
return CR_OK;
if (simple_sels) {
if (selector) {
return status;
static enum CRStatus
&& a_func_name,
goto error;
goto error;
goto error;
if (expr) {
return CR_OK;
if (*a_func_name) {
if (expr) {
if (token) {
return status;
static enum CRStatus
return status;
static enum CRStatus
return status;
static enum CRStatus
return status;
static enum CRStatus
goto done;
token);
&charset,
&location);
if (charset) {
} else if (token
token);
goto parse_charset ;
} else if (token) {
token);
if (token) {
goto done;
} while (token
if (token) {
token);
goto done;
&location);
if (import_string
goto error ;
if (media_list) {
if (import_string) {
} else if (token
if (token) {
goto done;
} while (token
if (token) {
goto parse_ruleset_and_others;
goto done;
if (token
if (token) {
(a_this);
} while (token
if (token) {
} else if (token
(a_this);
done:
if (token) {
return CR_OK;
return status;
if (token) {
return status;
CRParser *
if (a_tknzr) {
return result;
CRParser *
if (!result) {
return NULL;
return result;
CRParser *
if (a_input) {
return result;
CRParser *
if (!tokenizer) {
return NULL;
return result;
enum CRStatus
return CR_OK;
enum CRStatus
return CR_OK;
enum CRStatus
return status;
enum CRStatus
return CR_OK;
enum CRStatus
return CR_OK;
enum CRStatus
return status;
enum CRStatus
goto error;
switch (operatr) {
operatr = 0;
nb_terms++;
return CR_OK;
if (expr) {
if (expr2) {
return status;
enum CRStatus
&& a_prio
goto error;
return CR_OK;
if (token) {
return status;
enum CRStatus
goto error;
(a_this,
goto error;
if (prio) {
if (*a_expr) {
return CR_OK;
if (expr) {
if (*a_property) {
return status;
enum CRStatus
case ATKEYWORD_TK:
case IMPORT_SYM_TK:
case PAGE_SYM_TK:
case MEDIA_SYM_TK:
case FONT_FACE_SYM_TK:
case CHARSET_SYM_TK:
return CR_OK;
if (token) {
return status;
enum CRStatus
next_char = 0;
if (selector) {
&expr,
&is_important);
if (expr) {
if (property) {
if (expr) {
guint32 c = 0 ;
goto end_of_ruleset ;
if (expr) {
if (property) {
if (expr) {
if (expr) {
if (simple_sels) {
if (selector) {
return CR_OK;
if (expr) {
if (simple_sels) {
if (property) {
if (selector) {
return status;
enum CRStatus
next_char = 0;
if (a_location) {
goto error;
goto okay;
goto error;
okay:
return CR_OK;
if (*a_media_list) {
if (*a_import_string) {
if (medium) {
return status;
enum CRStatus
cur_char = 0;
&token);
&& token
if (medium) {
if (medium) {
&location);
if (medium) {
if (media_list) {
return CR_OK;
if (token) {
if (medium) {
if (media_list) {
return status;
enum CRStatus
&token) ;
&& token
&location);
&important);
if (css_expression)
if (property) {
if (css_expression) {
if (token) {
token);
&important);
if (property) {
if (css_expression) {
(a_this) ;
if (token) {
&& token
if (page_selector) {
if (page_pseudo_class) {
return CR_OK;
if (token) {
if (page_selector) {
if (page_pseudo_class) {
if (property) {
if (css_expression) {
return status;
enum CRStatus
if (a_charset_sym_location) {
if (charset_str) {
return CR_OK;
if (token) {
if (*a_value) {
if (charset_str) {
return status;
enum CRStatus
cur_char = 0;
&& token
if (token) {
&token);
if (token) {
if (property) {
if (css_expression) {
&property,
&important);
if (property) {
if (css_expression) {
if (token) {
return CR_OK;
if (token) {
if (property) {
if (css_expression) {
return status;
enum CRStatus
return status;
enum CRStatus
if (a_tknzr)
return CR_OK;
enum CRStatus
return CR_OK;
enum CRStatus
enum CRStatus
return status;
if (a_this) {