1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 a general purpose lexical scanner.
7 <!-- ##### SECTION Long_Description ##### -->
9 The #GScanner and its associated functions provide a general purpose
13 FIXME: really needs an example and more detail, but I don't completely
14 understand it myself. Look at gtkrc.c for some code using the scanner.
17 <!-- ##### SECTION See_Also ##### -->
22 <!-- ##### STRUCT GScanner ##### -->
24 The data structure representing a lexical scanner.
27 You should set input_name after creating the scanner, since it is used
28 by the default message handler when displaying warnings and errors.
29 If you are scanning a file, the file name would be a good choice.
32 The <structfield>user_data</structfield> and
33 <structfield>derived_data</structfield> fields are not used.
34 If you need to associate extra data with the scanner you can place them here.
37 If you want to use your own message handler you can set the
38 <structfield>msg_handler</structfield> field. The type of the message
39 handler function is declared by #GScannerMsgFunc.
64 <!-- ##### FUNCTION g_scanner_new ##### -->
66 Creates a new #GScanner.
67 The @config_templ structure specifies the initial settings of the scanner,
68 which are copied into the #GScanner <structfield>config</structfield> field.
69 If you pass NULL then the default settings are used.
70 (See g_scanner_config_template in gscanner.c for the defaults.)
73 @config_templ: the initial scanner settings.
74 @Returns: the new #GScanner.
77 <!-- ##### STRUCT GScannerConfig ##### -->
79 Specifies the #GScanner settings.
82 <structfield>cset_skip_characters</structfield> specifies which characters
83 should be skipped by the scanner (the default is the whitespace characters:
84 space, tab, carriage-return and line-feed).
87 <structfield>cset_identifier_first</structfield> specifies the characters
88 which can start identifiers.
89 (the default is #G_CSET_a_2_z, "_", and #G_CSET_A_2_Z).
92 <structfield>cset_identifier_nth</structfield> specifies the characters
93 which can be used in identifiers, after the first character.
94 The default is #G_CSET_a_2_z, "_0123456789", #G_CSET_A_2_Z, #G_CSET_LATINS,
98 <structfield>cpair_comment_single</structfield> specifies the characters
99 at the start and end of single-line comments. The default is "#\n" which
100 means that single-line comments start with a '#' and continue until a '\n'
104 <structfield>case_sensitive</structfield> specifies if symbols are
108 The rest of the fields are flags which turn features on or off.
109 FIXME: should describe these.
112 @cset_skip_characters:
113 @cset_identifier_first:
114 @cset_identifier_nth:
115 @cpair_comment_single:
118 @skip_comment_single:
121 @scan_identifier_1char:
122 @scan_identifier_NULL:
133 @identifier_2_string:
138 <!-- ##### FUNCTION g_scanner_input_file ##### -->
140 Prepares to scan a file.
143 @scanner: a #GScanner.
144 @input_fd: a file descriptor.
147 <!-- ##### FUNCTION g_scanner_sync_file_offset ##### -->
155 <!-- ##### FUNCTION g_scanner_stat_mode ##### -->
157 Gets the file attributes.
158 This is the <structfield>st_mode</structfield> field from the
159 <structname>stat</structname> structure. See the <function>stat()</function>
163 @filename: the file name.
164 @Returns: the file attributes.
167 <!-- ##### FUNCTION g_scanner_input_text ##### -->
169 Prepares to scan a text buffer.
172 @scanner: a #GScanner.
173 @text: the text buffer to scan.
174 @text_len: the length of the text buffer.
177 <!-- ##### FUNCTION g_scanner_peek_next_token ##### -->
179 Gets the next token, without removing it from the input stream.
180 The token data is placed in the
181 <structfield>next_token</structfield>,
182 <structfield>next_value</structfield>,
183 <structfield>next_line</structfield>, and
184 <structfield>next_position</structfield> fields of the #GScanner structure.
187 @scanner: a #GScanner.
188 @Returns: the type of the token.
191 <!-- ##### FUNCTION g_scanner_get_next_token ##### -->
193 Gets the next token, removing it from the input stream.
194 The token data is placed in the
195 <structfield>token</structfield>,
196 <structfield>value</structfield>,
197 <structfield>line</structfield>, and
198 <structfield>position</structfield> fields of the #GScanner structure.
201 @scanner: a #GScanner.
202 @Returns: the type of the token.
205 <!-- ##### FUNCTION g_scanner_cur_line ##### -->
207 Gets the current line in the input stream (counting from 1).
210 @scanner: a #GScanner.
211 @Returns: the current line.
214 <!-- ##### FUNCTION g_scanner_cur_position ##### -->
216 Gets the current position in the current line (counting from 0).
219 @scanner: a #GScanner.
220 @Returns: the current position on the line.
223 <!-- ##### FUNCTION g_scanner_cur_token ##### -->
225 Gets the current token type.
226 This is simply the <structfield>token</structfield> field in the #GScanner
230 @scanner: a #GScanner.
231 @Returns: the current token type.
234 <!-- ##### FUNCTION g_scanner_cur_value ##### -->
236 Gets the current token value.
237 This is simply the <structfield>value</structfield> field in the #GScanner
241 @scanner: a #GScanner.
242 @Returns: the current token value.
245 <!-- ##### FUNCTION g_scanner_eof ##### -->
247 Returns TRUE if the scanner has reached the end of the file or text buffer.
250 @scanner: a #GScanner.
251 @Returns: TRUE if the scanner has reached the end of the file or text buffer.
254 <!-- ##### FUNCTION g_scanner_set_scope ##### -->
256 Sets the current scope.
259 @scanner: a #GScanner.
260 @scope_id: the new scope id.
261 @Returns: the old scope id.
264 <!-- ##### FUNCTION g_scanner_scope_add_symbol ##### -->
266 Adds a symbol to the given scope.
269 @scanner: a #GScanner.
270 @scope_id: the scope id.
271 @symbol: the symbol to add.
272 @value: the value of the symbol.
275 <!-- ##### FUNCTION g_scanner_scope_foreach_symbol ##### -->
286 <!-- ##### FUNCTION g_scanner_scope_lookup_symbol ##### -->
297 <!-- ##### FUNCTION g_scanner_scope_remove_symbol ##### -->
307 <!-- ##### FUNCTION g_scanner_freeze_symbol_table ##### -->
309 This function is deprecated and will be removed in the next major
310 release of GLib. It does nothing.
316 <!-- ##### FUNCTION g_scanner_thaw_symbol_table ##### -->
318 This function is deprecated and will be removed in the next major
319 release of GLib. It does nothing.
325 <!-- ##### FUNCTION g_scanner_lookup_symbol ##### -->
335 <!-- ##### FUNCTION g_scanner_warn ##### -->
337 Outputs a warning message, via the #GScanner message handler.
340 @scanner: a #GScanner.
341 @format: the message format. See the <function>printf()</function>
343 @Varargs: the parameters to insert into the format string.
346 <!-- ##### FUNCTION g_scanner_error ##### -->
348 Outputs an error message, via the #GScanner message handler.
351 @scanner: a #GScanner.
352 @format: the message format. See the <function>printf()</function>
354 @Varargs: the parameters to insert into the format string.
357 <!-- ##### FUNCTION g_scanner_unexp_token ##### -->
359 Outputs a message resulting from an unexpected token in the input stream.
360 FIXME: I don't understand the arguments here.
363 @scanner: a #GScanner.
364 @expected_token: the expected token.
365 @identifier_spec: a string describing the expected type of identifier,
366 or NULL to use the default "identifier" string.
367 @symbol_spec: a string describing the expected type of identifier,
368 or NULL to use the default "symbol" string.
370 @message: a message string to output at the end of the warning/error, or NULL.
371 @is_error: if TRUE it is output as an error. If False it is output as a
375 <!-- ##### USER_FUNCTION GScannerMsgFunc ##### -->
385 <!-- ##### FUNCTION g_scanner_destroy ##### -->
387 Frees all memory used by the #GScanner.
390 @scanner: a #GScanner.
393 <!-- ##### ENUM GTokenType ##### -->
395 The possible types of token returned from each g_scanner_get_next_token() call.
401 @G_TOKEN_RIGHT_CURLY:
403 <!-- ##### UNION GTokenValue ##### -->
405 A union holding the value of the token.
409 <!-- ##### ENUM GErrorType ##### -->
411 The possible errors, used in the <structfield>v_error</structfield> field
412 of #GTokenValue, when the token is a G_TOKEN_ERROR.
417 @G_ERR_UNEXP_EOF_IN_STRING:
418 @G_ERR_UNEXP_EOF_IN_COMMENT:
419 @G_ERR_NON_DIGIT_IN_CONST:
422 @G_ERR_FLOAT_MALFORMED:
424 <!-- ##### MACRO G_CSET_a_2_z ##### -->
426 The set of lower-case ASCII alphabet characters.
427 Used for specifying valid identifier characters in #GScannerConfig.
432 <!-- ##### MACRO G_CSET_A_2_Z ##### -->
434 The set of upper-case ASCII alphabet characters.
435 Used for specifying valid identifier characters in #GScannerConfig.
440 <!-- ##### MACRO G_CSET_DIGITS ##### -->
447 <!-- ##### MACRO G_CSET_LATINC ##### -->
449 Part of the set of extended characters in the Latin character sets.
451 Used for specifying valid identifier characters in #GScannerConfig.
456 <!-- ##### MACRO G_CSET_LATINS ##### -->
458 Part of the set of extended characters in the Latin character sets.
460 Used for specifying valid identifier characters in #GScannerConfig.
465 <!-- ##### MACRO g_scanner_add_symbol ##### -->
467 Adds a symbol to the default scope.
468 Deprecated in favour of g_scanner_scope_add_symbol().
471 @scanner: a #GScanner.
472 @symbol: the symbol to add.
473 @value: the value of the symbol.
476 <!-- ##### MACRO g_scanner_remove_symbol ##### -->
478 Removes a symbol from the default scope.
479 Deprecated in favour of g_scanner_scope_remove_symbol().
482 @scanner: a #GScanner.
483 @symbol: the symbol to remove.
486 <!-- ##### MACRO g_scanner_foreach_symbol ##### -->
488 Calls a function for each symbol in the default scope.
489 Deprecated in favour of g_scanner_scope_foreach_symbol().
492 @scanner: a #GScanner.
493 @func: the function to call with each symbol.
494 @data: data to pass to the function.