Xfce Foundation Classes
Main Page | Index | Namespace List | Alphabetical List | Class List | File List

# Xfc::G::Scanner Class Reference

A general purpose lexical scanner. More...

`#include <xfc/glib/scanner.hh>`

Inheritance diagram for Xfc::G::Scanner:

List of all members.

## Public Types

- typedef sigc::slot< void,
  void *, void * > ScopeForeachSymbolSlot
    Signature of the callback slot for a key/value pair.

## Public Member Functions

Constructors

- Scanner (const GScannerConfig *initial_settings)
    Construct a new scanner.
- Scanner (GScanner *scanner)
    Construct a scanner from an existing GScanner.
- ~Scanner ()
    Destructor.

Accessors

- GScanner * g_scanner () const
    Get a pointer to the GScanner object.
- operator GScanner * () const
    Conversion operator; Safely converts a G::Scanner object into a GScanner pointer.
- GTokenType token () const
    Gets the current token type.
- GTokenValue value () const
    Gets the current token value.
- unsigned int line () const
    Gets the current line in the input stream (counting from 1).
- unsigned int position () const
    Gets the current position in the current line (counting from 0).
- bool eof () const
    Returns true if the scanner has reached the end of the file or text buffer.
- GTokenType next_token () const
    Gets the next token type.
- GTokenValue next_value () const
    Gets the next token value.
- unsigned int next_line () const
    Gets the next line in the input stream (counting from 1).
- unsigned int next_position () const
    Gets the next position in the current line (counting from 0).
- GTokenType get_next_token () const
    Gets the next token, removing it from the input stream.
- GTokenType peek_next_token () const
    Gets the next token, without removing it from the input stream.

Methods

- void input_file (int input_fd)
    Prepares to scan a file.
- void sync_file_offset ()
    Rewinds the file descriptor to the current buffer position and blows the file read ahead buffer.
- void input_text (const char *text, unsigned int length)
    Prepares to scan a text buffer.
- void input_text (const String &text)
    Prepares to scan a text buffer.
- unsigned int set_scope (unsigned int scope_id)
    Sets the current scope.
- void scope_add_symbol (unsigned int scope_id, const char *symbol, void *value)
    Adds a symbol to the given scope.
- void scope_remove_symbol (unsigned int scope_id, const char *symbol)
    Removes a symbol from a scope.
- void * scope_lookup_symbol (unsigned int scope_id, const char *symbol)
    Looks up a symbol in a scope and returns its value.
- void scope_foreach_symbol (unsigned int scope_id, const ScopeForeachSymbolSlot &slot)
    Calls the given slot for each of the symbol/value pairs in the given scope of the scanner.
- void * lookup_symbol (const char *symbol)
    Looks up a symbol in the current scope and returns its value.
- void error (const char *format,...)
    Outputs an error message, via the GScanner message handler.
- void warn (const char *format,...)
    Outputs a warning message, via the GScanner message handler.

## Detailed Description

A general purpose lexical scanner.

## Constructor & Destructor Documentation

Xfc::G::Scanner::Scanner | ( | const GScannerConfig * | initial_settings | ) |

Construct a new scanner.

Parameters:

  | initial_settings | A GScannerConfig structure specifiying the initial settings for the scanner.

If you pass null for the initial_settings, the default settings are used.

Xfc::G::Scanner::Scanner | ( | GScanner * | scanner | ) | `[explicit]`

Construct a scanner from an existing GScanner.

Parameters:

  | scanner | A pointer to a GScanner.

The Scanner object takes over the ownership of the GScanner and destroys it when the destructor is called.

## Member Function Documentation

void Xfc::G::Scanner::error | ( | const char * | format,
|  |  | ...
| ) |

Outputs an error message, via the GScanner message handler.

Parameters:

  | format | The message format. See the printf() documentation.
  | ... | The parameters to insert into the format string.

GTokenType Xfc::G::Scanner::get_next_token | ( |  | ) | const

| Gets the next token, removing it from the input stream. The token data is placed in the token(), value(), line(), and position() fields.

void Xfc::G::Scanner::input_file | ( | int | input_fd | ) |

Prepares to scan a file.

Parameters:

  | input_fd | A file descriptor.

void Xfc::G::Scanner::input_text | ( | const String & | text | ) |

Prepares to scan a text buffer.

Parameters:

  | text | The text buffer to scan.

void Xfc::G::Scanner::input_text | ( | const char * | text,
|  | unsigned int | length
| ) |

Prepares to scan a text buffer.

Parameters:

  | text | The text buffer to scan.
  | length | The length of the text buffer.

void* Xfc::G::Scanner::lookup_symbol | ( | const char * | symbol | ) |

Looks up a symbol in the current scope and returns its value.

Parameters:

  | symbol | The symbol to look up.

Returns:
  The value of symbol in the current scope, or null if symbol is not bound in the current scope.

GTokenType Xfc::G::Scanner::peek_next_token | ( |  | ) | const

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

void Xfc::G::Scanner::scope_add_symbol | ( | unsigned int | scope_id,
|  | const char * | symbol,
|  | void * | value
| ) |

Adds a symbol to the given scope.

Parameters:

  | scope_id | The scope id.
  | symbol | The symbol to add.
  | value | The value of the symbol.

void Xfc::G::Scanner::scope_foreach_symbol | ( | unsigned int | scope_id,
|  | const ScopeForeachSymbolSlot & | slot
| ) |

Calls the given slot for each of the symbol/value pairs in the given scope of the scanner.

Parameters:

  | scope_id | The scope id.
  | slot | The ScopeForeachSymbolSlot method to call.

The slot method is passed the symbol and value of each pair as a parameter.

void* Xfc::G::Scanner::scope_lookup_symbol | ( | unsigned int | scope_id,
|  | const char * | symbol
| ) |

Looks up a symbol in a scope and returns its value.

Parameters:

  | scope_id | The scope id.
  | symbol | The symbol to look up.

If the symbol is not bound in the scope, null is returned.

void Xfc::G::Scanner::scope_remove_symbol | ( | unsigned int | scope_id,
|  | const char * | symbol
| ) |

Removes a symbol from a scope.

Parameters:

  | scope_id | The scope id.
  | symbol | The symbol to remove.

unsigned int Xfc::G::Scanner::set_scope | ( | unsigned int | scope_id | ) |

Sets the current scope.

Parameters:

  | scope_id | The new scope id.

Returns:
  The old scope id.

void Xfc::G::Scanner::sync_file_offset | ( |  | ) |

| Rewinds the file descriptor 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.

void Xfc::G::Scanner::warn | ( | const char * | format,
|  |  | ...
| ) |

Outputs a warning message, via the GScanner message handler.

Parameters:

  | format | The message format. See the printf() documentation.
  | ... | The parameters to insert into the format string.

The documentation for this class was generated from the following file:

- scanner.hh

Xfce Foundation Classes

Copyright © 2004-2005 The XFC Development Team | XFC 4.3