various: add GLIB_AVAILABLE_IN_ALL everywhere else
[platform/upstream/glib.git] / glib / gscanner.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
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 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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/.
25  */
26
27 #ifndef __G_SCANNER_H__
28 #define __G_SCANNER_H__
29
30 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
31 #error "Only <glib.h> can be included directly."
32 #endif
33
34 #include <glib/gdataset.h>
35 #include <glib/ghash.h>
36
37 G_BEGIN_DECLS
38
39 typedef struct _GScanner        GScanner;
40 typedef struct _GScannerConfig  GScannerConfig;
41 typedef union  _GTokenValue     GTokenValue;
42
43 typedef void            (*GScannerMsgFunc)      (GScanner      *scanner,
44                                                  gchar         *message,
45                                                  gboolean       error);
46
47 /* GScanner: Flexible lexical scanner for general purpose.
48  */
49
50 /* Character sets */
51 #define G_CSET_A_2_Z    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
52 #define G_CSET_a_2_z    "abcdefghijklmnopqrstuvwxyz"
53 #define G_CSET_DIGITS   "0123456789"
54 #define G_CSET_LATINC   "\300\301\302\303\304\305\306"\
55                         "\307\310\311\312\313\314\315\316\317\320"\
56                         "\321\322\323\324\325\326"\
57                         "\330\331\332\333\334\335\336"
58 #define G_CSET_LATINS   "\337\340\341\342\343\344\345\346"\
59                         "\347\350\351\352\353\354\355\356\357\360"\
60                         "\361\362\363\364\365\366"\
61                         "\370\371\372\373\374\375\376\377"
62
63 /* Error types */
64 typedef enum
65 {
66   G_ERR_UNKNOWN,
67   G_ERR_UNEXP_EOF,
68   G_ERR_UNEXP_EOF_IN_STRING,
69   G_ERR_UNEXP_EOF_IN_COMMENT,
70   G_ERR_NON_DIGIT_IN_CONST,
71   G_ERR_DIGIT_RADIX,
72   G_ERR_FLOAT_RADIX,
73   G_ERR_FLOAT_MALFORMED
74 } GErrorType;
75
76 /* Token types */
77 typedef enum
78 {
79   G_TOKEN_EOF                   =   0,
80   
81   G_TOKEN_LEFT_PAREN            = '(',
82   G_TOKEN_RIGHT_PAREN           = ')',
83   G_TOKEN_LEFT_CURLY            = '{',
84   G_TOKEN_RIGHT_CURLY           = '}',
85   G_TOKEN_LEFT_BRACE            = '[',
86   G_TOKEN_RIGHT_BRACE           = ']',
87   G_TOKEN_EQUAL_SIGN            = '=',
88   G_TOKEN_COMMA                 = ',',
89   
90   G_TOKEN_NONE                  = 256,
91   
92   G_TOKEN_ERROR,
93   
94   G_TOKEN_CHAR,
95   G_TOKEN_BINARY,
96   G_TOKEN_OCTAL,
97   G_TOKEN_INT,
98   G_TOKEN_HEX,
99   G_TOKEN_FLOAT,
100   G_TOKEN_STRING,
101   
102   G_TOKEN_SYMBOL,
103   G_TOKEN_IDENTIFIER,
104   G_TOKEN_IDENTIFIER_NULL,
105   
106   G_TOKEN_COMMENT_SINGLE,
107   G_TOKEN_COMMENT_MULTI,
108
109   /*< private >*/
110   G_TOKEN_LAST
111 } GTokenType;
112
113 union   _GTokenValue
114 {
115   gpointer      v_symbol;
116   gchar         *v_identifier;
117   gulong        v_binary;
118   gulong        v_octal;
119   gulong        v_int;
120   guint64       v_int64;
121   gdouble       v_float;
122   gulong        v_hex;
123   gchar         *v_string;
124   gchar         *v_comment;
125   guchar        v_char;
126   guint         v_error;
127 };
128
129 struct  _GScannerConfig
130 {
131   /* Character sets
132    */
133   gchar         *cset_skip_characters;          /* default: " \t\n" */
134   gchar         *cset_identifier_first;
135   gchar         *cset_identifier_nth;
136   gchar         *cpair_comment_single;          /* default: "#\n" */
137   
138   /* Should symbol lookup work case sensitive?
139    */
140   guint         case_sensitive : 1;
141   
142   /* Boolean values to be adjusted "on the fly"
143    * to configure scanning behaviour.
144    */
145   guint         skip_comment_multi : 1;         /* C like comment */
146   guint         skip_comment_single : 1;        /* single line comment */
147   guint         scan_comment_multi : 1;         /* scan multi line comments? */
148   guint         scan_identifier : 1;
149   guint         scan_identifier_1char : 1;
150   guint         scan_identifier_NULL : 1;
151   guint         scan_symbols : 1;
152   guint         scan_binary : 1;
153   guint         scan_octal : 1;
154   guint         scan_float : 1;
155   guint         scan_hex : 1;                   /* `0x0ff0' */
156   guint         scan_hex_dollar : 1;            /* `$0ff0' */
157   guint         scan_string_sq : 1;             /* string: 'anything' */
158   guint         scan_string_dq : 1;             /* string: "\\-escapes!\n" */
159   guint         numbers_2_int : 1;              /* bin, octal, hex => int */
160   guint         int_2_float : 1;                /* int => G_TOKEN_FLOAT? */
161   guint         identifier_2_string : 1;
162   guint         char_2_token : 1;               /* return G_TOKEN_CHAR? */
163   guint         symbol_2_token : 1;
164   guint         scope_0_fallback : 1;           /* try scope 0 on lookups? */
165   guint         store_int64 : 1;                /* use value.v_int64 rather than v_int */
166
167   /*< private >*/
168   guint         padding_dummy;
169 };
170
171 struct  _GScanner
172 {
173   /* unused fields */
174   gpointer              user_data;
175   guint                 max_parse_errors;
176   
177   /* g_scanner_error() increments this field */
178   guint                 parse_errors;
179   
180   /* name of input stream, featured by the default message handler */
181   const gchar           *input_name;
182   
183   /* quarked data */
184   GData                 *qdata;
185   
186   /* link into the scanner configuration */
187   GScannerConfig        *config;
188   
189   /* fields filled in after g_scanner_get_next_token() */
190   GTokenType            token;
191   GTokenValue           value;
192   guint                 line;
193   guint                 position;
194   
195   /* fields filled in after g_scanner_peek_next_token() */
196   GTokenType            next_token;
197   GTokenValue           next_value;
198   guint                 next_line;
199   guint                 next_position;
200
201   /*< private >*/
202   /* to be considered private */
203   GHashTable            *symbol_table;
204   gint                  input_fd;
205   const gchar           *text;
206   const gchar           *text_end;
207   gchar                 *buffer;
208   guint                 scope_id;
209
210   /*< public >*/
211   /* handler function for _warn and _error */
212   GScannerMsgFunc       msg_handler;
213 };
214
215 GLIB_AVAILABLE_IN_ALL
216 GScanner*       g_scanner_new                   (const GScannerConfig *config_templ);
217 GLIB_AVAILABLE_IN_ALL
218 void            g_scanner_destroy               (GScanner       *scanner);
219 GLIB_AVAILABLE_IN_ALL
220 void            g_scanner_input_file            (GScanner       *scanner,
221                                                  gint           input_fd);
222 GLIB_AVAILABLE_IN_ALL
223 void            g_scanner_sync_file_offset      (GScanner       *scanner);
224 GLIB_AVAILABLE_IN_ALL
225 void            g_scanner_input_text            (GScanner       *scanner,
226                                                  const  gchar   *text,
227                                                  guint          text_len);
228 GLIB_AVAILABLE_IN_ALL
229 GTokenType      g_scanner_get_next_token        (GScanner       *scanner);
230 GLIB_AVAILABLE_IN_ALL
231 GTokenType      g_scanner_peek_next_token       (GScanner       *scanner);
232 GLIB_AVAILABLE_IN_ALL
233 GTokenType      g_scanner_cur_token             (GScanner       *scanner);
234 GLIB_AVAILABLE_IN_ALL
235 GTokenValue     g_scanner_cur_value             (GScanner       *scanner);
236 GLIB_AVAILABLE_IN_ALL
237 guint           g_scanner_cur_line              (GScanner       *scanner);
238 GLIB_AVAILABLE_IN_ALL
239 guint           g_scanner_cur_position          (GScanner       *scanner);
240 GLIB_AVAILABLE_IN_ALL
241 gboolean        g_scanner_eof                   (GScanner       *scanner);
242 GLIB_AVAILABLE_IN_ALL
243 guint           g_scanner_set_scope             (GScanner       *scanner,
244                                                  guint           scope_id);
245 GLIB_AVAILABLE_IN_ALL
246 void            g_scanner_scope_add_symbol      (GScanner       *scanner,
247                                                  guint           scope_id,
248                                                  const gchar    *symbol,
249                                                  gpointer       value);
250 GLIB_AVAILABLE_IN_ALL
251 void            g_scanner_scope_remove_symbol   (GScanner       *scanner,
252                                                  guint           scope_id,
253                                                  const gchar    *symbol);
254 GLIB_AVAILABLE_IN_ALL
255 gpointer        g_scanner_scope_lookup_symbol   (GScanner       *scanner,
256                                                  guint           scope_id,
257                                                  const gchar    *symbol);
258 GLIB_AVAILABLE_IN_ALL
259 void            g_scanner_scope_foreach_symbol  (GScanner       *scanner,
260                                                  guint           scope_id,
261                                                  GHFunc          func,
262                                                  gpointer        user_data);
263 GLIB_AVAILABLE_IN_ALL
264 gpointer        g_scanner_lookup_symbol         (GScanner       *scanner,
265                                                  const gchar    *symbol);
266 GLIB_AVAILABLE_IN_ALL
267 void            g_scanner_unexp_token           (GScanner       *scanner,
268                                                  GTokenType     expected_token,
269                                                  const gchar    *identifier_spec,
270                                                  const gchar    *symbol_spec,
271                                                  const gchar    *symbol_name,
272                                                  const gchar    *message,
273                                                  gint            is_error);
274 GLIB_AVAILABLE_IN_ALL
275 void            g_scanner_error                 (GScanner       *scanner,
276                                                  const gchar    *format,
277                                                  ...) G_GNUC_PRINTF (2,3);
278 GLIB_AVAILABLE_IN_ALL
279 void            g_scanner_warn                  (GScanner       *scanner,
280                                                  const gchar    *format,
281                                                  ...) G_GNUC_PRINTF (2,3);
282
283 #ifndef G_DISABLE_DEPRECATED
284
285 /* keep downward source compatibility */
286 #define         g_scanner_add_symbol( scanner, symbol, value )  G_STMT_START { \
287   g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
288 } G_STMT_END
289 #define         g_scanner_remove_symbol( scanner, symbol )      G_STMT_START { \
290   g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
291 } G_STMT_END
292 #define         g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
293   g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
294 } G_STMT_END
295
296 /* The following two functions are deprecated and will be removed in
297  * the next major release. They do no good. */
298 #define g_scanner_freeze_symbol_table(scanner) ((void)0)
299 #define g_scanner_thaw_symbol_table(scanner) ((void)0)
300
301 #endif /* G_DISABLE_DEPRECATED */
302
303 G_END_DECLS
304
305 #endif /* __G_SCANNER_H__ */