1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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/>.
19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
25 #ifndef __G_SCANNER_H__
26 #define __G_SCANNER_H__
28 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
29 #error "Only <glib.h> can be included directly."
32 #include <glib/gdataset.h>
33 #include <glib/ghash.h>
37 typedef struct _GScanner GScanner
;
38 typedef struct _GScannerConfig GScannerConfig
;
39 typedef union _GTokenValue GTokenValue
;
41 typedef void (*GScannerMsgFunc
) (GScanner
*scanner
,
45 /* GScanner: Flexible lexical scanner for general purpose.
49 #define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
50 #define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"
51 #define G_CSET_DIGITS "0123456789"
52 #define G_CSET_LATINC "\300\301\302\303\304\305\306"\
53 "\307\310\311\312\313\314\315\316\317\320"\
54 "\321\322\323\324\325\326"\
55 "\330\331\332\333\334\335\336"
56 #define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\
57 "\347\350\351\352\353\354\355\356\357\360"\
58 "\361\362\363\364\365\366"\
59 "\370\371\372\373\374\375\376\377"
66 G_ERR_UNEXP_EOF_IN_STRING
,
67 G_ERR_UNEXP_EOF_IN_COMMENT
,
68 G_ERR_NON_DIGIT_IN_CONST
,
79 G_TOKEN_LEFT_PAREN
= '(',
80 G_TOKEN_RIGHT_PAREN
= ')',
81 G_TOKEN_LEFT_CURLY
= '{',
82 G_TOKEN_RIGHT_CURLY
= '}',
83 G_TOKEN_LEFT_BRACE
= '[',
84 G_TOKEN_RIGHT_BRACE
= ']',
85 G_TOKEN_EQUAL_SIGN
= '=',
102 G_TOKEN_IDENTIFIER_NULL
,
104 G_TOKEN_COMMENT_SINGLE
,
105 G_TOKEN_COMMENT_MULTI
,
127 struct _GScannerConfig
131 gchar
*cset_skip_characters
; /* default: " \t\n" */
132 gchar
*cset_identifier_first
;
133 gchar
*cset_identifier_nth
;
134 gchar
*cpair_comment_single
; /* default: "#\n" */
136 /* Should symbol lookup work case sensitive?
138 guint case_sensitive
: 1;
140 /* Boolean values to be adjusted "on the fly"
141 * to configure scanning behaviour.
143 guint skip_comment_multi
: 1; /* C like comment */
144 guint skip_comment_single
: 1; /* single line comment */
145 guint scan_comment_multi
: 1; /* scan multi line comments? */
146 guint scan_identifier
: 1;
147 guint scan_identifier_1char
: 1;
148 guint scan_identifier_NULL
: 1;
149 guint scan_symbols
: 1;
150 guint scan_binary
: 1;
151 guint scan_octal
: 1;
152 guint scan_float
: 1;
153 guint scan_hex
: 1; /* '0x0ff0' */
154 guint scan_hex_dollar
: 1; /* '$0ff0' */
155 guint scan_string_sq
: 1; /* string: 'anything' */
156 guint scan_string_dq
: 1; /* string: "\\-escapes!\n" */
157 guint numbers_2_int
: 1; /* bin, octal, hex => int */
158 guint int_2_float
: 1; /* int => G_TOKEN_FLOAT? */
159 guint identifier_2_string
: 1;
160 guint char_2_token
: 1; /* return G_TOKEN_CHAR? */
161 guint symbol_2_token
: 1;
162 guint scope_0_fallback
: 1; /* try scope 0 on lookups? */
163 guint store_int64
: 1; /* use value.v_int64 rather than v_int */
173 guint max_parse_errors
;
175 /* g_scanner_error() increments this field */
178 /* name of input stream, featured by the default message handler */
179 const gchar
*input_name
;
184 /* link into the scanner configuration */
185 GScannerConfig
*config
;
187 /* fields filled in after g_scanner_get_next_token() */
193 /* fields filled in after g_scanner_peek_next_token() */
194 GTokenType next_token
;
195 GTokenValue next_value
;
200 /* to be considered private */
201 GHashTable
*symbol_table
;
204 const gchar
*text_end
;
209 /* handler function for _warn and _error */
210 GScannerMsgFunc msg_handler
;
213 GLIB_AVAILABLE_IN_ALL
214 GScanner
* g_scanner_new (const GScannerConfig
*config_templ
);
215 GLIB_AVAILABLE_IN_ALL
216 void g_scanner_destroy (GScanner
*scanner
);
217 GLIB_AVAILABLE_IN_ALL
218 void g_scanner_input_file (GScanner
*scanner
,
220 GLIB_AVAILABLE_IN_ALL
221 void g_scanner_sync_file_offset (GScanner
*scanner
);
222 GLIB_AVAILABLE_IN_ALL
223 void g_scanner_input_text (GScanner
*scanner
,
226 GLIB_AVAILABLE_IN_ALL
227 GTokenType
g_scanner_get_next_token (GScanner
*scanner
);
228 GLIB_AVAILABLE_IN_ALL
229 GTokenType
g_scanner_peek_next_token (GScanner
*scanner
);
230 GLIB_AVAILABLE_IN_ALL
231 GTokenType
g_scanner_cur_token (GScanner
*scanner
);
232 GLIB_AVAILABLE_IN_ALL
233 GTokenValue
g_scanner_cur_value (GScanner
*scanner
);
234 GLIB_AVAILABLE_IN_ALL
235 guint
g_scanner_cur_line (GScanner
*scanner
);
236 GLIB_AVAILABLE_IN_ALL
237 guint
g_scanner_cur_position (GScanner
*scanner
);
238 GLIB_AVAILABLE_IN_ALL
239 gboolean
g_scanner_eof (GScanner
*scanner
);
240 GLIB_AVAILABLE_IN_ALL
241 guint
g_scanner_set_scope (GScanner
*scanner
,
243 GLIB_AVAILABLE_IN_ALL
244 void g_scanner_scope_add_symbol (GScanner
*scanner
,
248 GLIB_AVAILABLE_IN_ALL
249 void g_scanner_scope_remove_symbol (GScanner
*scanner
,
251 const gchar
*symbol
);
252 GLIB_AVAILABLE_IN_ALL
253 gpointer
g_scanner_scope_lookup_symbol (GScanner
*scanner
,
255 const gchar
*symbol
);
256 GLIB_AVAILABLE_IN_ALL
257 void g_scanner_scope_foreach_symbol (GScanner
*scanner
,
261 GLIB_AVAILABLE_IN_ALL
262 gpointer
g_scanner_lookup_symbol (GScanner
*scanner
,
263 const gchar
*symbol
);
264 GLIB_AVAILABLE_IN_ALL
265 void g_scanner_unexp_token (GScanner
*scanner
,
266 GTokenType expected_token
,
267 const gchar
*identifier_spec
,
268 const gchar
*symbol_spec
,
269 const gchar
*symbol_name
,
270 const gchar
*message
,
272 GLIB_AVAILABLE_IN_ALL
273 void g_scanner_error (GScanner
*scanner
,
275 ...) G_GNUC_PRINTF (2,3);
276 GLIB_AVAILABLE_IN_ALL
277 void g_scanner_warn (GScanner
*scanner
,
279 ...) G_GNUC_PRINTF (2,3);
281 #ifndef G_DISABLE_DEPRECATED
283 /* keep downward source compatibility */
284 #define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
285 g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
287 #define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
288 g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
290 #define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
291 g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
294 /* The following two functions are deprecated and will be removed in
295 * the next major release. They do no good. */
296 #define g_scanner_freeze_symbol_table(scanner) ((void)0)
297 #define g_scanner_thaw_symbol_table(scanner) ((void)0)
299 #endif /* G_DISABLE_DEPRECATED */
303 #endif /* __G_SCANNER_H__ */