Struct

GLibScanner

Description [src]

struct GScanner {
  gpointer user_data;
  guint max_parse_errors;
  guint parse_errors;
  const gchar* input_name;
  GData* qdata;
  GScannerConfig* config;
  GTokenType token;
  GTokenValue value;
  guint line;
  guint position;
  GTokenType next_token;
  GTokenValue next_value;
  guint next_line;
  guint next_position;
  GScannerMsgFunc msg_handler;
}

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.

Structure members
user_data

Unused.

max_parse_errors

Unused.

parse_errors

G_scanner_error() increments this field.

input_name

Name of input stream, featured by the default message handler.

qdata

Quarked data.

config

Link into the scanner configuration.

token

Token parsed by the last g_scanner_get_next_token().

value

Value of the last token from g_scanner_get_next_token().

line

Line number of the last token from g_scanner_get_next_token().

position

Char number of the last token from g_scanner_get_next_token().

next_token

Token parsed by the last g_scanner_peek_next_token().

next_value

Value of the last token from g_scanner_peek_next_token().

next_line

Line number of the last token from g_scanner_peek_next_token().

next_position

Char number of the last token from g_scanner_peek_next_token().

msg_handler

Handler function for _warn and _error.

Functions

g_scanner_new

Creates a new GScanner.

Instance methods

g_scanner_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().

g_scanner_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().

g_scanner_cur_token

Gets the current token type. This is simply the token field in the GScanner structure.

g_scanner_cur_value

Gets the current token value. This is simply the value field in the GScanner structure.

g_scanner_destroy

Frees all memory used by the GScanner.

g_scanner_eof

Returns TRUE if the scanner has reached the end of the file or text buffer.

g_scanner_error

Outputs an error message, via the GScanner message handler.

g_scanner_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, value, line, and position fields of the GScanner structure.

g_scanner_input_file

Prepares to scan a file.

g_scanner_input_text

Prepares to scan a text buffer.

g_scanner_lookup_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.

g_scanner_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 next_position fields of the GScanner structure.

g_scanner_scope_add_symbol

Adds a symbol to the given scope.

g_scanner_scope_foreach_symbol

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.

g_scanner_scope_lookup_symbol

Looks up a symbol in a scope and return its value. If the symbol is not bound in the scope, NULL is returned.

g_scanner_scope_remove_symbol

Removes a symbol from a scope.

g_scanner_set_scope

Sets the current scope.

g_scanner_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.

g_scanner_unexp_token

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.

g_scanner_warn

Outputs a warning message, via the GScanner message handler.