hssqlppp-0.5.18: SQL parser and type checker

Safe HaskellSafe
LanguageHaskell2010

Database.HsSqlPpp.LexicalSyntax

Synopsis

Documentation

data Token

Represents a lexed token

Constructors

Symbol Text

a symbol in postgresql dialect is one of the following:

  • one of the characters (),;[]
  • '..' or ':=' or '.' or ':'
  • a compound symbol, which starts with one of '*/<>=~!@%^&|`?'

things that are not lexed as symbols:

  • [] used in quoted identifiers, prefix @,#,: used in identifiers
  • $n positional arg
Identifier (Maybe (Char, Char)) Text

This is an identifier or keyword.

The 'Maybe (Char,Char)' selects the quoted style - Nothing means the identifier was unquoted otherwise the two characters are the start and end quote.

'"' is used to quote identifiers in standard sql, sql server also uses [brackets] to quote identifiers.

The identifier also includes the 'variable marker prefix' used in sql server (e.g. @identifier, #identifier), and oracle (e.g. :identifier)

SqlString Text Text

This is a string literal.

The first field is the quotes used: single quote (') for normal strings, E' for escape supporting strings, and $$ delimiter for postgresql dollar quoted strings.

The lexer doesn't process the escapes in strings, but passes on the literal source e.g. E'\n' parses to SqlString "E'" "\n" with the literal characters '\' and 'n' in the string, not a newline character. quotes within a string ('') or escaped string ('' or \') are passed through unchanged

SqlNumber Text

a number literal (integral or otherwise), stored in original format unchanged

Whitespace Text

non-significant whitespace (space, tab, newline) (strictly speaking, it is up to the client to decide whether the whitespace is significant or not)

PositionalArg Int

a postgresql positional arg, e.g. $1

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

Splice Char Text

an antiquotation splice, e.g. $x(stuff)

CopyPayload Text

the copy data in a copy from stdin

Instances

prettyToken :: SQLSyntaxDialect -> Token -> Text

Accurate pretty printing, if you lex a bunch of tokens, then pretty print them, should should get back exactly the same string

sqlToken :: SQLSyntaxDialect -> Parser ((FilePath, Int, Int), Token)

parser for a sql token

sqlTokens :: SQLSyntaxDialect -> FilePath -> Maybe (Int, Int) -> Text -> Either ParseError [((FilePath, Int, Int), Token)]