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 | |
29 | G_BEGIN_DECLS |
30 | |
31 | typedef struct _GtkCssParser GtkCssParser; |
32 | |
33 | typedef struct _GtkCssParseOption GtkCssParseOption; |
34 | |
35 | struct _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 | |
46 | typedef void (* GtkCssParserErrorFunc) (GtkCssParser *parser, |
47 | const GtkCssLocation *start, |
48 | const GtkCssLocation *end, |
49 | const GError *error, |
50 | gpointer user_data); |
51 | |
52 | GtkCssParser * gtk_css_parser_new_for_file (GFile *file, |
53 | GtkCssParserErrorFunc error_func, |
54 | gpointer user_data, |
55 | GDestroyNotify user_destroy, |
56 | GError **error); |
57 | GtkCssParser * gtk_css_parser_new_for_bytes (GBytes *bytes, |
58 | GFile *file, |
59 | GtkCssParserErrorFunc error_func, |
60 | gpointer user_data, |
61 | GDestroyNotify user_destroy); |
62 | GtkCssParser * gtk_css_parser_ref (GtkCssParser *self); |
63 | void gtk_css_parser_unref (GtkCssParser *self); |
64 | |
65 | GFile * gtk_css_parser_get_file (GtkCssParser *self) G_GNUC_PURE; |
66 | GFile * gtk_css_parser_resolve_url (GtkCssParser *self, |
67 | const char *url); |
68 | |
69 | const GtkCssLocation * gtk_css_parser_get_start_location (GtkCssParser *self) G_GNUC_PURE; |
70 | const GtkCssLocation * gtk_css_parser_get_end_location (GtkCssParser *self) G_GNUC_PURE; |
71 | const GtkCssLocation * gtk_css_parser_get_block_location (GtkCssParser *self) G_GNUC_PURE; |
72 | |
73 | const GtkCssToken * gtk_css_parser_peek_token (GtkCssParser *self); |
74 | const GtkCssToken * gtk_css_parser_get_token (GtkCssParser *self); |
75 | void gtk_css_parser_consume_token (GtkCssParser *self); |
76 | |
77 | void gtk_css_parser_start_block (GtkCssParser *self); |
78 | void gtk_css_parser_start_semicolon_block (GtkCssParser *self, |
79 | GtkCssTokenType alternative_token); |
80 | void gtk_css_parser_end_block_prelude (GtkCssParser *self); |
81 | void gtk_css_parser_end_block (GtkCssParser *self); |
82 | void gtk_css_parser_skip (GtkCssParser *self); |
83 | void gtk_css_parser_skip_until (GtkCssParser *self, |
84 | GtkCssTokenType token_type); |
85 | |
86 | void gtk_css_parser_emit_error (GtkCssParser *self, |
87 | const GtkCssLocation *start, |
88 | const GtkCssLocation *end, |
89 | const GError *error); |
90 | void 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); |
96 | void gtk_css_parser_error_syntax (GtkCssParser *self, |
97 | const char *format, |
98 | ...) G_GNUC_PRINTF(2, 3); |
99 | void gtk_css_parser_error_value (GtkCssParser *self, |
100 | const char *format, |
101 | ...) G_GNUC_PRINTF(2, 3); |
102 | void gtk_css_parser_error_import (GtkCssParser *self, |
103 | const char *format, |
104 | ...) G_GNUC_PRINTF(2, 3); |
105 | void 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); |
111 | void gtk_css_parser_warn_syntax (GtkCssParser *self, |
112 | const char *format, |
113 | ...) G_GNUC_PRINTF(2, 3); |
114 | |
115 | |
116 | gboolean gtk_css_parser_has_token (GtkCssParser *self, |
117 | GtkCssTokenType token_type); |
118 | gboolean gtk_css_parser_has_ident (GtkCssParser *self, |
119 | const char *ident); |
120 | gboolean gtk_css_parser_has_number (GtkCssParser *self); |
121 | gboolean gtk_css_parser_has_integer (GtkCssParser *self); |
122 | gboolean gtk_css_parser_has_function (GtkCssParser *self, |
123 | const char *name); |
124 | |
125 | gboolean gtk_css_parser_try_delim (GtkCssParser *self, |
126 | gunichar codepoint); |
127 | gboolean gtk_css_parser_try_ident (GtkCssParser *self, |
128 | const char *ident); |
129 | gboolean gtk_css_parser_try_at_keyword (GtkCssParser *self, |
130 | const char *keyword); |
131 | gboolean gtk_css_parser_try_token (GtkCssParser *self, |
132 | GtkCssTokenType token_type); |
133 | |
134 | char * gtk_css_parser_consume_ident (GtkCssParser *self) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC; |
135 | char * gtk_css_parser_consume_string (GtkCssParser *self) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC; |
136 | char * gtk_css_parser_consume_url (GtkCssParser *self) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC; |
137 | gboolean gtk_css_parser_consume_number (GtkCssParser *self, |
138 | double *number); |
139 | gboolean gtk_css_parser_consume_integer (GtkCssParser *self, |
140 | int *number); |
141 | gboolean gtk_css_parser_consume_percentage (GtkCssParser *self, |
142 | double *number); |
143 | gboolean 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); |
148 | gsize gtk_css_parser_consume_any (GtkCssParser *parser, |
149 | const GtkCssParseOption *options, |
150 | gsize n_options, |
151 | gpointer user_data); |
152 | |
153 | G_END_DECLS |
154 | |
155 | #endif /* __GTK_CSS_PARSER_H__ */ |
156 | |