Package ch.bailu.gtk.glib
Class Scanner
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.glib.Scanner
- All Implemented Interfaces:
PointerInterface
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.
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.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
link into the scanner configurationstatic final String
name of input stream, featured by the default message handlerstatic final String
unusedstatic final String
g_scanner_error() increments this fieldstatic final String
quarked datastatic final String
token parsed by the last g_scanner_get_next_token()static final String
unused -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Scanner
_new
(ScannerConfig config_templ) Creates a new #GScanner.int
curLine()
Returns the current line in the input stream (counting
from 1).int
Returns the current position in the current line (counting
from 0).int
curToken()
Gets the current token type.void
destroy()
Frees all memory used by the #GScanner.boolean
eof()
Returns %TRUE if the scanner has reached the end of
the file or text buffer.void
Outputs an error message, via the #GScanner message handler.void
Outputs an error message, via the #GScanner message handler.static ClassHandler
link into the scanner configurationname of input stream, featured by the default message handlerint
unusedint
g_scanner_error() increments this fieldch.bailu.gtk.glib.Data
quarked dataint
token parsed by the last g_scanner_get_next_token()unusedint
Parses the next token just like g_scanner_peek_next_token()
and also removes it from the input stream.void
inputFile
(int input_fd) Prepares to scan a file.void
Prepares to scan a text buffer.void
Prepares to scan a text buffer.lookupSymbol
(Str symbol) Looks up a symbol in the current scope and return its value.lookupSymbol
(String symbol) Looks up a symbol in the current scope and return its value.int
Parses the next token, without removing it from the input stream.void
scopeAddSymbol
(int scope_id, Str symbol, Pointer value) Adds a symbol to the given scope.void
scopeAddSymbol
(int scope_id, String symbol, Pointer value) Adds a symbol to the given scope.void
scopeForeachSymbol
(int scope_id, Scanner.OnHFunc func, Pointer user_data) Calls the given function for each of the symbol/value pairs
in the given scope of the #GScanner.scopeLookupSymbol
(int scope_id, Str symbol) Looks up a symbol in a scope and return its value.scopeLookupSymbol
(int scope_id, String symbol) Looks up a symbol in a scope and return its value.void
scopeRemoveSymbol
(int scope_id, Str symbol) Removes a symbol from a scope.void
scopeRemoveSymbol
(int scope_id, String symbol) Removes a symbol from a scope.void
setFieldConfig
(ScannerConfig config) link into the scanner configurationvoid
setFieldInputName
(Str input_name) name of input stream, featured by the default message handlervoid
setFieldMaxParseErrors
(int max_parse_errors) unusedvoid
setFieldParseErrors
(int parse_errors) g_scanner_error() increments this fieldvoid
setFieldQdata
(ch.bailu.gtk.glib.Data qdata) quarked datavoid
setFieldToken
(int token) token parsed by the last g_scanner_get_next_token()void
setFieldUserData
(Pointer user_data) unusedint
setScope
(int scope_id) Sets the current scope.void
Rewinds the filedescriptor to the current buffer position
and blows the file read ahead buffer.void
unexpToken
(int expected_token, Str identifier_spec, Str symbol_spec, Str symbol_name, Str message, int is_error) Outputs a message through the scanner's msg_handler,
resulting from an unexpected token in the input stream.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.void
Outputs a warning message, via the #GScanner message handler.void
Outputs a warning message, via the #GScanner message handler.Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
USER_DATA
unused- See Also:
-
MAX_PARSE_ERRORS
unused- See Also:
-
PARSE_ERRORS
g_scanner_error() increments this field- See Also:
-
INPUT_NAME
name of input stream, featured by the default message handler- See Also:
-
QDATA
quarked data- See Also:
-
CONFIG
link into the scanner configuration- See Also:
-
TOKEN
token parsed by the last g_scanner_get_next_token()- See Also:
-
-
Constructor Details
-
Scanner
-
-
Method Details
-
getClassHandler
-
setFieldUserData
unused -
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
name of input stream, featured by the default message handler -
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
link into the scanner configuration -
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. -
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
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
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
Prepares to scan a text buffer.- Parameters:
text
- the text buffer to scantext_len
- the length of the text buffer
-
inputText
Prepares to scan a text buffer.- Parameters:
text
- the text buffer to scantext_len
- the length of the text buffer
-
lookupSymbol
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
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
Adds a symbol to the given scope.- Parameters:
scope_id
- the scope idsymbol
- the symbol to addvalue
- the value of the symbol
-
scopeAddSymbol
Adds a symbol to the given scope.- Parameters:
scope_id
- the scope idsymbol
- the symbol to addvalue
- the value of the symbol
-
scopeForeachSymbol
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 idfunc
- the function to call for each symbol/value pairuser_data
- user data to pass to the function
-
scopeLookupSymbol
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 idsymbol
- 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
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 idsymbol
- 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
Removes a symbol from a scope.- Parameters:
scope_id
- the scope idsymbol
- the symbol to remove
-
scopeRemoveSymbol
Removes a symbol from a scope.- Parameters:
scope_id
- the scope idsymbol
- 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 tokenidentifier_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 tokenidentifier_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
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
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
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
-