Commit 7ccb9db7 authored by Benjamin Otte's avatar Benjamin Otte

css: Rewrite the parser

Instead of relying on GScanner and its idea of syntax, code up a parser
that obeys the CSS spec.
This also has the great side effect of reporting correct line numbers
and positions.

Also included is a reorganization of the returned error values. Instead
of error values describing what type of syntax error was returned, the
code just returns SYNTAX_ERROR. Other messages exist for when actual
values don't work or when errors shouldn't be fatal due to backwards
compatibility.
parent 058bbb2a
......@@ -386,6 +386,7 @@ gtk_private_h_sources = \
gtkbuilderprivate.h \
gtkbuttonprivate.h \
gtkcellareaboxcontextprivate.h \
gtkcssparserprivate.h \
gtkcssproviderprivate.h \
gtkcssstringfuncsprivate.h \
gtkcustompaperunixdialog.h \
......@@ -512,6 +513,7 @@ gtk_base_c_sources = \
gtkcombobox.c \
gtkcomboboxtext.c \
gtkcontainer.c \
gtkcssparser.c \
gtkcssprovider.c \
gtkcssstringfuncs.c \
gtkdialog.c \
......
This diff is collapsed.
/* GTK - 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_CSS_PARSER_PRIVATE_H__
#define __GTK_CSS_PARSER_PRIVATE_H__
#include <gtk/gtksymboliccolor.h>
G_BEGIN_DECLS
typedef struct _GtkCssParser GtkCssParser;
typedef void (* GtkCssParserErrorFunc) (GtkCssParser *parser,
const GError *error,
gpointer user_data);
GtkCssParser * _gtk_css_parser_new (const char *data,
GtkCssParserErrorFunc error_func,
gpointer user_data);
void _gtk_css_parser_free (GtkCssParser *parser);
void _gtk_css_parser_error (GtkCssParser *parser,
const char *format,
...) G_GNUC_PRINTF (2, 3);
guint _gtk_css_parser_get_line (GtkCssParser *parser);
guint _gtk_css_parser_get_position (GtkCssParser *parser);
gboolean _gtk_css_parser_is_eof (GtkCssParser *parser);
gboolean _gtk_css_parser_begins_with (GtkCssParser *parser,
char c);
gboolean _gtk_css_parser_is_string (GtkCssParser *parser);
/* IMPORTANT:
* _try_foo() functions do not modify the data pointer if they fail, nor do they
* signal an error. _read_foo() will modify the data pointer and position it at
* the first token that is broken and emit an error about the failure.
* So only call _read_foo() when you know that you are reading a foo. _try_foo()
* however is fine to call if you don't know yet if the token is a foo or a bar,
* you can _try_bar() if try_foo() failed.
*/
gboolean _gtk_css_parser_try (GtkCssParser *parser,
const char *string,
gboolean skip_whitespace);
char * _gtk_css_parser_try_ident (GtkCssParser *parser,
gboolean skip_whitespace);
char * _gtk_css_parser_try_name (GtkCssParser *parser,
gboolean skip_whitespace);
gboolean _gtk_css_parser_try_int (GtkCssParser *parser,
int *value);
gboolean _gtk_css_parser_try_uint (GtkCssParser *parser,
uint *value);
gboolean _gtk_css_parser_try_double (GtkCssParser *parser,
gdouble *value);
void _gtk_css_parser_skip_whitespace (GtkCssParser *parser);
char * _gtk_css_parser_read_string (GtkCssParser *parser);
char * _gtk_css_parser_read_uri (GtkCssParser *parser);
char * _gtk_css_parser_read_value (GtkCssParser *parser);
GtkSymbolicColor *_gtk_css_parser_read_symbolic_color
(GtkCssParser *parser);
void _gtk_css_parser_resync (GtkCssParser *parser,
gboolean sync_at_semicolon,
char terminator);
G_END_DECLS
#endif /* __GTK_CSS_PARSER_PRIVATE_H__ */
This diff is collapsed.
......@@ -37,15 +37,9 @@ typedef enum
{
GTK_CSS_PROVIDER_ERROR_FAILED,
GTK_CSS_PROVIDER_ERROR_SYNTAX,
GTK_CSS_PROVIDER_ERROR_PROPERTY_NAME,
GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE,
GTK_CSS_PROVIDER_ERROR_SELECTOR,
GTK_CSS_PROVIDER_ERROR_COMBINATOR,
GTK_CSS_PROVIDER_ERROR_CLASS,
GTK_CSS_PROVIDER_ERROR_PSEUDO_CLASS,
GTK_CSS_PROVIDER_ERROR_AT_RULE,
GTK_CSS_PROVIDER_ERROR_IMPORT,
GTK_CSS_PROVIDER_ERROR_DEFINE_COLOR
GTK_CSS_PROVIDER_ERROR_NAME,
GTK_CSS_PROVIDER_ERROR_DEPRECATED
} GtkCssProviderError;
GQuark gtk_css_provider_error_quark (void);
......
This diff is collapsed.
......@@ -30,9 +30,6 @@ gboolean _gtk_css_value_from_string (GValue *value,
GError **error);
char * _gtk_css_value_to_string (const GValue *value);
GtkSymbolicColor * _gtk_css_parse_symbolic_color (const char *str,
GError **error);
GFile * _gtk_css_parse_url (GFile *base,
const char *str,
char **end,
......
boolean.css:26: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
boolean.css:29: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
boolean.css:32: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
boolean.css:35: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
boolean.css:38: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
boolean.css:41: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
boolean.css:44: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
boolean.css:47: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
boolean.css:26: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
boolean.css:29: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
boolean.css:32: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
boolean.css:35: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
boolean.css:38: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
boolean.css:41: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
boolean.css:44: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
boolean.css:47: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
border.css:26: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
border.css:30: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
border.css:34: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
border.css:38: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
border.css:42: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
border.css:46: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
border.css:50: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
border.css:54: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_NAME
border.css:26: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
border.css:30: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
border.css:34: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
border.css:38: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
border.css:42: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
border.css:46: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
border.css:50: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
border.css:54: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
does-not-exist.css:2: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_NAME
does-not-exist.css:2: error: GTK_CSS_PROVIDER_ERROR_NAME
integer.css:17: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
integer.css:20: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
integer.css:23: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
integer.css:29: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
integer.css:32: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
integer.css:17: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
integer.css:20: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
integer.css:23: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
integer.css:29: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
integer.css:32: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
integer.css:35: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
integer.css:38: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
integer.css:41: error: GTK_CSS_PROVIDER_ERROR_PROPERTY_VALUE
integer.css:38: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
integer.css:41: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment