Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Lexer for SQL.
Synopsis
- data Token
- data WithPos a = WithPos {}
- lexSQL :: Dialect -> Bool -> Text -> Maybe (Int, Int) -> Text -> Either ParseError [Token]
- lexSQLWithPositions :: Dialect -> Bool -> Text -> Maybe (Int, Int) -> Text -> Either ParseError [WithPos Token]
- prettyToken :: Dialect -> Token -> Text
- prettyTokens :: Dialect -> [Token] -> Text
- type ParseError = ParseErrorBundle Text Void
- prettyError :: ParseError -> Text
- tokenListWillPrintAndLex :: Dialect -> [Token] -> Bool
- ansi2011 :: Dialect
- data SQLStream = SQLStream {
- sqlStreamInput :: String
- unSQLStream :: [WithPos Token]
Documentation
Represents a lexed token
Symbol Text | A symbol (in ansi dialect) is one of the following |
Identifier (Maybe (Text, Text)) Text | This is an identifier or keyword. The first field is the quotes used, or nothing if no quotes were used. The quotes can be " or u& or something dialect specific like [] |
PrefixedVariable Char Text | This is a prefixed variable symbol, such as :var, @var or #var (only :var is used in ansi dialect) |
PositionalArg Int | This is a positional arg identifier e.g. $1 |
SqlString Text Text Text | This is a string literal. The first two fields are the -- start and end quotes, which are usually both ', but can be the character set (one of nNbBxX, or u&, U&), or a dialect specific string quoting (such as $$ in postgres) |
SqlNumber Text | A number literal (integral or otherwise), stored in original format unchanged |
Whitespace Text | Whitespace, one or more of space, tab or newline. |
LineComment Text | A commented line using --, contains every character starting with the '--' and including the terminating newline character if there is one - this will be missing if the last line in the source is a line comment with no trailing newline |
BlockComment Text | A block comment, /* stuff */, includes the comment delimiters |
InvalidToken Text | Used for generating better error messages when using the output of the lexer in a parser |
Positional information added to tokens to preserve source positions for the parser
:: Dialect | dialect of SQL to use |
-> Bool | produce InvalidToken, see lexSQLWithPositions |
-> Text | filename to use in error messages |
-> Maybe (Int, Int) | line number and column number of the first character in the source to use in error messages |
-> Text | the SQL source to lex |
-> Either ParseError [Token] |
Lex some SQL to a list of tokens.
:: Dialect | dialect of SQL to use |
-> Bool | produce InvalidToken |
-> Text | filename to use in error messages |
-> Maybe (Int, Int) | line number and column number of the first character in the source to use in error messages |
-> Text | the SQL source to lex |
-> Either ParseError [WithPos Token] |
Lex some SQL to a list of tokens. The invalid token setting changes the behaviour so that if there's a parse error at the start of parsing an invalid token, it adds a final InvalidToken with the character to the result then stop parsing. This can then be used to produce a parse error with more context in the parser. Parse errors within tokens still produce Left errors.
prettyToken :: Dialect -> Token -> Text Source #
Pretty printing, if you lex a bunch of tokens, then pretty print them, should should get back exactly the same string
type ParseError = ParseErrorBundle Text Void Source #
prettyError :: ParseError -> Text Source #
tokenListWillPrintAndLex :: Dialect -> [Token] -> Bool Source #
Utility function to tell you if a list of tokens will pretty print then lex back to the same set of tokens. Used internally, might be useful for generating SQL via lexical tokens.
Wrapper to allow using the lexer as input to a megaparsec parser.
SQLStream | |
|
Instances
Stream SQLStream Source # | |||||||||
Defined in Language.SQL.SimpleSQL.Lex
tokenToChunk :: Proxy SQLStream -> Token SQLStream -> Tokens SQLStream # tokensToChunk :: Proxy SQLStream -> [Token SQLStream] -> Tokens SQLStream # chunkToTokens :: Proxy SQLStream -> Tokens SQLStream -> [Token SQLStream] # chunkLength :: Proxy SQLStream -> Tokens SQLStream -> Int # chunkEmpty :: Proxy SQLStream -> Tokens SQLStream -> Bool # take1_ :: SQLStream -> Maybe (Token SQLStream, SQLStream) # takeN_ :: Int -> SQLStream -> Maybe (Tokens SQLStream, SQLStream) # takeWhile_ :: (Token SQLStream -> Bool) -> SQLStream -> (Tokens SQLStream, SQLStream) # | |||||||||
TraversableStream SQLStream Source # | |||||||||
VisualStream SQLStream Source # | |||||||||
type Token SQLStream Source # | |||||||||
Defined in Language.SQL.SimpleSQL.Lex | |||||||||
type Tokens SQLStream Source # | |||||||||
Defined in Language.SQL.SimpleSQL.Lex |