2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2006-11-27 18:35:18 +03:00
|
|
|
* This file is part of NetSurf, http://netsurf-browser.org/
|
2003-06-30 16:44:03 +04:00
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2004-05-01 21:48:38 +04:00
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
2003-03-26 00:03:14 +03:00
|
|
|
*/
|
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
/** \file
|
|
|
|
* CSS tokeniser using re2c.
|
|
|
|
*
|
|
|
|
* see CSS2 Specification, chapter 4
|
|
|
|
* http://www.w3.org/TR/REC-CSS2/syndata.html,
|
|
|
|
* and errata
|
|
|
|
* http://www.w3.org/Style/css2-updates/REC-CSS2-19980512-errata
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#define CSS_INTERNALS
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "css/css.h"
|
|
|
|
#include "css/parser.h"
|
2004-05-01 21:48:38 +04:00
|
|
|
|
|
|
|
#define YYCTYPE unsigned char
|
|
|
|
#define YYCURSOR (*buffer)
|
|
|
|
#define YYLIMIT end
|
|
|
|
#define YYMARKER marker
|
|
|
|
#define YYFILL(n) { return 0; }
|
2003-03-26 00:03:14 +03:00
|
|
|
|
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
/**
|
|
|
|
* Identify a CSS source token.
|
|
|
|
*
|
|
|
|
* \param buffer source to tokenise, updated to new position
|
|
|
|
* \param end end of source
|
|
|
|
* \param token_text updated to start of recognized token
|
|
|
|
* \return token number
|
|
|
|
*/
|
|
|
|
|
|
|
|
int css_tokenise(unsigned char **buffer, unsigned char *end,
|
|
|
|
unsigned char **token_text)
|
|
|
|
{
|
|
|
|
unsigned char *marker;
|
2003-03-26 00:03:14 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
start:
|
|
|
|
*token_text = YYCURSOR;
|
2003-03-26 00:03:14 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
/*!re2c
|
|
|
|
nonascii = [\200-\377];
|
2005-01-05 23:20:32 +03:00
|
|
|
unicode = "\\" [0-9a-f]+ ("\r\n" | [ \n\r\t\f])?;
|
2004-05-01 21:48:38 +04:00
|
|
|
escape = unicode | "\\" [ -~\200-\377];
|
|
|
|
nmchar = [-a-zA-Z0-9_] | nonascii | escape;
|
|
|
|
nmstart = [a-zA-Z_] | nonascii | escape;
|
2005-01-05 23:20:32 +03:00
|
|
|
ident = [-]? nmstart nmchar*;
|
2004-05-01 21:48:38 +04:00
|
|
|
name = nmchar+;
|
2005-07-31 19:55:36 +04:00
|
|
|
num = [+-]? ([0-9]+ | [0-9]* "." [0-9]+);
|
2004-05-01 21:48:38 +04:00
|
|
|
nl = "\n" | "\r\n" | "\r" | "\f";
|
|
|
|
string1 = "\"" ([\t !#$%&(-~] | "\\" nl | "'" | nonascii | escape)* "\"";
|
|
|
|
string2 = "'" ([\t !#$%&(-~] | "\\" nl | "\""| nonascii | escape)* "'";
|
|
|
|
string = string1 | string2;
|
2005-01-05 23:20:32 +03:00
|
|
|
s = [ \t\r\n\f];
|
|
|
|
w = s*;
|
2004-05-01 21:48:38 +04:00
|
|
|
any = [\000-\377];
|
2003-03-26 00:03:14 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
ident { return IDENT; }
|
|
|
|
"@" ident { return ATKEYWORD; }
|
|
|
|
string { return STRING; }
|
|
|
|
"#" name { return HASH; }
|
2005-01-05 23:20:32 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
num { return NUMBER; }
|
|
|
|
num "%" { return PERCENTAGE; }
|
|
|
|
num ident { return DIMENSION; }
|
2005-01-05 23:20:32 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
"url(" w string w ")" | "url(" w ([!#$%&*-~]|nonascii|escape)* w ")"
|
|
|
|
{ return URI; }
|
|
|
|
"U+" [0-9A-F?]+ ("-" [0-9A-F]+ )?
|
|
|
|
{ return UNICODE_RANGE; }
|
2005-01-05 23:20:32 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
"<!--" { goto start; /* ignore CDO */ }
|
|
|
|
"-->" { goto start; /* ignore CDC */ }
|
2005-01-05 23:20:32 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
";" { return SEMI; }
|
|
|
|
"{" { return LBRACE; }
|
|
|
|
"}" { return RBRACE; }
|
|
|
|
"(" { return LPAREN; }
|
|
|
|
")" { return RPAREN; }
|
|
|
|
"[" { return LBRAC; }
|
|
|
|
"]" { return RBRAC; }
|
2005-01-05 23:20:32 +03:00
|
|
|
|
|
|
|
s+ { return S; }
|
|
|
|
|
|
|
|
"/*" (any\[*])* "*"+ ((any\[/*]) (any\[*])* "*"+)* "/"
|
2004-05-01 21:48:38 +04:00
|
|
|
{ goto start; /* ignore comments */ }
|
2005-01-05 23:20:32 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
ident "(" { return FUNCTION; }
|
2005-01-05 23:20:32 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
"~=" { return INCLUDES; }
|
2003-03-26 00:03:14 +03:00
|
|
|
"|=" { return DASHMATCH; }
|
2004-07-31 01:53:52 +04:00
|
|
|
"^=" { return PREFIX; }
|
|
|
|
"$=" { return SUFFIX; }
|
|
|
|
"*=" { return SUBSTR; }
|
2005-01-05 23:20:32 +03:00
|
|
|
|
|
|
|
"=" { return EQUALS; }
|
2004-05-01 21:48:38 +04:00
|
|
|
":" { return COLON; }
|
|
|
|
"," { return COMMA; }
|
2003-04-02 01:33:08 +04:00
|
|
|
"+" { return PLUS; }
|
2004-05-01 21:48:38 +04:00
|
|
|
">" { return GT; }
|
2003-04-02 01:33:08 +04:00
|
|
|
"." { return DOT; }
|
2004-03-30 01:27:52 +04:00
|
|
|
"*" { return ASTERISK; }
|
2005-01-05 23:20:32 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
any { return DELIM; }
|
|
|
|
*/
|
2003-03-26 00:03:14 +03:00
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
}
|