Class Scanner

All Implemented Interfaces:
PointerInterface

public class Scanner extends Record
The data structure representing a 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.

https://docs.gtk.org/glib/struct.Scanner.html

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • setFieldUserData

      public void setFieldUserData(Pointer user_data)
      unused
    • getFieldUserData

      public Pointer getFieldUserData()
      unused
    • setFieldMaxParseErrors

      public void setFieldMaxParseErrors(int max_parse_errors)
      unused
    • getFieldMaxParseErrors

      public int getFieldMaxParseErrors()
      unused
    • setFieldParseErrors

      public void setFieldParseErrors(int parse_errors)
      g_scanner_error() increments this field
    • getFieldParseErrors

      public int getFieldParseErrors()
      g_scanner_error() increments this field
    • setFieldInputName

      public void setFieldInputName(Str input_name)
      name of input stream, featured by the default message handler
    • getFieldInputName

      public Str getFieldInputName()
      name of input stream, featured by the default message handler
    • setFieldQdata

      public void setFieldQdata(ch.bailu.gtk.glib.Data qdata)
      quarked data
    • getFieldQdata

      public ch.bailu.gtk.glib.Data getFieldQdata()
      quarked data
    • setFieldConfig

      public void setFieldConfig(ScannerConfig config)
      link into the scanner configuration
    • getFieldConfig

      public ScannerConfig getFieldConfig()
      link into the scanner configuration
    • setFieldToken

      public void setFieldToken(int token)
      token parsed by the last g_scanner_get_next_token()
    • getFieldToken

      public int getFieldToken()
      token parsed by the last g_scanner_get_next_token()
    • curLine

      public int curLine()
      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().
      Returns:
      the current line
    • curPosition

      public int curPosition()
      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().
      Returns:
      the current position on the line
    • curToken

      public int curToken()
      Gets the current token type. This is simply the @token
      field in the #GScanner structure.
      Returns:
      the current token type
    • destroy

      public void destroy()
      Frees all memory used by the #GScanner.
      Overrides:
      destroy in class Record
    • eof

      public boolean eof()
      Returns %TRUE if the scanner has reached the end of
      the file or text buffer.
      Returns:
      %TRUE if the scanner has reached the end of the file or text buffer
    • error

      public void error(@Nonnull Str format, Object... _elipse)
      Outputs an error message, via the #GScanner message handler.
      Parameters:
      format - the message format. See the printf() documentation
      _elipse - the parameters to insert into the format string
    • error

      public void error(String format, Object... _elipse)
      Outputs an error message, via the #GScanner message handler.
      Parameters:
      format - the message format. See the printf() documentation
      _elipse - the parameters to insert into the format string
    • getNextToken

      public int getNextToken()
      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.
      Returns:
      the type of the token
    • inputFile

      public void inputFile(int input_fd)
      Prepares to scan a file.
      Parameters:
      input_fd - a file descriptor
    • inputText

      public void inputText(@Nonnull Str text, int text_len)
      Prepares to scan a text buffer.
      Parameters:
      text - the text buffer to scan
      text_len - the length of the text buffer
    • inputText

      public void inputText(String text, int text_len)
      Prepares to scan a text buffer.
      Parameters:
      text - the text buffer to scan
      text_len - the length of the text buffer
    • lookupSymbol

      public Pointer lookupSymbol(@Nonnull Str 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.
      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
    • lookupSymbol

      public Pointer lookupSymbol(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.
      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
    • peekNextToken

      public int peekNextToken()
      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.

      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.
      Returns:
      the type of the token
    • scopeAddSymbol

      public void scopeAddSymbol(int scope_id, @Nonnull Str symbol, @Nullable Pointer 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
    • scopeAddSymbol

      public void scopeAddSymbol(int scope_id, String symbol, @Nullable Pointer 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
    • scopeForeachSymbol

      public void scopeForeachSymbol(int scope_id, Scanner.OnHFunc func, @Nullable Pointer 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.
      Parameters:
      scope_id - the scope id
      func - the function to call for each symbol/value pair
      user_data - user data to pass to the function
    • scopeLookupSymbol

      public Pointer scopeLookupSymbol(int scope_id, @Nonnull Str symbol)
      Looks up a symbol in a scope and return its value. If the
      symbol is not bound in the scope, %NULL is returned.
      Parameters:
      scope_id - the scope id
      symbol - the symbol to look up
      Returns:
      the value of @symbol in the given scope, or %NULL if @symbol is not bound in the given scope.
    • scopeLookupSymbol

      public Pointer scopeLookupSymbol(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.
      Parameters:
      scope_id - the scope id
      symbol - the symbol to look up
      Returns:
      the value of @symbol in the given scope, or %NULL if @symbol is not bound in the given scope.
    • scopeRemoveSymbol

      public void scopeRemoveSymbol(int scope_id, @Nonnull Str symbol)
      Removes a symbol from a scope.
      Parameters:
      scope_id - the scope id
      symbol - the symbol to remove
    • scopeRemoveSymbol

      public void scopeRemoveSymbol(int scope_id, String symbol)
      Removes a symbol from a scope.
      Parameters:
      scope_id - the scope id
      symbol - the symbol to remove
    • setScope

      public int setScope(int scope_id)
      Sets the current scope.
      Parameters:
      scope_id - the new scope id
      Returns:
      the old scope id
    • syncFileOffset

      public void syncFileOffset()
      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.
    • unexpToken

      public void unexpToken(int expected_token, @Nonnull Str identifier_spec, @Nonnull Str symbol_spec, @Nonnull Str symbol_name, @Nonnull Str 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.
      Parameters:
      expected_token - the expected token
      identifier_spec - a string describing how the scanner's user refers to identifiers (%NULL defaults to "identifier"). This is used if @expected_token is %G_TOKEN_IDENTIFIER or %G_TOKEN_IDENTIFIER_NULL.
      symbol_spec - 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 - the name of the symbol, if the scanner's current token is a symbol.
      message - a message string to output at the end of the warning/error, or %NULL.
      is_error - if %TRUE it is output as an error. If %FALSE it is output as a warning.
    • unexpToken

      public void unexpToken(int 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.
      Parameters:
      expected_token - the expected token
      identifier_spec - a string describing how the scanner's user refers to identifiers (%NULL defaults to "identifier"). This is used if @expected_token is %G_TOKEN_IDENTIFIER or %G_TOKEN_IDENTIFIER_NULL.
      symbol_spec - 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 - the name of the symbol, if the scanner's current token is a symbol.
      message - a message string to output at the end of the warning/error, or %NULL.
      is_error - if %TRUE it is output as an error. If %FALSE it is output as a warning.
    • warn

      public void warn(@Nonnull Str format, Object... _elipse)
      Outputs a warning message, via the #GScanner message handler.
      Parameters:
      format - the message format. See the printf() documentation
      _elipse - the parameters to insert into the format string
    • warn

      public void warn(String format, Object... _elipse)
      Outputs a warning message, via the #GScanner message handler.
      Parameters:
      format - the message format. See the printf() documentation
      _elipse - the parameters to insert into the format string
    • _new

      public static Scanner _new(@Nonnull ScannerConfig config_templ)
      Creates a new #GScanner.

      The @config_templ structure specifies the initial settings
      of the scanner, which are copied into the #GScanner
      @config field. If you pass %NULL then the default settings
      are used.
      Parameters:
      config_templ - the initial scanner settings
      Returns:
      the new #GScanner