1/*
2 * Copyright © 2019 Benjamin Otte
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Benjamin Otte <otte@gnome.org>
18 */
19
20
21#ifndef __GTK_CSS_PARSER_H__
22#define __GTK_CSS_PARSER_H__
23
24#include "gtkcssenums.h"
25#include "gtkcsstokenizerprivate.h"
26
27#include <gio/gio.h>
28
29G_BEGIN_DECLS
30
31typedef struct _GtkCssParser GtkCssParser;
32
33typedef struct _GtkCssParseOption GtkCssParseOption;
34
35struct _GtkCssParseOption
36{
37 gboolean (* can_parse) (GtkCssParser *parser,
38 gpointer option_data,
39 gpointer user_data);
40 gboolean (* parse) (GtkCssParser *parser,
41 gpointer option_data,
42 gpointer user_data);
43 gpointer data;
44};
45
46typedef void (* GtkCssParserErrorFunc) (GtkCssParser *parser,
47 const GtkCssLocation *start,
48 const GtkCssLocation *end,
49 const GError *error,
50 gpointer user_data);
51
52GtkCssParser * gtk_css_parser_new_for_file (GFile *file,
53 GtkCssParserErrorFunc error_func,
54 gpointer user_data,
55 GDestroyNotify user_destroy,
56 GError **error);
57GtkCssParser * gtk_css_parser_new_for_bytes (GBytes *bytes,
58 GFile *file,
59 GtkCssParserErrorFunc error_func,
60 gpointer user_data,
61 GDestroyNotify user_destroy);
62GtkCssParser * gtk_css_parser_ref (GtkCssParser *self);
63void gtk_css_parser_unref (GtkCssParser *self);
64
65GFile * gtk_css_parser_get_file (GtkCssParser *self) G_GNUC_PURE;
66GFile * gtk_css_parser_resolve_url (GtkCssParser *self,
67 const char *url);
68
69const GtkCssLocation * gtk_css_parser_get_start_location (GtkCssParser *self) G_GNUC_PURE;
70const GtkCssLocation * gtk_css_parser_get_end_location (GtkCssParser *self) G_GNUC_PURE;
71const GtkCssLocation * gtk_css_parser_get_block_location (GtkCssParser *self) G_GNUC_PURE;
72
73const GtkCssToken * gtk_css_parser_peek_token (GtkCssParser *self);
74const GtkCssToken * gtk_css_parser_get_token (GtkCssParser *self);
75void gtk_css_parser_consume_token (GtkCssParser *self);
76
77void gtk_css_parser_start_block (GtkCssParser *self);
78void gtk_css_parser_start_semicolon_block (GtkCssParser *self,
79 GtkCssTokenType alternative_token);
80void gtk_css_parser_end_block_prelude (GtkCssParser *self);
81void gtk_css_parser_end_block (GtkCssParser *self);
82void gtk_css_parser_skip (GtkCssParser *self);
83void gtk_css_parser_skip_until (GtkCssParser *self,
84 GtkCssTokenType token_type);
85
86void gtk_css_parser_emit_error (GtkCssParser *self,
87 const GtkCssLocation *start,
88 const GtkCssLocation *end,
89 const GError *error);
90void gtk_css_parser_error (GtkCssParser *self,
91 GtkCssParserError code,
92 const GtkCssLocation *start,
93 const GtkCssLocation *end,
94 const char *format,
95 ...) G_GNUC_PRINTF(5, 6);
96void gtk_css_parser_error_syntax (GtkCssParser *self,
97 const char *format,
98 ...) G_GNUC_PRINTF(2, 3);
99void gtk_css_parser_error_value (GtkCssParser *self,
100 const char *format,
101 ...) G_GNUC_PRINTF(2, 3);
102void gtk_css_parser_error_import (GtkCssParser *self,
103 const char *format,
104 ...) G_GNUC_PRINTF(2, 3);
105void gtk_css_parser_warn (GtkCssParser *self,
106 GtkCssParserWarning code,
107 const GtkCssLocation *start,
108 const GtkCssLocation *end,
109 const char *format,
110 ...) G_GNUC_PRINTF(5, 6);
111void gtk_css_parser_warn_syntax (GtkCssParser *self,
112 const char *format,
113 ...) G_GNUC_PRINTF(2, 3);
114
115
116gboolean gtk_css_parser_has_token (GtkCssParser *self,
117 GtkCssTokenType token_type);
118gboolean gtk_css_parser_has_ident (GtkCssParser *self,
119 const char *ident);
120gboolean gtk_css_parser_has_number (GtkCssParser *self);
121gboolean gtk_css_parser_has_integer (GtkCssParser *self);
122gboolean gtk_css_parser_has_function (GtkCssParser *self,
123 const char *name);
124
125gboolean gtk_css_parser_try_delim (GtkCssParser *self,
126 gunichar codepoint);
127gboolean gtk_css_parser_try_ident (GtkCssParser *self,
128 const char *ident);
129gboolean gtk_css_parser_try_at_keyword (GtkCssParser *self,
130 const char *keyword);
131gboolean gtk_css_parser_try_token (GtkCssParser *self,
132 GtkCssTokenType token_type);
133
134char * gtk_css_parser_consume_ident (GtkCssParser *self) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
135char * gtk_css_parser_consume_string (GtkCssParser *self) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
136char * gtk_css_parser_consume_url (GtkCssParser *self) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
137gboolean gtk_css_parser_consume_number (GtkCssParser *self,
138 double *number);
139gboolean gtk_css_parser_consume_integer (GtkCssParser *self,
140 int *number);
141gboolean gtk_css_parser_consume_percentage (GtkCssParser *self,
142 double *number);
143gboolean gtk_css_parser_consume_function (GtkCssParser *self,
144 guint min_args,
145 guint max_args,
146 guint (* parse_func) (GtkCssParser *, guint, gpointer),
147 gpointer data);
148gsize gtk_css_parser_consume_any (GtkCssParser *parser,
149 const GtkCssParseOption *options,
150 gsize n_options,
151 gpointer user_data);
152
153G_END_DECLS
154
155#endif /* __GTK_CSS_PARSER_H__ */
156

source code of gtk/gtk/css/gtkcssparserprivate.h