2016-03-04 17:40:11 +00:00
|
|
|
/* GSK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2011 Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcsstokenizerprivate.h"
|
|
|
|
|
|
|
|
#include "gtkcssenums.h"
|
|
|
|
#include "gtkcsserror.h"
|
2019-03-23 02:27:56 +00:00
|
|
|
#include "gtkcsslocationprivate.h"
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
struct _GtkCssTokenizer
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int ref_count;
|
2016-03-04 17:40:11 +00:00
|
|
|
GBytes *bytes;
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *data;
|
|
|
|
const char *end;
|
2019-03-15 03:00:21 +00:00
|
|
|
|
|
|
|
GtkCssLocation position;
|
2016-03-04 17:40:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_css_token_clear (GtkCssToken *token)
|
|
|
|
{
|
|
|
|
switch (token->type)
|
|
|
|
{
|
|
|
|
case GTK_CSS_TOKEN_STRING:
|
|
|
|
case GTK_CSS_TOKEN_IDENT:
|
|
|
|
case GTK_CSS_TOKEN_FUNCTION:
|
|
|
|
case GTK_CSS_TOKEN_AT_KEYWORD:
|
|
|
|
case GTK_CSS_TOKEN_HASH_UNRESTRICTED:
|
|
|
|
case GTK_CSS_TOKEN_HASH_ID:
|
|
|
|
case GTK_CSS_TOKEN_URL:
|
|
|
|
g_free (token->string.string);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
|
|
|
|
case GTK_CSS_TOKEN_DIMENSION:
|
|
|
|
g_free (token->dimension.dimension);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
case GTK_CSS_TOKEN_EOF:
|
|
|
|
case GTK_CSS_TOKEN_WHITESPACE:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_PARENS:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_PARENS:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_SQUARE:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_SQUARE:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_CURLY:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_CURLY:
|
|
|
|
case GTK_CSS_TOKEN_COMMA:
|
|
|
|
case GTK_CSS_TOKEN_COLON:
|
|
|
|
case GTK_CSS_TOKEN_SEMICOLON:
|
|
|
|
case GTK_CSS_TOKEN_CDC:
|
|
|
|
case GTK_CSS_TOKEN_CDO:
|
|
|
|
case GTK_CSS_TOKEN_DELIM:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_NUMBER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_NUMBER:
|
|
|
|
case GTK_CSS_TOKEN_PERCENTAGE:
|
|
|
|
case GTK_CSS_TOKEN_INCLUDE_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_DASH_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_PREFIX_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_SUFFIX_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_SUBSTRING_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_COLUMN:
|
|
|
|
case GTK_CSS_TOKEN_BAD_STRING:
|
|
|
|
case GTK_CSS_TOKEN_BAD_URL:
|
|
|
|
case GTK_CSS_TOKEN_COMMENT:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
token->type = GTK_CSS_TOKEN_EOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_token_initv (GtkCssToken *token,
|
|
|
|
GtkCssTokenType type,
|
|
|
|
va_list args)
|
|
|
|
{
|
|
|
|
token->type = type;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GTK_CSS_TOKEN_STRING:
|
|
|
|
case GTK_CSS_TOKEN_IDENT:
|
|
|
|
case GTK_CSS_TOKEN_FUNCTION:
|
|
|
|
case GTK_CSS_TOKEN_AT_KEYWORD:
|
|
|
|
case GTK_CSS_TOKEN_HASH_UNRESTRICTED:
|
|
|
|
case GTK_CSS_TOKEN_HASH_ID:
|
|
|
|
case GTK_CSS_TOKEN_URL:
|
|
|
|
token->string.string = va_arg (args, char *);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_DELIM:
|
|
|
|
token->delim.delim = va_arg (args, gunichar);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_NUMBER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_NUMBER:
|
|
|
|
case GTK_CSS_TOKEN_PERCENTAGE:
|
|
|
|
token->number.number = va_arg (args, double);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
|
|
|
|
case GTK_CSS_TOKEN_DIMENSION:
|
|
|
|
token->dimension.value = va_arg (args, double);
|
|
|
|
token->dimension.dimension = va_arg (args, char *);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
case GTK_CSS_TOKEN_EOF:
|
|
|
|
case GTK_CSS_TOKEN_WHITESPACE:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_PARENS:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_PARENS:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_SQUARE:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_SQUARE:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_CURLY:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_CURLY:
|
|
|
|
case GTK_CSS_TOKEN_COMMA:
|
|
|
|
case GTK_CSS_TOKEN_COLON:
|
|
|
|
case GTK_CSS_TOKEN_SEMICOLON:
|
|
|
|
case GTK_CSS_TOKEN_CDC:
|
|
|
|
case GTK_CSS_TOKEN_CDO:
|
|
|
|
case GTK_CSS_TOKEN_INCLUDE_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_DASH_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_PREFIX_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_SUFFIX_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_SUBSTRING_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_COLUMN:
|
|
|
|
case GTK_CSS_TOKEN_BAD_STRING:
|
|
|
|
case GTK_CSS_TOKEN_BAD_URL:
|
|
|
|
case GTK_CSS_TOKEN_COMMENT:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
append_ident (GString *string,
|
|
|
|
const char *ident)
|
|
|
|
{
|
|
|
|
/* XXX */
|
|
|
|
g_string_append (string, ident);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
append_string (GString *string,
|
|
|
|
const char *s)
|
|
|
|
{
|
|
|
|
g_string_append_c (string, '"');
|
|
|
|
/* XXX */
|
|
|
|
g_string_append (string, s);
|
|
|
|
g_string_append_c (string, '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gtk_css_token_is_finite:
|
|
|
|
* @token: a #GtkCssToken
|
|
|
|
*
|
|
|
|
* A token is considered finite when it would stay the same no matter
|
|
|
|
* what bytes follow it in the data stream.
|
|
|
|
*
|
|
|
|
* An obvious example for this is the ';' token.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the token is considered finite.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_css_token_is_finite (const GtkCssToken *token)
|
|
|
|
{
|
|
|
|
switch (token->type)
|
|
|
|
{
|
|
|
|
case GTK_CSS_TOKEN_EOF:
|
|
|
|
case GTK_CSS_TOKEN_STRING:
|
|
|
|
case GTK_CSS_TOKEN_FUNCTION:
|
|
|
|
case GTK_CSS_TOKEN_URL:
|
|
|
|
case GTK_CSS_TOKEN_PERCENTAGE:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_PARENS:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_PARENS:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_SQUARE:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_SQUARE:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_CURLY:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_CURLY:
|
|
|
|
case GTK_CSS_TOKEN_COMMA:
|
|
|
|
case GTK_CSS_TOKEN_COLON:
|
|
|
|
case GTK_CSS_TOKEN_SEMICOLON:
|
|
|
|
case GTK_CSS_TOKEN_CDC:
|
|
|
|
case GTK_CSS_TOKEN_CDO:
|
|
|
|
case GTK_CSS_TOKEN_INCLUDE_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_DASH_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_PREFIX_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_SUFFIX_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_SUBSTRING_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_COLUMN:
|
|
|
|
case GTK_CSS_TOKEN_COMMENT:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
case GTK_CSS_TOKEN_WHITESPACE:
|
|
|
|
case GTK_CSS_TOKEN_IDENT:
|
|
|
|
case GTK_CSS_TOKEN_AT_KEYWORD:
|
|
|
|
case GTK_CSS_TOKEN_HASH_UNRESTRICTED:
|
|
|
|
case GTK_CSS_TOKEN_HASH_ID:
|
|
|
|
case GTK_CSS_TOKEN_DELIM:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_NUMBER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_NUMBER:
|
|
|
|
case GTK_CSS_TOKEN_BAD_STRING:
|
|
|
|
case GTK_CSS_TOKEN_BAD_URL:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
|
|
|
|
case GTK_CSS_TOKEN_DIMENSION:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 04:32:05 +00:00
|
|
|
/*
|
|
|
|
* gtk_css_token_is_preserved:
|
|
|
|
* @token: a #GtkCssToken
|
|
|
|
* @out_closing: (allow-none): Type of the token that closes a block
|
|
|
|
* started with this token
|
|
|
|
*
|
|
|
|
* A token is considered preserved when it does not start a block.
|
|
|
|
*
|
|
|
|
* Tokens that start a block require different error recovery when parsing,
|
|
|
|
* so CSS parsers want to look at this function
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the token is considered preserved.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_css_token_is_preserved (const GtkCssToken *token,
|
|
|
|
GtkCssTokenType *out_closing)
|
|
|
|
{
|
|
|
|
switch (token->type)
|
|
|
|
{
|
|
|
|
case GTK_CSS_TOKEN_FUNCTION:
|
|
|
|
case GTK_CSS_TOKEN_OPEN_PARENS:
|
|
|
|
if (out_closing)
|
|
|
|
*out_closing = GTK_CSS_TOKEN_CLOSE_PARENS;
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_OPEN_SQUARE:
|
|
|
|
if (out_closing)
|
|
|
|
*out_closing = GTK_CSS_TOKEN_CLOSE_SQUARE;
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_OPEN_CURLY:
|
|
|
|
if (out_closing)
|
|
|
|
*out_closing = GTK_CSS_TOKEN_CLOSE_CURLY;
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
case GTK_CSS_TOKEN_EOF:
|
|
|
|
case GTK_CSS_TOKEN_WHITESPACE:
|
|
|
|
case GTK_CSS_TOKEN_STRING:
|
|
|
|
case GTK_CSS_TOKEN_URL:
|
|
|
|
case GTK_CSS_TOKEN_PERCENTAGE:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_PARENS:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_SQUARE:
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_CURLY:
|
|
|
|
case GTK_CSS_TOKEN_COMMA:
|
|
|
|
case GTK_CSS_TOKEN_COLON:
|
|
|
|
case GTK_CSS_TOKEN_SEMICOLON:
|
|
|
|
case GTK_CSS_TOKEN_CDC:
|
|
|
|
case GTK_CSS_TOKEN_CDO:
|
|
|
|
case GTK_CSS_TOKEN_INCLUDE_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_DASH_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_PREFIX_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_SUFFIX_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_SUBSTRING_MATCH:
|
|
|
|
case GTK_CSS_TOKEN_COLUMN:
|
|
|
|
case GTK_CSS_TOKEN_COMMENT:
|
|
|
|
case GTK_CSS_TOKEN_IDENT:
|
|
|
|
case GTK_CSS_TOKEN_AT_KEYWORD:
|
|
|
|
case GTK_CSS_TOKEN_HASH_UNRESTRICTED:
|
|
|
|
case GTK_CSS_TOKEN_HASH_ID:
|
|
|
|
case GTK_CSS_TOKEN_DELIM:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_NUMBER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_NUMBER:
|
|
|
|
case GTK_CSS_TOKEN_BAD_STRING:
|
|
|
|
case GTK_CSS_TOKEN_BAD_URL:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
|
|
|
|
case GTK_CSS_TOKEN_DIMENSION:
|
|
|
|
if (out_closing)
|
|
|
|
*out_closing = GTK_CSS_TOKEN_EOF;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 17:40:11 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_token_is_ident (const GtkCssToken *token,
|
|
|
|
const char *ident)
|
|
|
|
{
|
|
|
|
return gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT)
|
|
|
|
&& (g_ascii_strcasecmp (token->string.string, ident) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_css_token_is_function (const GtkCssToken *token,
|
|
|
|
const char *ident)
|
|
|
|
{
|
|
|
|
return gtk_css_token_is (token, GTK_CSS_TOKEN_FUNCTION)
|
|
|
|
&& (g_ascii_strcasecmp (token->string.string, ident) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_css_token_is_delim (const GtkCssToken *token,
|
|
|
|
gunichar delim)
|
|
|
|
{
|
|
|
|
return gtk_css_token_is (token, GTK_CSS_TOKEN_DELIM)
|
|
|
|
&& token->delim.delim == delim;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_css_token_print (const GtkCssToken *token,
|
|
|
|
GString *string)
|
|
|
|
{
|
|
|
|
char buf[G_ASCII_DTOSTR_BUF_SIZE];
|
|
|
|
|
|
|
|
switch (token->type)
|
|
|
|
{
|
|
|
|
case GTK_CSS_TOKEN_STRING:
|
|
|
|
append_string (string, token->string.string);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_IDENT:
|
|
|
|
append_ident (string, token->string.string);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_URL:
|
|
|
|
g_string_append (string, "url(");
|
|
|
|
append_ident (string, token->string.string);
|
|
|
|
g_string_append (string, ")");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_FUNCTION:
|
|
|
|
append_ident (string, token->string.string);
|
|
|
|
g_string_append_c (string, '(');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_AT_KEYWORD:
|
|
|
|
g_string_append_c (string, '@');
|
|
|
|
append_ident (string, token->string.string);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_HASH_UNRESTRICTED:
|
|
|
|
case GTK_CSS_TOKEN_HASH_ID:
|
|
|
|
g_string_append_c (string, '#');
|
|
|
|
append_ident (string, token->string.string);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_DELIM:
|
|
|
|
g_string_append_unichar (string, token->delim.delim);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_NUMBER:
|
|
|
|
if (token->number.number >= 0)
|
|
|
|
g_string_append_c (string, '+');
|
2020-03-06 07:32:21 +00:00
|
|
|
G_GNUC_FALLTHROUGH;
|
2016-03-04 17:40:11 +00:00
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER:
|
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_NUMBER:
|
|
|
|
g_ascii_dtostr (buf, G_ASCII_DTOSTR_BUF_SIZE, token->number.number);
|
|
|
|
g_string_append (string, buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_PERCENTAGE:
|
|
|
|
g_ascii_dtostr (buf, G_ASCII_DTOSTR_BUF_SIZE, token->number.number);
|
|
|
|
g_string_append (string, buf);
|
|
|
|
g_string_append_c (string, '%');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION:
|
|
|
|
if (token->dimension.value >= 0)
|
|
|
|
g_string_append_c (string, '+');
|
2020-03-06 07:32:21 +00:00
|
|
|
G_GNUC_FALLTHROUGH;
|
2016-03-04 17:40:11 +00:00
|
|
|
case GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION:
|
|
|
|
case GTK_CSS_TOKEN_DIMENSION:
|
2019-05-29 12:29:25 +00:00
|
|
|
g_ascii_dtostr (buf, G_ASCII_DTOSTR_BUF_SIZE, token->dimension.value);
|
2016-03-04 17:40:11 +00:00
|
|
|
g_string_append (string, buf);
|
|
|
|
append_ident (string, token->dimension.dimension);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_EOF:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_WHITESPACE:
|
|
|
|
g_string_append (string, " ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_OPEN_PARENS:
|
|
|
|
g_string_append (string, "(");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_PARENS:
|
|
|
|
g_string_append (string, ")");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_OPEN_SQUARE:
|
|
|
|
g_string_append (string, "[");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_SQUARE:
|
|
|
|
g_string_append (string, "]");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_OPEN_CURLY:
|
|
|
|
g_string_append (string, "{");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_CLOSE_CURLY:
|
|
|
|
g_string_append (string, "}");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_COMMA:
|
|
|
|
g_string_append (string, ",");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_COLON:
|
|
|
|
g_string_append (string, ":");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_SEMICOLON:
|
|
|
|
g_string_append (string, ";");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_CDO:
|
|
|
|
g_string_append (string, "<!--");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_CDC:
|
|
|
|
g_string_append (string, "-->");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_INCLUDE_MATCH:
|
|
|
|
g_string_append (string, "~=");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_DASH_MATCH:
|
|
|
|
g_string_append (string, "|=");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_PREFIX_MATCH:
|
|
|
|
g_string_append (string, "^=");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_SUFFIX_MATCH:
|
|
|
|
g_string_append (string, "$=");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_SUBSTRING_MATCH:
|
|
|
|
g_string_append (string, "*=");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_COLUMN:
|
|
|
|
g_string_append (string, "||");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_BAD_STRING:
|
|
|
|
g_string_append (string, "\"\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_BAD_URL:
|
|
|
|
g_string_append (string, "url(bad url)");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_CSS_TOKEN_COMMENT:
|
|
|
|
g_string_append (string, "/* comment */");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
gtk_css_token_to_string (const GtkCssToken *token)
|
|
|
|
{
|
|
|
|
GString *string;
|
|
|
|
|
|
|
|
string = g_string_new (NULL);
|
|
|
|
gtk_css_token_print (token, string);
|
|
|
|
return g_string_free (string, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_token_init (GtkCssToken *token,
|
|
|
|
GtkCssTokenType type,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, type);
|
|
|
|
gtk_css_token_initv (token, type, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssTokenizer *
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_new (GBytes *bytes)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
GtkCssTokenizer *tokenizer;
|
|
|
|
|
|
|
|
tokenizer = g_slice_new0 (GtkCssTokenizer);
|
|
|
|
tokenizer->ref_count = 1;
|
|
|
|
tokenizer->bytes = g_bytes_ref (bytes);
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
tokenizer->data = g_bytes_get_data (bytes, NULL);
|
|
|
|
tokenizer->end = tokenizer->data + g_bytes_get_size (bytes);
|
|
|
|
|
|
|
|
gtk_css_location_init (&tokenizer->position);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
return tokenizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssTokenizer *
|
|
|
|
gtk_css_tokenizer_ref (GtkCssTokenizer *tokenizer)
|
|
|
|
{
|
|
|
|
tokenizer->ref_count++;
|
|
|
|
|
|
|
|
return tokenizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_css_tokenizer_unref (GtkCssTokenizer *tokenizer)
|
|
|
|
{
|
|
|
|
tokenizer->ref_count--;
|
|
|
|
if (tokenizer->ref_count > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_bytes_unref (tokenizer->bytes);
|
|
|
|
g_slice_free (GtkCssTokenizer, tokenizer);
|
|
|
|
}
|
|
|
|
|
|
|
|
const GtkCssLocation *
|
|
|
|
gtk_css_tokenizer_get_location (GtkCssTokenizer *tokenizer)
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
return &tokenizer->position;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_parse_error (GError **error,
|
|
|
|
const char *format,
|
|
|
|
...) G_GNUC_PRINTF(2, 3);
|
2016-03-04 17:40:11 +00:00
|
|
|
static void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_parse_error (GError **error,
|
|
|
|
const char *format,
|
|
|
|
...)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
va_start (args, format);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
*error = g_error_new_valist (GTK_CSS_PARSER_ERROR,
|
|
|
|
GTK_CSS_PARSER_ERROR_SYNTAX,
|
|
|
|
format, args);
|
|
|
|
}
|
2016-03-04 17:40:11 +00:00
|
|
|
else
|
2019-03-15 03:00:21 +00:00
|
|
|
{
|
|
|
|
char *s = g_strdup_vprintf (format, args);
|
|
|
|
g_print ("error: %s\n", s);
|
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
va_end (args);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_newline (char c)
|
|
|
|
{
|
|
|
|
return c == '\n'
|
|
|
|
|| c == '\r'
|
|
|
|
|| c == '\f';
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_whitespace (char c)
|
|
|
|
{
|
|
|
|
return is_newline (c)
|
|
|
|
|| c == '\t'
|
|
|
|
|| c == ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_multibyte (char c)
|
|
|
|
{
|
|
|
|
return c & 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_name_start (char c)
|
|
|
|
{
|
|
|
|
return is_multibyte (c)
|
|
|
|
|| g_ascii_isalpha (c)
|
|
|
|
|| c == '_';
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_name (char c)
|
|
|
|
{
|
|
|
|
return is_name_start (c)
|
|
|
|
|| g_ascii_isdigit (c)
|
|
|
|
|| c == '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_non_printable (char c)
|
|
|
|
{
|
|
|
|
return (c >= 0 && c <= 0x08)
|
|
|
|
|| c == 0x0B
|
|
|
|
|| c == 0x0E
|
|
|
|
|| c == 0x1F
|
|
|
|
|| c == 0x7F;
|
|
|
|
}
|
|
|
|
|
2019-05-07 06:56:28 +00:00
|
|
|
static gboolean
|
|
|
|
is_valid_escape (const char *data,
|
|
|
|
const char *end)
|
|
|
|
{
|
|
|
|
switch (end - data)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
if (is_newline (data[1]))
|
|
|
|
return FALSE;
|
|
|
|
G_GNUC_FALLTHROUGH;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
return data[0] == '\\';
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 17:40:11 +00:00
|
|
|
static inline gsize
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_remaining (GtkCssTokenizer *tokenizer)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
return tokenizer->end - tokenizer->data;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_has_valid_escape (GtkCssTokenizer *tokenizer)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-05-07 06:56:28 +00:00
|
|
|
return is_valid_escape (tokenizer->data, tokenizer->end);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_has_identifier (GtkCssTokenizer *tokenizer)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
const char *data = tokenizer->data;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (data == tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (*data == '-')
|
|
|
|
{
|
|
|
|
data++;
|
2019-03-15 03:00:21 +00:00
|
|
|
if (data == tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
return FALSE;
|
|
|
|
if (*data == '-')
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_name_start (*data))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (*data == '\\')
|
|
|
|
{
|
|
|
|
data++;
|
2019-03-15 03:00:21 +00:00
|
|
|
if (data == tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
return TRUE; /* really? */
|
|
|
|
if (is_newline (*data))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_has_number (GtkCssTokenizer *tokenizer)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
const char *data = tokenizer->data;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (data == tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (*data == '-' || *data == '+')
|
|
|
|
{
|
|
|
|
data++;
|
2019-03-15 03:00:21 +00:00
|
|
|
if (data == tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*data == '.')
|
|
|
|
{
|
|
|
|
data++;
|
2019-03-15 03:00:21 +00:00
|
|
|
if (data == tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_ascii_isdigit (*data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_newline (GtkCssTokenizer *tokenizer)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gsize n;
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_remaining (tokenizer) > 1 &&
|
|
|
|
tokenizer->data[0] == '\r' && tokenizer->data[1] == '\n')
|
2016-03-04 17:40:11 +00:00
|
|
|
n = 2;
|
|
|
|
else
|
|
|
|
n = 1;
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
tokenizer->data += n;
|
|
|
|
gtk_css_location_advance_newline (&tokenizer->position, n == 2 ? TRUE : FALSE);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume (GtkCssTokenizer *tokenizer,
|
|
|
|
gsize n_bytes,
|
|
|
|
gsize n_characters)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
/* NB: must not contain newlines! */
|
2019-03-15 03:00:21 +00:00
|
|
|
tokenizer->data += n_bytes;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_location_advance (&tokenizer->position, n_bytes, n_characters);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (GtkCssTokenizer *tokenizer)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
/* NB: must not contain newlines! */
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume (tokenizer, 1, 1);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_whitespace (GtkCssTokenizer *tokenizer)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (is_newline (*tokenizer->data))
|
|
|
|
gtk_css_tokenizer_consume_newline (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
else
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_char (GtkCssTokenizer *tokenizer,
|
|
|
|
GString *string)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (is_newline (*tokenizer->data))
|
|
|
|
gtk_css_tokenizer_consume_newline (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gsize char_size = g_utf8_next_char (tokenizer->data) - tokenizer->data;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
if (string)
|
2019-03-15 03:00:21 +00:00
|
|
|
g_string_append_len (string, tokenizer->data, char_size);
|
|
|
|
gtk_css_tokenizer_consume (tokenizer, char_size, 1);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_whitespace (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
do {
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_whitespace (tokenizer);
|
|
|
|
} while (tokenizer->data != tokenizer->end &&
|
|
|
|
is_whitespace (*tokenizer->data));
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_WHITESPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gunichar
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_escape (GtkCssTokenizer *tokenizer)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gunichar value = 0;
|
|
|
|
guint i;
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume (tokenizer, 1, 1);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
for (i = 0; i < 6 && tokenizer->data < tokenizer->end && g_ascii_isxdigit (*tokenizer->data); i++)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
value = value * 16 + g_ascii_xdigit_value (*tokenizer->data);
|
|
|
|
gtk_css_tokenizer_consume (tokenizer, 1, 1);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
2019-03-15 03:00:21 +00:00
|
|
|
{
|
2019-05-07 06:56:28 +00:00
|
|
|
gsize remaining = gtk_css_tokenizer_remaining (tokenizer);
|
|
|
|
if (remaining == 0)
|
|
|
|
return 0xFFFD;
|
|
|
|
|
|
|
|
value = g_utf8_get_char_validated (tokenizer->data, remaining);
|
2019-03-15 03:00:21 +00:00
|
|
|
if (value == (gunichar) -1 || value == (gunichar) -2)
|
|
|
|
value = 0;
|
|
|
|
|
|
|
|
gtk_css_tokenizer_consume_char (tokenizer, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (is_whitespace (*tokenizer->data))
|
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
}
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (!g_unichar_validate (value) || g_unichar_type (value) == G_UNICODE_SURROGATE)
|
|
|
|
return 0xFFFD;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_name (GtkCssTokenizer *tokenizer)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
GString *string = g_string_new (NULL);
|
|
|
|
|
|
|
|
do {
|
2019-03-15 03:00:21 +00:00
|
|
|
if (*tokenizer->data == '\\')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_has_valid_escape (tokenizer))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gunichar value = gtk_css_tokenizer_read_escape (tokenizer);
|
|
|
|
g_string_append_unichar (string, value);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (tokenizer->data == tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
g_string_append_unichar (string, 0xFFFD);
|
|
|
|
break;
|
|
|
|
}
|
2019-11-19 08:37:45 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_char (tokenizer, string);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (is_name (*tokenizer->data))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_char (tokenizer, string);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
while (tokenizer->data != tokenizer->end);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
return g_string_free (string, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_bad_url (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
while (tokenizer->data < tokenizer->end && *tokenizer->data != ')')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_has_valid_escape (tokenizer))
|
|
|
|
gtk_css_tokenizer_read_escape (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
else
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_char (tokenizer, NULL);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (tokenizer->data < tokenizer->end)
|
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_BAD_URL);
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_tokenizer_read_url (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token,
|
|
|
|
GError **error)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
GString *url = g_string_new (NULL);
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
while (tokenizer->data < tokenizer->end && is_whitespace (*tokenizer->data))
|
|
|
|
gtk_css_tokenizer_consume_whitespace (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
while (tokenizer->data < tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (*tokenizer->data == ')')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (is_whitespace (*tokenizer->data))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
do
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_whitespace (tokenizer);
|
|
|
|
while (tokenizer->data < tokenizer->end && is_whitespace (*tokenizer->data));
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (*tokenizer->data == ')')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (tokenizer->data >= tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_bad_url (tokenizer, token);
|
|
|
|
gtk_css_tokenizer_parse_error (error, "Whitespace only allowed at start and end of url");
|
|
|
|
return FALSE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (is_non_printable (*tokenizer->data))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_bad_url (tokenizer, token);
|
2016-03-04 17:40:11 +00:00
|
|
|
g_string_free (url, TRUE);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_parse_error (error, "Nonprintable character 0x%02X in url", *tokenizer->data);
|
|
|
|
return FALSE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (*tokenizer->data == '"' ||
|
|
|
|
*tokenizer->data == '\'' ||
|
|
|
|
*tokenizer->data == '(')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_bad_url (tokenizer, token);
|
|
|
|
gtk_css_tokenizer_parse_error (error, "Invalid character %c in url", *tokenizer->data);
|
2016-03-04 17:40:11 +00:00
|
|
|
g_string_free (url, TRUE);
|
2019-03-15 03:00:21 +00:00
|
|
|
return FALSE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (gtk_css_tokenizer_has_valid_escape (tokenizer))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
g_string_append_unichar (url, gtk_css_tokenizer_read_escape (tokenizer));
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (*tokenizer->data == '\\')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_bad_url (tokenizer, token);
|
|
|
|
gtk_css_tokenizer_parse_error (error, "Newline may not follow '\' escape character");
|
2016-03-04 17:40:11 +00:00
|
|
|
g_string_free (url, TRUE);
|
2019-03-15 03:00:21 +00:00
|
|
|
return FALSE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_char (tokenizer, url);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_URL, g_string_free (url, FALSE));
|
2019-03-15 03:00:21 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_tokenizer_read_ident_like (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token,
|
|
|
|
GError **error)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
char *name = gtk_css_tokenizer_read_name (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (*tokenizer->data == '(')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
if (g_ascii_strcasecmp (name, "url") == 0)
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
const char *data = tokenizer->data;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
while (is_whitespace (*data))
|
|
|
|
data++;
|
|
|
|
|
|
|
|
if (*data != '"' && *data != '\'')
|
|
|
|
{
|
2019-11-19 08:37:45 +00:00
|
|
|
g_free (name);
|
2019-03-15 03:00:21 +00:00
|
|
|
return gtk_css_tokenizer_read_url (tokenizer, token, error);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-19 08:37:45 +00:00
|
|
|
|
2016-03-04 17:40:11 +00:00
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_FUNCTION, name);
|
2019-03-15 03:00:21 +00:00
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_IDENT, name);
|
2019-03-15 03:00:21 +00:00
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_numeric (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
int sign = 1, exponent_sign = 1;
|
|
|
|
gint64 integer, fractional = 0, fractional_length = 1, exponent = 0;
|
|
|
|
gboolean is_int = TRUE, has_sign = FALSE;
|
2019-03-15 03:00:21 +00:00
|
|
|
const char *data = tokenizer->data;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
if (*data == '-')
|
|
|
|
{
|
|
|
|
has_sign = TRUE;
|
|
|
|
sign = -1;
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
else if (*data == '+')
|
|
|
|
{
|
|
|
|
has_sign = TRUE;
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
for (integer = 0; data < tokenizer->end && g_ascii_isdigit (*data); data++)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
/* check for overflow here? */
|
|
|
|
integer = 10 * integer + g_ascii_digit_value (*data);
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (data + 1 < tokenizer->end && *data == '.' && g_ascii_isdigit (data[1]))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
is_int = FALSE;
|
|
|
|
data++;
|
|
|
|
|
|
|
|
fractional = g_ascii_digit_value (*data);
|
|
|
|
fractional_length = 10;
|
|
|
|
data++;
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
while (data < tokenizer->end && g_ascii_isdigit (*data))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
if (fractional_length < G_MAXINT64 / 10)
|
|
|
|
{
|
|
|
|
fractional = 10 * fractional + g_ascii_digit_value (*data);
|
|
|
|
fractional_length *= 10;
|
|
|
|
}
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-29 16:12:09 +00:00
|
|
|
if (data + 1 < tokenizer->end && (*data == 'e' || *data == 'E') &&
|
|
|
|
(g_ascii_isdigit (data[1]) ||
|
|
|
|
(data + 2 < tokenizer->end && (data[1] == '+' || data[1] == '-') && g_ascii_isdigit (data[2]))))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
is_int = FALSE;
|
|
|
|
data++;
|
|
|
|
|
|
|
|
if (*data == '-')
|
|
|
|
{
|
|
|
|
exponent_sign = -1;
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
else if (*data == '+')
|
|
|
|
{
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
while (data < tokenizer->end && g_ascii_isdigit (*data))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
exponent = 10 * exponent + g_ascii_digit_value (*data);
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume (tokenizer, data - tokenizer->data, data - tokenizer->data);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_has_identifier (tokenizer))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gtk_css_token_init (token,
|
|
|
|
is_int ? (has_sign ? GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION : GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION)
|
|
|
|
: GTK_CSS_TOKEN_DIMENSION,
|
|
|
|
sign * (integer + ((double) fractional / fractional_length)) * pow (10, exponent_sign * exponent),
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_name (tokenizer));
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (gtk_css_tokenizer_remaining (tokenizer) > 0 && *tokenizer->data == '%')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gtk_css_token_init (token,
|
|
|
|
GTK_CSS_TOKEN_PERCENTAGE,
|
|
|
|
sign * (integer + ((double) fractional / fractional_length)) * pow (10, exponent_sign * exponent));
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_css_token_init (token,
|
|
|
|
is_int ? (has_sign ? GTK_CSS_TOKEN_SIGNED_INTEGER : GTK_CSS_TOKEN_SIGNLESS_INTEGER)
|
|
|
|
: (has_sign ? GTK_CSS_TOKEN_SIGNED_NUMBER : GTK_CSS_TOKEN_SIGNLESS_NUMBER),
|
|
|
|
sign * (integer + ((double) fractional / fractional_length)) * pow (10, exponent_sign * exponent));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_delim (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_DELIM, g_utf8_get_char (tokenizer->data));
|
|
|
|
gtk_css_tokenizer_consume_char (tokenizer, NULL);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_tokenizer_read_dash (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token,
|
|
|
|
GError **error)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_remaining (tokenizer) == 1)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_delim (tokenizer, token);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (gtk_css_tokenizer_has_number (tokenizer))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_numeric (tokenizer, token);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (gtk_css_tokenizer_remaining (tokenizer) >= 3 &&
|
|
|
|
tokenizer->data[1] == '-' &&
|
|
|
|
tokenizer->data[2] == '>')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_CDC);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume (tokenizer, 3, 3);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (gtk_css_tokenizer_has_identifier (tokenizer))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
return gtk_css_tokenizer_read_ident_like (tokenizer, token, error);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_delim (tokenizer, token);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_tokenizer_read_string (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token,
|
|
|
|
GError **error)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
GString *string = g_string_new (NULL);
|
2019-03-15 03:00:21 +00:00
|
|
|
char end = *tokenizer->data;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
while (tokenizer->data < tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (*tokenizer->data == end)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (*tokenizer->data == '\\')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_remaining (tokenizer) == 1)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (is_newline (tokenizer->data[1]))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
gtk_css_tokenizer_consume_newline (tokenizer);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
g_string_append_unichar (string, gtk_css_tokenizer_read_escape (tokenizer));
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (is_newline (*tokenizer->data))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
g_string_free (string, TRUE);
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_BAD_STRING);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_parse_error (error, "Newlines inside strings must be escaped");
|
|
|
|
return FALSE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_char (tokenizer, string);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_STRING, g_string_free (string, FALSE));
|
2019-03-15 03:00:21 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_tokenizer_read_comment (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token,
|
|
|
|
GError **error)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume (tokenizer, 2, 2);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
while (tokenizer->data < tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_remaining (tokenizer) > 1 &&
|
|
|
|
tokenizer->data[0] == '*' && tokenizer->data[1] == '/')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume (tokenizer, 2, 2);
|
2016-03-04 17:40:11 +00:00
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_COMMENT);
|
2019-03-15 03:00:21 +00:00
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_char (tokenizer, NULL);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_COMMENT);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_parse_error (error, "Comment not terminated at end of document.");
|
|
|
|
return FALSE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_match (GtkCssTokenizer *tokenizer,
|
|
|
|
GtkCssToken *token,
|
|
|
|
GtkCssTokenType type)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_remaining (tokenizer) > 1 && tokenizer->data[1] == '=')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gtk_css_token_init (token, type);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume (tokenizer, 2, 2);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_delim (tokenizer, token);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
gboolean
|
2016-03-04 17:40:11 +00:00
|
|
|
gtk_css_tokenizer_read_token (GtkCssTokenizer *tokenizer,
|
2019-03-15 03:00:21 +00:00
|
|
|
GtkCssToken *token,
|
|
|
|
GError **error)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
if (tokenizer->data == tokenizer->end)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_EOF);
|
2019-03-15 03:00:21 +00:00
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (tokenizer->data[0] == '/' && gtk_css_tokenizer_remaining (tokenizer) > 1 &&
|
|
|
|
tokenizer->data[1] == '*')
|
|
|
|
return gtk_css_tokenizer_read_comment (tokenizer, token, error);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
switch (*tokenizer->data)
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
case '\t':
|
|
|
|
case '\f':
|
|
|
|
case ' ':
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_whitespace (tokenizer, token);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '"':
|
2019-03-15 03:00:21 +00:00
|
|
|
return gtk_css_tokenizer_read_string (tokenizer, token, error);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '#':
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
if (is_name (*tokenizer->data) || gtk_css_tokenizer_has_valid_escape (tokenizer))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
GtkCssTokenType type;
|
|
|
|
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_has_identifier (tokenizer))
|
2016-03-04 17:40:11 +00:00
|
|
|
type = GTK_CSS_TOKEN_HASH_ID;
|
|
|
|
else
|
|
|
|
type = GTK_CSS_TOKEN_HASH_UNRESTRICTED;
|
|
|
|
|
|
|
|
gtk_css_token_init (token,
|
|
|
|
type,
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_name (tokenizer));
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_DELIM, '#');
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '$':
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_match (tokenizer, token, GTK_CSS_TOKEN_SUFFIX_MATCH);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '\'':
|
2019-03-15 03:00:21 +00:00
|
|
|
return gtk_css_tokenizer_read_string (tokenizer, token, error);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '(':
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_OPEN_PARENS);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case ')':
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_CLOSE_PARENS);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '*':
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_match (tokenizer, token, GTK_CSS_TOKEN_SUBSTRING_MATCH);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '+':
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_has_number (tokenizer))
|
|
|
|
gtk_css_tokenizer_read_numeric (tokenizer, token);
|
2016-03-04 17:40:11 +00:00
|
|
|
else
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_delim (tokenizer, token);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case ',':
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_COMMA);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '-':
|
2019-03-15 03:00:21 +00:00
|
|
|
return gtk_css_tokenizer_read_dash (tokenizer, token, error);
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '.':
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_has_number (tokenizer))
|
|
|
|
gtk_css_tokenizer_read_numeric (tokenizer, token);
|
2016-03-04 17:40:11 +00:00
|
|
|
else
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_delim (tokenizer, token);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case ':':
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_COLON);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case ';':
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_SEMICOLON);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '<':
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_remaining (tokenizer) >= 4 &&
|
|
|
|
tokenizer->data[1] == '!' &&
|
|
|
|
tokenizer->data[2] == '-' &&
|
|
|
|
tokenizer->data[3] == '-')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_CDO);
|
2020-10-31 04:37:39 +00:00
|
|
|
gtk_css_tokenizer_consume (tokenizer, 4, 4);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_delim (tokenizer, token);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '@':
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
if (gtk_css_tokenizer_has_identifier (tokenizer))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gtk_css_token_init (token,
|
|
|
|
GTK_CSS_TOKEN_AT_KEYWORD,
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_name (tokenizer));
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_DELIM, '@');
|
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '[':
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_OPEN_SQUARE);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '\\':
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_has_valid_escape (tokenizer))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
return gtk_css_tokenizer_read_ident_like (tokenizer, token, error);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_DELIM, '\\');
|
2019-05-06 03:56:06 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_parse_error (error, "Newline may not follow '\' escape character");
|
|
|
|
return FALSE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case ']':
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_CLOSE_SQUARE);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '^':
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_match (tokenizer, token, GTK_CSS_TOKEN_PREFIX_MATCH);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '{':
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_OPEN_CURLY);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '}':
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_CLOSE_CURLY);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume_ascii (tokenizer);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '|':
|
2019-03-15 03:00:21 +00:00
|
|
|
if (gtk_css_tokenizer_remaining (tokenizer) > 1 && tokenizer->data[1] == '|')
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
|
|
|
gtk_css_token_init (token, GTK_CSS_TOKEN_COLUMN);
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_consume (tokenizer, 2, 2);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_match (tokenizer, token, GTK_CSS_TOKEN_DASH_MATCH);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
case '~':
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_match (tokenizer, token, GTK_CSS_TOKEN_INCLUDE_MATCH);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
|
|
|
|
default:
|
2019-03-15 03:00:21 +00:00
|
|
|
if (g_ascii_isdigit (*tokenizer->data))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
gtk_css_tokenizer_read_numeric (tokenizer, token);
|
|
|
|
return TRUE;
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
2019-03-15 03:00:21 +00:00
|
|
|
else if (is_name_start (*tokenizer->data))
|
2016-03-04 17:40:11 +00:00
|
|
|
{
|
2019-03-15 03:00:21 +00:00
|
|
|
return gtk_css_tokenizer_read_ident_like (tokenizer, token, error);
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
else
|
2019-03-15 03:00:21 +00:00
|
|
|
{
|
|
|
|
gtk_css_tokenizer_read_delim (tokenizer, token);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-03-04 17:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|