Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
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
.
- newtype Scanner = Scanner (ManagedPtr Scanner)
- newZeroScanner :: MonadIO m => m Scanner
- noScanner :: Maybe Scanner
- data ScannerCurLineMethodInfo
- scannerCurLine :: (HasCallStack, MonadIO m) => Scanner -> m Word32
- data ScannerCurPositionMethodInfo
- scannerCurPosition :: (HasCallStack, MonadIO m) => Scanner -> m Word32
- data ScannerCurTokenMethodInfo
- scannerCurToken :: (HasCallStack, MonadIO m) => Scanner -> m TokenType
- data ScannerDestroyMethodInfo
- scannerDestroy :: (HasCallStack, MonadIO m) => Scanner -> m ()
- data ScannerEofMethodInfo
- scannerEof :: (HasCallStack, MonadIO m) => Scanner -> m Bool
- data ScannerGetNextTokenMethodInfo
- scannerGetNextToken :: (HasCallStack, MonadIO m) => Scanner -> m TokenType
- data ScannerInputFileMethodInfo
- scannerInputFile :: (HasCallStack, MonadIO m) => Scanner -> Int32 -> m ()
- data ScannerInputTextMethodInfo
- scannerInputText :: (HasCallStack, MonadIO m) => Scanner -> Text -> Word32 -> m ()
- data ScannerLookupSymbolMethodInfo
- scannerLookupSymbol :: (HasCallStack, MonadIO m) => Scanner -> Text -> m (Ptr ())
- data ScannerPeekNextTokenMethodInfo
- scannerPeekNextToken :: (HasCallStack, MonadIO m) => Scanner -> m TokenType
- data ScannerScopeAddSymbolMethodInfo
- scannerScopeAddSymbol :: (HasCallStack, MonadIO m) => Scanner -> Word32 -> Text -> Ptr () -> m ()
- data ScannerScopeLookupSymbolMethodInfo
- scannerScopeLookupSymbol :: (HasCallStack, MonadIO m) => Scanner -> Word32 -> Text -> m (Ptr ())
- data ScannerScopeRemoveSymbolMethodInfo
- scannerScopeRemoveSymbol :: (HasCallStack, MonadIO m) => Scanner -> Word32 -> Text -> m ()
- data ScannerSetScopeMethodInfo
- scannerSetScope :: (HasCallStack, MonadIO m) => Scanner -> Word32 -> m Word32
- data ScannerSyncFileOffsetMethodInfo
- scannerSyncFileOffset :: (HasCallStack, MonadIO m) => Scanner -> m ()
- data ScannerUnexpTokenMethodInfo
- scannerUnexpToken :: (HasCallStack, MonadIO m) => Scanner -> TokenType -> Text -> Text -> Text -> Text -> Int32 -> m ()
- clearScannerConfig :: MonadIO m => Scanner -> m ()
- getScannerConfig :: MonadIO m => Scanner -> m (Maybe ScannerConfig)
- scanner_config :: AttrLabelProxy "config"
- setScannerConfig :: MonadIO m => Scanner -> Ptr ScannerConfig -> m ()
- clearScannerInputName :: MonadIO m => Scanner -> m ()
- getScannerInputName :: MonadIO m => Scanner -> m (Maybe Text)
- scanner_inputName :: AttrLabelProxy "inputName"
- setScannerInputName :: MonadIO m => Scanner -> CString -> m ()
- getScannerLine :: MonadIO m => Scanner -> m Word32
- scanner_line :: AttrLabelProxy "line"
- setScannerLine :: MonadIO m => Scanner -> Word32 -> m ()
- getScannerMaxParseErrors :: MonadIO m => Scanner -> m Word32
- scanner_maxParseErrors :: AttrLabelProxy "maxParseErrors"
- setScannerMaxParseErrors :: MonadIO m => Scanner -> Word32 -> m ()
- clearScannerMsgHandler :: MonadIO m => Scanner -> m ()
- getScannerMsgHandler :: MonadIO m => Scanner -> m (Maybe ScannerMsgFunc)
- scanner_msgHandler :: AttrLabelProxy "msgHandler"
- setScannerMsgHandler :: MonadIO m => Scanner -> FunPtr C_ScannerMsgFunc -> m ()
- getScannerNextLine :: MonadIO m => Scanner -> m Word32
- scanner_nextLine :: AttrLabelProxy "nextLine"
- setScannerNextLine :: MonadIO m => Scanner -> Word32 -> m ()
- getScannerNextPosition :: MonadIO m => Scanner -> m Word32
- scanner_nextPosition :: AttrLabelProxy "nextPosition"
- setScannerNextPosition :: MonadIO m => Scanner -> Word32 -> m ()
- getScannerNextToken :: MonadIO m => Scanner -> m TokenType
- scanner_nextToken :: AttrLabelProxy "nextToken"
- setScannerNextToken :: MonadIO m => Scanner -> TokenType -> m ()
- getScannerNextValue :: MonadIO m => Scanner -> m TokenValue
- scanner_nextValue :: AttrLabelProxy "nextValue"
- getScannerParseErrors :: MonadIO m => Scanner -> m Word32
- scanner_parseErrors :: AttrLabelProxy "parseErrors"
- setScannerParseErrors :: MonadIO m => Scanner -> Word32 -> m ()
- getScannerPosition :: MonadIO m => Scanner -> m Word32
- scanner_position :: AttrLabelProxy "position"
- setScannerPosition :: MonadIO m => Scanner -> Word32 -> m ()
- clearScannerQdata :: MonadIO m => Scanner -> m ()
- getScannerQdata :: MonadIO m => Scanner -> m (Maybe Data)
- scanner_qdata :: AttrLabelProxy "qdata"
- setScannerQdata :: MonadIO m => Scanner -> Ptr Data -> m ()
- getScannerToken :: MonadIO m => Scanner -> m TokenType
- scanner_token :: AttrLabelProxy "token"
- setScannerToken :: MonadIO m => Scanner -> TokenType -> m ()
- clearScannerUserData :: MonadIO m => Scanner -> m ()
- getScannerUserData :: MonadIO m => Scanner -> m (Ptr ())
- scanner_userData :: AttrLabelProxy "userData"
- setScannerUserData :: MonadIO m => Scanner -> Ptr () -> m ()
- getScannerValue :: MonadIO m => Scanner -> m TokenValue
- scanner_value :: AttrLabelProxy "value"
Exported types
Methods
curLine
data ScannerCurLineMethodInfo Source #
((~) * signature (m Word32), MonadIO m) => MethodInfo * ScannerCurLineMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> 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
data ScannerCurPositionMethodInfo Source #
((~) * signature (m Word32), MonadIO m) => MethodInfo * ScannerCurPositionMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> 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
data ScannerCurTokenMethodInfo Source #
((~) * signature (m TokenType), MonadIO m) => MethodInfo * ScannerCurTokenMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> m TokenType | Returns: the current token type |
Gets the current token type. This is simply the token
field in the Scanner
structure.
destroy
data ScannerDestroyMethodInfo Source #
((~) * signature (m ()), MonadIO m) => MethodInfo * ScannerDestroyMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> m () |
Frees all memory used by the Scanner
.
eof
data ScannerEofMethodInfo Source #
((~) * signature (m Bool), MonadIO m) => MethodInfo * ScannerEofMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> m Bool | Returns: |
Returns True
if the scanner has reached the end of
the file or text buffer.
getNextToken
data ScannerGetNextTokenMethodInfo Source #
((~) * signature (m TokenType), MonadIO m) => MethodInfo * ScannerGetNextTokenMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> 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
data ScannerInputFileMethodInfo Source #
((~) * signature (Int32 -> m ()), MonadIO m) => MethodInfo * ScannerInputFileMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> Int32 |
|
-> m () |
Prepares to scan a file.
inputText
data ScannerInputTextMethodInfo Source #
((~) * signature (Text -> Word32 -> m ()), MonadIO m) => MethodInfo * ScannerInputTextMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> Text |
|
-> Word32 |
|
-> m () |
Prepares to scan a text buffer.
lookupSymbol
data ScannerLookupSymbolMethodInfo Source #
((~) * signature (Text -> m (Ptr ())), MonadIO m) => MethodInfo * ScannerLookupSymbolMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> Text |
|
-> m (Ptr ()) | Returns: the value of |
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
data ScannerPeekNextTokenMethodInfo Source #
((~) * signature (m TokenType), MonadIO m) => MethodInfo * ScannerPeekNextTokenMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> 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 #
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> Word32 |
|
-> Text |
|
-> Ptr () |
|
-> m () |
Adds a symbol to the given scope.
scopeLookupSymbol
scannerScopeLookupSymbol Source #
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> Word32 |
|
-> Text |
|
-> m (Ptr ()) | Returns: the value of |
Looks up a symbol in a scope and return its value. If the
symbol is not bound in the scope, Nothing
is returned.
scopeRemoveSymbol
data ScannerScopeRemoveSymbolMethodInfo Source #
((~) * signature (Word32 -> Text -> m ()), MonadIO m) => MethodInfo * ScannerScopeRemoveSymbolMethodInfo Scanner signature Source # | |
scannerScopeRemoveSymbol Source #
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> Word32 |
|
-> Text |
|
-> m () |
Removes a symbol from a scope.
setScope
data ScannerSetScopeMethodInfo Source #
((~) * signature (Word32 -> m Word32), MonadIO m) => MethodInfo * ScannerSetScopeMethodInfo Scanner signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> Word32 |
|
-> m Word32 | Returns: the old scope id |
Sets the current scope.
syncFileOffset
data ScannerSyncFileOffsetMethodInfo Source #
((~) * signature (m ()), MonadIO m) => MethodInfo * ScannerSyncFileOffsetMethodInfo Scanner signature Source # | |
scannerSyncFileOffset Source #
:: (HasCallStack, MonadIO m) | |
=> 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
:: (HasCallStack, MonadIO m) | |
=> Scanner |
|
-> TokenType |
|
-> Text |
|
-> Text |
|
-> Text |
|
-> Text |
|
-> Int32 |
|
-> 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
clearScannerConfig :: MonadIO m => Scanner -> m () Source #
getScannerConfig :: MonadIO m => Scanner -> m (Maybe ScannerConfig) Source #
scanner_config :: AttrLabelProxy "config" Source #
setScannerConfig :: MonadIO m => Scanner -> Ptr ScannerConfig -> m () Source #
inputName
clearScannerInputName :: MonadIO m => Scanner -> m () Source #
scanner_inputName :: AttrLabelProxy "inputName" Source #
line
scanner_line :: AttrLabelProxy "line" Source #
maxParseErrors
scanner_maxParseErrors :: AttrLabelProxy "maxParseErrors" Source #
msgHandler
clearScannerMsgHandler :: MonadIO m => Scanner -> m () Source #
getScannerMsgHandler :: MonadIO m => Scanner -> m (Maybe ScannerMsgFunc) Source #
scanner_msgHandler :: AttrLabelProxy "msgHandler" Source #
setScannerMsgHandler :: MonadIO m => Scanner -> FunPtr C_ScannerMsgFunc -> m () Source #
nextLine
scanner_nextLine :: AttrLabelProxy "nextLine" Source #
nextPosition
scanner_nextPosition :: AttrLabelProxy "nextPosition" Source #
nextToken
scanner_nextToken :: AttrLabelProxy "nextToken" Source #
nextValue
getScannerNextValue :: MonadIO m => Scanner -> m TokenValue Source #
scanner_nextValue :: AttrLabelProxy "nextValue" Source #
parseErrors
scanner_parseErrors :: AttrLabelProxy "parseErrors" Source #
position
scanner_position :: AttrLabelProxy "position" Source #
qdata
clearScannerQdata :: MonadIO m => Scanner -> m () Source #
scanner_qdata :: AttrLabelProxy "qdata" Source #
token
scanner_token :: AttrLabelProxy "token" Source #
userData
clearScannerUserData :: MonadIO m => Scanner -> m () Source #
scanner_userData :: AttrLabelProxy "userData" Source #
value
getScannerValue :: MonadIO m => Scanner -> m TokenValue Source #
scanner_value :: AttrLabelProxy "value" Source #