gi-glib-2.0.13: GLib bindings

CopyrightWill Thompson, Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.GLib.Structs.Scanner

Contents

Description

The data structure representing a lexical scanner.

You should set inputName 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 userData and maxParseErrors 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 msgHandler field. The type of the message handler function is declared by ScannerMsgFunc.

Synopsis

Exported types

newZeroScanner :: MonadIO m => m Scanner Source #

Construct a Scanner struct initialized to zero.

Methods

curLine

scannerCurLine Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> m Word32

Returns: the current line

Returns the current line in the input stream (counting from 1). This is the line of the last token parsed via scannerGetNextToken.

curPosition

scannerCurPosition Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> m Word32

Returns: the current position on the line

Returns the current position in the current line (counting from 0). This is the position of the last token parsed via scannerGetNextToken.

curToken

scannerCurToken Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> m TokenType

Returns: the current token type

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

destroy

scannerDestroy Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> m () 

Frees all memory used by the Scanner.

eof

scannerEof Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> m Bool

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.

getNextToken

scannerGetNextToken Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> m TokenType

Returns: the type of the token

Parses the next token just like scannerPeekNextToken and also removes it from the input stream. The token data is placed in the token, value, line, and position fields of the Scanner structure.

inputFile

scannerInputFile Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> Int32

inputFd: a file descriptor

-> m () 

Prepares to scan a file.

inputText

scannerInputText Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> Text

text: the text buffer to scan

-> Word32

textLen: the length of the text buffer

-> m () 

Prepares to scan a text buffer.

lookupSymbol

scannerLookupSymbol Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> Text

symbol: the symbol to look up

-> m (Ptr ())

Returns: the value of symbol in the current scope, or Nothing if symbol is not bound in the current scope

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

peekNextToken

scannerPeekNextToken Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> m TokenType

Returns: the type of the token

Parses the next token, without removing it from the input stream. The token data is placed in the nextToken, nextValue, nextLine, and nextPosition fields of the Scanner structure.

Note that, while the token is not removed from the input stream (i.e. the next call to scannerGetNextToken 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.

scopeAddSymbol

scannerScopeAddSymbol Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> Word32

scopeId: the scope id

-> Text

symbol: the symbol to add

-> Ptr ()

value: the value of the symbol

-> m () 

Adds a symbol to the given scope.

scopeLookupSymbol

scannerScopeLookupSymbol Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> Word32

scopeId: the scope id

-> Text

symbol: the symbol to look up

-> m (Ptr ())

Returns: the value of symbol in the given scope, or Nothing if symbol is not bound in the given scope.

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

scopeRemoveSymbol

scannerScopeRemoveSymbol Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> Word32

scopeId: the scope id

-> Text

symbol: the symbol to remove

-> m () 

Removes a symbol from a scope.

setScope

scannerSetScope Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> Word32

scopeId: the new scope id

-> m Word32

Returns: the old scope id

Sets the current scope.

syncFileOffset

scannerSyncFileOffset Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> m () 

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

scannerUnexpToken Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Scanner

scanner: a Scanner

-> TokenType

expectedToken: the expected token

-> Text

identifierSpec: a string describing how the scanner's user refers to identifiers (Nothing defaults to "identifier"). This is used if expectedToken is TokenTypeIdentifier or TokenTypeIdentifierNull.

-> Text

symbolSpec: a string describing how the scanner's user refers to symbols (Nothing defaults to "symbol"). This is used if expectedToken is TokenTypeSymbol or any token value greater than G_TOKEN_LAST.

-> Text

symbolName: the name of the symbol, if the scanner's current token is a symbol.

-> Text

message: a message string to output at the end of the warning/error, or Nothing.

-> Int32

isError: if True it is output as an error. If False it is output as a warning.

-> m () 

Outputs a message through the scanner's msg_handler, resulting from an unexpected token in the input stream. Note that you should not call scannerPeekNextToken followed by scannerUnexpToken without an intermediate call to scannerGetNextToken, as scannerUnexpToken evaluates the scanner's current token (not the peeked token) to construct part of the message.

Properties

config

inputName

line

maxParseErrors

msgHandler

nextLine

nextPosition

nextToken

nextValue

parseErrors

position

qdata

token

userData

value