summaryrefslogtreecommitdiff
path: root/gtk/css/gtkcsstokenizerprivate.h
blob: 279af1860e3f8b55908c02c852bca98d29f8380f (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
/* 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/>.
 */

#ifndef __GTK_CSS_TOKENIZER_PRIVATE_H__
#define __GTK_CSS_TOKENIZER_PRIVATE_H__

#include <glib.h>

#include <gtk/css/gtkcsslocation.h>

G_BEGIN_DECLS

typedef enum {
  /* no content */
  GTK_CSS_TOKEN_EOF,
  GTK_CSS_TOKEN_WHITESPACE,
  GTK_CSS_TOKEN_OPEN_PARENS,
  GTK_CSS_TOKEN_CLOSE_PARENS,
  GTK_CSS_TOKEN_OPEN_SQUARE,
  GTK_CSS_TOKEN_CLOSE_SQUARE,
  GTK_CSS_TOKEN_OPEN_CURLY,
  GTK_CSS_TOKEN_CLOSE_CURLY,
  GTK_CSS_TOKEN_COMMA,
  GTK_CSS_TOKEN_COLON,
  GTK_CSS_TOKEN_SEMICOLON,
  GTK_CSS_TOKEN_CDO,
  GTK_CSS_TOKEN_CDC,
  GTK_CSS_TOKEN_INCLUDE_MATCH,
  GTK_CSS_TOKEN_DASH_MATCH,
  GTK_CSS_TOKEN_PREFIX_MATCH,
  GTK_CSS_TOKEN_SUFFIX_MATCH,
  GTK_CSS_TOKEN_SUBSTRING_MATCH,
  GTK_CSS_TOKEN_COLUMN,
  GTK_CSS_TOKEN_BAD_STRING,
  GTK_CSS_TOKEN_BAD_URL,
  GTK_CSS_TOKEN_COMMENT,
  /* delim */
  GTK_CSS_TOKEN_DELIM,
  /* string */
  GTK_CSS_TOKEN_STRING,
  GTK_CSS_TOKEN_IDENT,
  GTK_CSS_TOKEN_FUNCTION,
  GTK_CSS_TOKEN_AT_KEYWORD,
  GTK_CSS_TOKEN_HASH_UNRESTRICTED,
  GTK_CSS_TOKEN_HASH_ID,
  GTK_CSS_TOKEN_URL,
  /* number */
  GTK_CSS_TOKEN_SIGNED_INTEGER,
  GTK_CSS_TOKEN_SIGNLESS_INTEGER,
  GTK_CSS_TOKEN_SIGNED_NUMBER,
  GTK_CSS_TOKEN_SIGNLESS_NUMBER,
  GTK_CSS_TOKEN_PERCENTAGE,
  /* dimension */
  GTK_CSS_TOKEN_SIGNED_INTEGER_DIMENSION,
  GTK_CSS_TOKEN_SIGNLESS_INTEGER_DIMENSION,
  GTK_CSS_TOKEN_DIMENSION
} GtkCssTokenType;

typedef union _GtkCssToken GtkCssToken;
typedef struct _GtkCssTokenizer GtkCssTokenizer;

typedef struct _GtkCssStringToken GtkCssStringToken;
typedef struct _GtkCssDelimToken GtkCssDelimToken;
typedef struct _GtkCssNumberToken GtkCssNumberToken;
typedef struct _GtkCssDimensionToken GtkCssDimensionToken;

struct _GtkCssStringToken {
  GtkCssTokenType  type;
  char            *string;
};

struct _GtkCssDelimToken {
  GtkCssTokenType  type;
  gunichar         delim;
};

struct _GtkCssNumberToken {
  GtkCssTokenType  type;
  double           number;
};

struct _GtkCssDimensionToken {
  GtkCssTokenType  type;
  double           value;
  char            *dimension;
};

union _GtkCssToken {
  GtkCssTokenType type;
  GtkCssStringToken string;
  GtkCssDelimToken delim;
  GtkCssNumberToken number;
  GtkCssDimensionToken dimension;
};

void                    gtk_css_token_clear                     (GtkCssToken            *token);

gboolean                gtk_css_token_is_finite                 (const GtkCssToken      *token) G_GNUC_PURE;
gboolean                gtk_css_token_is_preserved              (const GtkCssToken      *token,
                                                                 GtkCssTokenType        *out_closing) G_GNUC_PURE;
#define gtk_css_token_is(token, _type) ((token)->type == (_type))
gboolean                gtk_css_token_is_ident                  (const GtkCssToken      *token,
                                                                 const char             *ident) G_GNUC_PURE;
gboolean                gtk_css_token_is_function               (const GtkCssToken      *token,
                                                                 const char             *ident) G_GNUC_PURE;
gboolean                gtk_css_token_is_delim                  (const GtkCssToken      *token,
                                                                 gunichar                delim) G_GNUC_PURE;

void                    gtk_css_token_print                     (const GtkCssToken      *token,
                                                                 GString                *string);
char *                  gtk_css_token_to_string                 (const GtkCssToken      *token);

GtkCssTokenizer *       gtk_css_tokenizer_new                   (GBytes                 *bytes);

GtkCssTokenizer *       gtk_css_tokenizer_ref                   (GtkCssTokenizer        *tokenizer);
void                    gtk_css_tokenizer_unref                 (GtkCssTokenizer        *tokenizer);

const GtkCssLocation *  gtk_css_tokenizer_get_location          (GtkCssTokenizer        *tokenizer);

gboolean                gtk_css_tokenizer_read_token            (GtkCssTokenizer        *tokenizer,
                                                                 GtkCssToken            *token,
                                                                 GError                **error);

G_END_DECLS

#endif /* __GTK_CSS_TOKENIZER_PRIVATE_H__ */