summaryrefslogtreecommitdiff
path: root/pango/css/gtkcssparserprivate.h
blob: 5659fe0c45f03d6e46bfa54b905ea223f5df2b76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * Copyright © 2019 Benjamin Otte
 *
 * 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.1 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/>.
 *
 * Authors: Benjamin Otte <otte@gnome.org>
 */


#ifndef __GTK_CSS_PARSER_H__
#define __GTK_CSS_PARSER_H__

#include "gtkcssenums.h"
#include "gtkcsstokenizerprivate.h"

#include <gio/gio.h>

G_BEGIN_DECLS

typedef struct _GtkCssParser GtkCssParser;

typedef struct _GtkCssParseOption GtkCssParseOption;

struct _GtkCssParseOption
{
  gboolean (* can_parse)  (GtkCssParser *parser,
                           gpointer      option_data,
                           gpointer      user_data);
  gboolean (* parse)      (GtkCssParser *parser,
                           gpointer      option_data,
                           gpointer      user_data);
  gpointer data;
};

typedef void            (* GtkCssParserErrorFunc)               (GtkCssParser                   *parser,
                                                                 const GtkCssLocation           *start,
                                                                 const GtkCssLocation           *end,
                                                                 const GError                   *error,
                                                                 gpointer                        user_data);

GtkCssParser *          gtk_css_parser_new_for_file             (GFile                          *file,
                                                                 GtkCssParserErrorFunc           error_func,
                                                                 gpointer                        user_data,
                                                                 GDestroyNotify                  user_destroy,
                                                                 GError                        **error);
GtkCssParser *          gtk_css_parser_new_for_bytes            (GBytes                         *bytes,
                                                                 GFile                          *file,
                                                                 GtkCssParserErrorFunc           error_func,
                                                                 gpointer                        user_data,
                                                                 GDestroyNotify                  user_destroy);
GtkCssParser *          gtk_css_parser_ref                      (GtkCssParser                   *self);
void                    gtk_css_parser_unref                    (GtkCssParser                   *self);

GFile *                 gtk_css_parser_get_file                 (GtkCssParser                   *self) G_GNUC_PURE;
GFile *                 gtk_css_parser_resolve_url              (GtkCssParser                   *self,
                                                                 const char                     *url);

const GtkCssLocation *  gtk_css_parser_get_start_location       (GtkCssParser                   *self) G_GNUC_PURE;
const GtkCssLocation *  gtk_css_parser_get_end_location         (GtkCssParser                   *self) G_GNUC_PURE;
const GtkCssLocation *  gtk_css_parser_get_block_location       (GtkCssParser                   *self) G_GNUC_PURE;

const GtkCssToken *     gtk_css_parser_peek_token               (GtkCssParser                   *self);
const GtkCssToken *     gtk_css_parser_get_token                (GtkCssParser                   *self);
void                    gtk_css_parser_consume_token            (GtkCssParser                   *self);

void                    gtk_css_parser_start_block              (GtkCssParser                   *self); 
void                    gtk_css_parser_start_semicolon_block    (GtkCssParser                   *self,
                                                                 GtkCssTokenType                 alternative_token);
void                    gtk_css_parser_end_block_prelude        (GtkCssParser                   *self);
void                    gtk_css_parser_end_block                (GtkCssParser                   *self); 
void                    gtk_css_parser_skip                     (GtkCssParser                   *self);
void                    gtk_css_parser_skip_until               (GtkCssParser                   *self,
                                                                 GtkCssTokenType                 token_type);

void                    gtk_css_parser_emit_error               (GtkCssParser                   *self,
                                                                 const GtkCssLocation           *start,
                                                                 const GtkCssLocation           *end,
                                                                 const GError                   *error);
void                    gtk_css_parser_error                    (GtkCssParser                   *self,
                                                                 GtkCssParserError               code,
                                                                 const GtkCssLocation           *start,
                                                                 const GtkCssLocation           *end,
                                                                 const char                     *format,
                                                                 ...) G_GNUC_PRINTF(5, 6);
void                    gtk_css_parser_error_syntax             (GtkCssParser                   *self,
                                                                 const char                     *format,
                                                                 ...) G_GNUC_PRINTF(2, 3);
void                    gtk_css_parser_error_value              (GtkCssParser                   *self,
                                                                 const char                     *format,
                                                                 ...) G_GNUC_PRINTF(2, 3);
void                    gtk_css_parser_error_import             (GtkCssParser                   *self,
                                                                 const char                     *format,
                                                                 ...) G_GNUC_PRINTF(2, 3);
void                    gtk_css_parser_warn                     (GtkCssParser                   *self,
                                                                 GtkCssParserWarning             code,
                                                                 const GtkCssLocation           *start,
                                                                 const GtkCssLocation           *end,
                                                                 const char                     *format,
                                                                 ...) G_GNUC_PRINTF(5, 6);
void                    gtk_css_parser_warn_syntax              (GtkCssParser                   *self,
                                                                 const char                     *format,
                                                                 ...) G_GNUC_PRINTF(2, 3);


gboolean                gtk_css_parser_has_token                (GtkCssParser                   *self,
                                                                 GtkCssTokenType                 token_type);
gboolean                gtk_css_parser_has_ident                (GtkCssParser                   *self,
                                                                 const char                     *ident);
gboolean                gtk_css_parser_has_number               (GtkCssParser                   *self);
gboolean                gtk_css_parser_has_integer              (GtkCssParser                   *self);
gboolean                gtk_css_parser_has_function             (GtkCssParser                   *self,
                                                                 const char                     *name);

gboolean                gtk_css_parser_try_delim                (GtkCssParser                   *self,
                                                                 gunichar                        codepoint);
gboolean                gtk_css_parser_try_ident                (GtkCssParser                   *self,
                                                                 const char                     *ident);
gboolean                gtk_css_parser_try_at_keyword           (GtkCssParser                   *self,
                                                                 const char                     *keyword);
gboolean                gtk_css_parser_try_token                (GtkCssParser                   *self,
                                                                 GtkCssTokenType                 token_type);

char *                  gtk_css_parser_consume_ident            (GtkCssParser                   *self) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
char *                  gtk_css_parser_consume_string           (GtkCssParser                   *self) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
char *                  gtk_css_parser_consume_url              (GtkCssParser                   *self) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
gboolean                gtk_css_parser_consume_number           (GtkCssParser                   *self,
                                                                 double                         *number);
gboolean                gtk_css_parser_consume_integer          (GtkCssParser                   *self,
                                                                 int                            *number);
gboolean                gtk_css_parser_consume_percentage       (GtkCssParser                   *self,
                                                                 double                         *number);
gboolean                gtk_css_parser_consume_function         (GtkCssParser                   *self,
                                                                 guint                           min_args,
                                                                 guint                           max_args,
                                                                 guint (* parse_func) (GtkCssParser *, guint, gpointer),
                                                                 gpointer                        data);
gsize                   gtk_css_parser_consume_any              (GtkCssParser                   *parser,
                                                                 const GtkCssParseOption        *options,
                                                                 gsize                           n_options,
                                                                 gpointer                        user_data);

G_END_DECLS

#endif /* __GTK_CSS_PARSER_H__ */