Basics
Guides
API Reference
Basics
Guides
API Reference
[20:7] extends: object
GScanner provides a general-purpose lexical scanner. You should set
@input_name after creating the scanner, since it is used by the default
message handler when displaying warnings and errors. If you are scanning a
file, the filename would be a good choice. The @user_data and
@max_parse_errors fields are not used. If you need to associate extra data
with the scanner you can place them here. If you want to use your own message
handler you can set the @msg_handler field. The type of the message handler
function is declared by #GScannerMsgFunc.
GScanner (Handle = null)
Creates a new
Scannerby wrapping a native handle or another wrapper.
Handle is the native handle or another wrapper whose handle to adopt.toNativeHandle (Source)
Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from
fn.call(...), another generated wrapper exposinghandle(), or null. Returns null when the argument carries no pointer.
Source is the raw handle, raw buffer, wrapper, or null.A raw pointer carrier or null when no pointer is present.getLib ()
Returns the opened native library for this generated wrapper.
The opened native library.handle ()
Returns the wrapped NativeHandle.
The wrapped NativeHandle.isNull ()
Returns true when the wrapped handle is null.
A bool.describe ()
Returns a small string for debugging generated wrappers.
A string.cur_line ()
Returns the current line in the input stream (counting from 1). This is the line of the last token parsed via g_scanner_get_next_token().
the current line.cur_position ()
Returns the current position in the current line (counting from 0). This is the position of the last token parsed via g_scanner_get_next_token().
the current position on the line.cur_token ()
Gets the current token type. This is simply the @token field in the #GScanner structure.
the current token type.cur_value ()
Gets the current token value. This is simply the @value field in the #GScanner structure.
the current token value.destroy ()
Frees all memory used by the #GScanner.
None.eof ()
Returns %TRUE if the scanner has reached the end of the file or text buffer.
%TRUE if the scanner has reached the end of the file or text buffer.error (string format, list varargs)
Outputs an error message, via the #GScanner message handler.
format is the message format. See the printf() documentation.... is the parameters to insert into the format string.None.get_next_token ()
Parses the next token just like g_scanner_peek_next_token() and also removes it from the input stream. The token data is placed in the @token,
@line, and @position fields of the #GScanner structure.the type of the token.input_file (int input_fd)
Prepares to scan a file.
input_fd is a file descriptor.None.input_text (string text, int text_len)
Prepares to scan a text buffer.
text is the text buffer to scan.text_len is the length of the text buffer.None.lookup_symbol (string symbol)
Looks up a symbol in the current scope and return its value. If the symbol is not bound in the current scope, %NULL is returned.
symbol is the symbol to look up.the value of @symbol in the current scope, or %NULL if @symbol is not bound in the current scope.peek_next_token ()
Parses the next token, without removing it from the input stream. The token data is placed in the @next_token, @next_value, @next_line, and
fields of the #GScanner structure. Note that, while the token is not removed from the input stream (i.e. the next call to g_scanner_get_next_token() will return the same token), it will not be reevaluated. This can lead to surprising results when changing scope or the scanner configuration after peeking the next token. Getting the next token after switching the scope or configuration will return whatever was peeked before, regardless of any symbols that may have been added or removed in the new scope.the type of the token.scope_add_symbol (int scope_id, string symbol, value)
Adds a symbol to the given scope.
scope_id is the scope id.symbol is the symbol to add.value is the value of the symbol.None.scope_foreach_symbol (int scope_id, user_data)
Calls the given function for each of the symbol/value pairs in the given scope of the #GScanner. The function is passed the symbol and value of each pair, and the given @user_data parameter.
scope_id is the scope id.func is the function to call for each symbol/value pair.user_data is user data to pass to the function.None.scope_lookup_symbol (int scope_id, string symbol)
Looks up a symbol in a scope and return its value. If the symbol is not bound in the scope, %NULL is returned.
scope_id is the scope id.symbol is the symbol to look up.the value of @symbol in the given scope, or %NULL if @symbol is not bound in the given scope..scope_remove_symbol (int scope_id, string symbol)
Removes a symbol from a scope.
scope_id is the scope id.symbol is the symbol to remove.None.set_scope (int scope_id)
Sets the current scope.
scope_id is the new scope id.the old scope id.sync_file_offset ()
Rewinds the filedescriptor to the current buffer position and blows the file read ahead buffer. This is useful for third party uses of the scanners filedescriptor, which hooks onto the current scanning position.
None.unexp_token (string expected_token, string identifier_spec, string symbol_spec, string symbol_name, string message, int is_error)
Outputs a message through the scanner's msg_handler, resulting from an unexpected token in the input stream. Note that you should not call g_scanner_peek_next_token() followed by g_scanner_unexp_token() without an intermediate call to g_scanner_get_next_token(), as g_scanner_unexp_token() evaluates the scanner's current token (not the peeked token) to construct part of the message.
expected_token is the expected token.identifier_spec is a string describing how the scanner's user refers to identifiers (%NULL defaults to "identifier"). This is used ifis %G_TOKEN_IDENTIFIER or %G_TOKEN_IDENTIFIER_NULL..symbol_spec is a string describing how the scanner's user refers to symbols (%NULL defaults to "symbol"). This is used if @expected_token is %G_TOKEN_SYMBOL or any token value greater than %G_TOKEN_LAST..symbol_name is the name of the symbol, if the scanner's current token is a symbol..message is a message string to output at the end of the warning/error, or %NULL..is_error is if %TRUE it is output as an error. If %FALSE it is output as a warning..None.warn (string format, list varargs)
Outputs a warning message, via the #GScanner message handler.
format is the message format. See the printf() documentation.... is the parameters to insert into the format string.None.
Aussom
Write once. Embed everywhere.
Copyright 2026 Austin Lehman. All rights reserved.