Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- initialInput :: Text -> ByteString -> Input
- data Input = Input {
- inputPos :: !SourcePos
- inputBytes :: !ByteString
- inputPrev :: !SourcePos
- inputPrevByte :: !Word8
- inputFile :: Input -> Text
- data Lexeme t = Lexeme {
- lexemeBytes :: !ByteString
- lexemeToken :: !t
- lexemeRange :: !SourceRange
- data SourcePos = SourcePos {
- sourceIndex :: !Int
- sourceFile :: !Text
- startPos :: Text -> SourcePos
- beforeStartPos :: Text -> SourcePos
- prevPos :: SourcePos -> SourcePos
- data SourceRange = SourceRange {
- sourceFrom :: !SourcePos
- sourceTo :: !SourcePos
- prettySourcePos :: SourcePos -> String
- prettySourceRange :: SourceRange -> String
- prettySourcePosLong :: SourcePos -> String
- prettySourceRangeLong :: SourceRange -> String
- class HasRange t where
- range :: t -> SourceRange
- (<->) :: (HasRange a, HasRange b) => a -> b -> SourceRange
- moveSourcePos :: SourcePos -> SourcePos
- newtype Action s a = A {}
- lexeme :: t -> Action s [Lexeme t]
- matchLength :: Action s Int
- matchRange :: Action s SourceRange
- matchBytes :: Action s ByteString
- getLexerState :: Action s s
- setLexerState :: s -> Action s ()
- startInput :: Action s Input
- endInput :: Action s Input
- type AlexInput = Input
- alexInputPrevChar :: AlexInput -> Char
- alexGetByte :: AlexInput -> Maybe (Word8, AlexInput)
- makeLexer :: ExpQ
- data LexerConfig s t = LexerConfig {
- lexerInitialState :: s
- lexerStateMode :: s -> Int
- lexerEOF :: s -> SourcePos -> [Lexeme t]
- simpleLexer :: LexerConfig () t
- data Word8
Lexer Basics
:: Text | Where the text came from |
-> ByteString | The text to lex |
-> Input |
Prepare the text for lexing.
Information about the lexer's input.
Input | |
|
Lexeme | |
|
SourcePos | |
|
beforeStartPos :: Text -> SourcePos Source #
prevPos :: SourcePos -> SourcePos Source #
Move one position back. Assumes that newlines use a single bytes.
This function is intended to be used when starting the lexing somewhere in the middle of the input, for example, if we are implementing a quasi quoter, and the previous part of the input is not in our language.
data SourceRange Source #
A range in the source code.
SourceRange | |
|
Instances
HasRange SourceRange Source # | |
Defined in AlexToolsBin range :: SourceRange -> SourceRange Source # | |
Show SourceRange Source # | |
Defined in AlexToolsBin showsPrec :: Int -> SourceRange -> ShowS # show :: SourceRange -> String # showList :: [SourceRange] -> ShowS # | |
NFData SourceRange Source # | |
Defined in AlexToolsBin rnf :: SourceRange -> () # | |
Eq SourceRange Source # | |
Defined in AlexToolsBin (==) :: SourceRange -> SourceRange -> Bool # (/=) :: SourceRange -> SourceRange -> Bool # |
prettySourcePos :: SourcePos -> String Source #
Pretty print the source position without the file name.
prettySourceRange :: SourceRange -> String Source #
Pretty print the range, without the file name
prettySourcePosLong :: SourcePos -> String Source #
Pretty print the source position, including the file name.
prettySourceRangeLong :: SourceRange -> String Source #
Pretty print the range, including the file name.
class HasRange t where Source #
range :: t -> SourceRange Source #
Instances
HasRange SourcePos Source # | |
Defined in AlexToolsBin range :: SourcePos -> SourceRange Source # | |
HasRange SourceRange Source # | |
Defined in AlexToolsBin range :: SourceRange -> SourceRange Source # | |
HasRange (Lexeme t) Source # | |
Defined in AlexToolsBin range :: Lexeme t -> SourceRange Source # | |
(HasRange a, HasRange b) => HasRange (Either a b) Source # | |
Defined in AlexToolsBin range :: Either a b -> SourceRange Source # |
moveSourcePos :: SourcePos -> SourcePos Source #
Update a SourcePos
for a particular matched character
Writing Lexer Actions
An action to be taken when a regular expression matchers.
Lexemes
lexeme :: t -> Action s [Lexeme t] Source #
Use the token and the current match to construct a lexeme.
matchLength :: Action s Int Source #
The number of characters in the matching input.
matchRange :: Action s SourceRange Source #
Get the range for the matching input.
matchBytes :: Action s ByteString Source #
Get the text associated with the matched input.
Manipulating the lexer's state
getLexerState :: Action s s Source #
Acces the curent state of the lexer.
setLexerState :: s -> Action s () Source #
Change the state of the lexer.
Access to the lexer's input
startInput :: Action s Input Source #
Acces the input just before the regular expression started matching.
Interface with Alex
alexInputPrevChar :: AlexInput -> Char Source #
Generate a function to use an Alex lexer.
The expression is of type LexerConfig s t -> Input -> [Lexeme t]
data LexerConfig s t Source #
Lexer configuration.
LexerConfig | |
|
simpleLexer :: LexerConfig () t Source #
A lexer that uses no lexer-modes, and does not emit anything at the end of the file.
8-bit unsigned integer type