Copyright | (c) Eric Mertens 2023 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module provides a custom engine for the Alex generated lexer. This lexer drive provides nested states, unicode support, and file location tracking.
The various states of this module are needed to deal with the varying lexing rules while lexing values, keys, and string-literals.
Synopsis
- type Action = Located String -> State [Context] [Located Token]
- data Context
- locatedUncons :: Located String -> Maybe (Int, Located String)
- value :: (String -> Token) -> Action
- value_ :: Token -> Action
- token :: (String -> Token) -> Action
- token_ :: Token -> Action
- squareO :: Action
- squareC :: Action
- curlyO :: Action
- curlyC :: Action
- equals :: Action
- timeValue :: ParseTime a => String -> [String] -> (a -> Token) -> Action
- eofToken :: [Context] -> Located String -> Located Token
- strFrag :: Action
- startMlStr :: Action
- startStr :: Action
- endStr :: Action
- unicodeEscape :: Action
Types
type Action = Located String -> State [Context] [Located Token] Source #
Type of actions associated with lexer patterns
Representation of the current lexer state.
ListContext Position | processing an inline list, lex values |
TableContext Position | processing an inline table, don't lex values |
ValueContext | processing after an equals, lex one value |
MlStrContext Position [String] | position of opening delimiter and list of fragments |
StrContext Position [String] | position of opening delimiter and list of fragments |
Input processing
locatedUncons :: Located String -> Maybe (Int, Located String) Source #
Pop the first character off a located string if it's not empty.
The resulting Int
will either be the ASCII value of the character
or 1
for non-ASCII Unicode values. To avoid a clash, x1
is
remapped to 0
.
Actions
value :: (String -> Token) -> Action Source #
Emit a value token using the current lexeme and update the current state
:: ParseTime a | |
=> String | description for error messages |
-> [String] | possible valid patterns |
-> (a -> Token) | token constructor |
-> Action |
Attempt to parse the current lexeme as a date-time token.
eofToken :: [Context] -> Located String -> Located Token Source #
Generate the correct terminating token given the current lexer state.
String literals
startMlStr :: Action Source #
Start a multi-line basic string literal
unicodeEscape :: Action Source #
Resolve a unicode escape sequence and add it to the current string literal