= TOC:

notes
Public api
Names - parsing identifiers
Typenames
Scalar expressions
  simple literals
  star, param
  parens expression, row constructor and scalar subquery
  case, cast, exists, unique, array/ multiset constructor
  typed literal, app, special function, aggregate, window function
  suffixes: in, between, quantified comparison, match predicate, array
    subscript, escape, collate
  operators
  scalar expression top level
  helpers
query expressions
  select lists
  from clause
  other table expression clauses:
    where, group by, having, order by, offset and fetch
  common table expressions
  query expression
  set operations
lexers
utilities

= Notes about the code

The lexers appear at the bottom of the file. There tries to be a clear
separation between the lexers and the other parser which only use the
lexers, this isn't 100% complete at the moment and needs fixing.

== Left factoring

The parsing code is aggressively left factored, and try is avoided as
much as possible. Try is avoided because:

 * when it is overused it makes the code hard to follow
 * when it is overused it makes the parsing code harder to debug
 * it makes the parser error messages much worse

The code could be made a bit simpler with a few extra 'trys', but this
isn't done because of the impact on the parser error
messages. Apparently it can also help the speed but this hasn't been
looked into.

== Parser error messages

A lot of care has been given to generating good parser error messages
for invalid syntax. There are a few utils below which partially help
in this area.

There is a set of crafted bad expressions in ErrorMessages.lhs, these
are used to guage the quality of the error messages and monitor
regressions by hand. The use of <?> is limited as much as possible:
each instance should justify itself by improving an actual error
message.

There is also a plan to write a really simple expression parser which
doesn't do precedence and associativity, and the fix these with a pass
over the ast. I don't think there is any other way to sanely handle
the common prefixes between many infix and postfix multiple keyword
operators, and some other ambiguities also. This should help a lot in
generating good error messages also.

Both the left factoring and error message work are greatly complicated
by the large number of shared prefixes of the various elements in SQL
syntax.

== Main left factoring issues

There are three big areas which are tricky to left factor:

 * typenames
 * scalar expressions which can start with an identifier
 * infix and suffix operators

=== typenames

There are a number of variations of typename syntax. The standard
deals with this by switching on the name of the type which is parsed
first. This code doesn't do this currently, but might in the
future. Taking the approach in the standard grammar will limit the
extensibility of the parser and might affect the ease of adapting to
support other sql dialects.

=== identifier scalar expressions

There are a lot of scalar expression nodes which start with
identifiers, and can't be distinguished the tokens after the initial
identifier are parsed. Using try to implement these variations is very
simple but makes the code much harder to debug and makes the parser
error messages really bad.

Here is a list of these nodes:

 * identifiers
 * function application
 * aggregate application
 * window application
 * typed literal: typename 'literal string'
 * interval literal which is like the typed literal with some extras

There is further ambiguity e.g. with typed literals with precision,
functions, aggregates, etc. - these are an identifier, followed by
parens comma separated scalar expressions or something similar, and it
is only later that we can find a token which tells us which flavour it
is.

There is also a set of nodes which start with an identifier/keyword
but can commit since no other syntax can start the same way:

 * case
 * cast
 * exists, unique subquery
 * array constructor
 * multiset constructor
 * all the special syntax functions: extract, position, substring,
  convert, translate, overlay, trim, etc.

The interval literal mentioned above is treated in this group at the
moment: if we see 'interval' we parse it either as a full interval
literal or a typed literal only.

Some items in this list might have to be fixed in the future, e.g. to
support standard 'substring(a from 3 for 5)' as well as regular
function substring syntax 'substring(a,3,5) at the same time.

The work in left factoring all this is mostly done, but there is still
a substantial bit to complete and this is by far the most difficult
bit. At the moment, the work around is to use try, the downsides of
which is the poor parsing error messages.

=== infix and suffix operators

== permissiveness

The parser is very permissive in many ways. This departs from the
standard which is able to eliminate a number of possibilities just in
the grammar, which this parser allows. This is done for a number of
reasons:

 * it makes the parser simple - less variations
 * it should allow for dialects and extensibility more easily in the
  future (e.g. new infix binary operators with custom precedence)
 * many things which are effectively checked in the grammar in the
  standard, can be checked using a typechecker or other simple static
  analysis

To use this code as a front end for a sql engine, or as a sql validity
checker, you will need to do a lot of checks on the ast. A
typechecker/static checker plus annotation to support being a compiler
front end is planned but not likely to happen too soon.

Some of the areas this affects:

typenames: the variation of the type name should switch on the actual
name given according to the standard, but this code only does this for
the special case of interval type names. E.g. you can write 'int
collate C' or 'int(15,2)' and this will parse as a character type name
or a precision scale type name instead of being rejected.

scalar expressions: every variation on scalar expressions uses the same
parser/syntax. This means we don't try to stop non boolean valued
expressions in boolean valued contexts in the parser. Another area
this affects is that we allow general scalar expressions in group by,
whereas the standard only allows column names with optional collation.

These are all areas which are specified (roughly speaking) in the
syntax rather than the semantics in the standard, and we are not
fixing them in the syntax but leaving them till the semantic checking
(which doesn't exist in this code at this time).

> {-# LANGUAGE TupleSections #-}
> -- | This is the module with the parser functions.
> module Language.SQL.SimpleSQL.Parse
>     (parseQueryExpr
>     ,parseScalarExpr
>     ,parseStatement
>     ,parseStatements
>     ,ParseError(..)) where

> import Control.Monad.Identity (Identity)
> import Control.Monad (guard, void)
> import Control.Applicative ((<**>))
> import Data.Char (toLower, isDigit)
> import Text.Parsec (setPosition,setSourceColumn,setSourceLine,getPosition
>                    ,option,between,sepBy,sepBy1
>                    ,try,many,many1,(<|>),choice,eof
>                    ,optionMaybe,optional,runParser
>                    ,chainl1, chainr1,(<?>))
> import Text.Parsec.Perm (permute,(<$?>), (<|?>))
> import Text.Parsec.Prim (getState, token)
> import Text.Parsec.Pos (newPos)
> import qualified Text.Parsec.Expr as E
> import Data.List (intercalate,sort,groupBy)
> import Data.Function (on)
> import Data.Maybe
> import Text.Parsec.String (GenParser)

> import Language.SQL.SimpleSQL.Syntax
> import Language.SQL.SimpleSQL.Combinators
> import Language.SQL.SimpleSQL.Errors
> import Language.SQL.SimpleSQL.Dialect
> import qualified Language.SQL.SimpleSQL.Lex as L


= Public API

> -- | Parses a query expr, trailing semicolon optional.
> parseQueryExpr :: Dialect
>                   -- ^ dialect of SQL to use
>                -> FilePath
>                   -- ^ 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
>                -> String
>                   -- ^ the SQL source to parse
>                -> Either ParseError QueryExpr
> parseQueryExpr :: Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError QueryExpr
parseQueryExpr = Parser QueryExpr
-> Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError QueryExpr
forall a.
Parser a
-> Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError a
wrapParse Parser QueryExpr
topLevelQueryExpr

> -- | Parses a statement, trailing semicolon optional.
> parseStatement :: Dialect
>                   -- ^ dialect of SQL to use
>                -> FilePath
>                   -- ^ 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
>                -> String
>                   -- ^ the SQL source to parse
>                -> Either ParseError Statement
> parseStatement :: Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError Statement
parseStatement = Parser Statement
-> Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError Statement
forall a.
Parser a
-> Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError a
wrapParse Parser Statement
topLevelStatement


> -- | Parses a list of statements, with semi colons between
> -- them. The final semicolon is optional.
> parseStatements :: Dialect
>                   -- ^ dialect of SQL to use
>                 -> FilePath
>                    -- ^ 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
>                 -> String
>                    -- ^ the SQL source to parse
>                 -> Either ParseError [Statement]
> parseStatements :: Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError [Statement]
parseStatements = Parser [Statement]
-> Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError [Statement]
forall a.
Parser a
-> Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError a
wrapParse Parser [Statement]
statements

> -- | Parses a scalar expression.
> parseScalarExpr :: Dialect
>                    -- ^ dialect of SQL to use
>                 -> FilePath
>                    -- ^ 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
>                 -> String
>                    -- ^ the SQL source to parse
>                 -> Either ParseError ScalarExpr
> parseScalarExpr :: Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError ScalarExpr
parseScalarExpr = Parser ScalarExpr
-> Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError ScalarExpr
forall a.
Parser a
-> Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError a
wrapParse Parser ScalarExpr
scalarExpr

This helper function takes the parser given and:

sets the position when parsing
automatically skips leading whitespace
checks the parser parses all the input using eof
converts the error return to the nice wrapper

> wrapParse :: Parser a
>           -> Dialect
>           -> FilePath
>           -> Maybe (Int,Int)
>           -> String
>           -> Either ParseError a
> wrapParse :: Parser a
-> Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError a
wrapParse parser :: Parser a
parser d :: Dialect
d f :: FilePath
f p :: Maybe (Int, Int)
p src :: FilePath
src = do
>     let (l :: Int
l,c :: Int
c) = (Int, Int) -> Maybe (Int, Int) -> (Int, Int)
forall a. a -> Maybe a -> a
fromMaybe (1,1) Maybe (Int, Int)
p
>     [((FilePath, Int, Int), Token)]
lx <- Dialect
-> FilePath
-> Maybe (Int, Int)
-> FilePath
-> Either ParseError [((FilePath, Int, Int), Token)]
L.lexSQL Dialect
d FilePath
f ((Int, Int) -> Maybe (Int, Int)
forall a. a -> Maybe a
Just (Int
l,Int
c)) FilePath
src
>     (ParseError -> Either ParseError a)
-> (a -> Either ParseError a)
-> Either ParseError a
-> Either ParseError a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ParseError -> Either ParseError a
forall a b. a -> Either a b
Left (ParseError -> Either ParseError a)
-> (ParseError -> ParseError) -> ParseError -> Either ParseError a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ParseError -> ParseError
convParseError FilePath
src) a -> Either ParseError a
forall a b. b -> Either a b
Right
>       (Either ParseError a -> Either ParseError a)
-> Either ParseError a -> Either ParseError a
forall a b. (a -> b) -> a -> b
$ Parser a
-> Dialect
-> FilePath
-> [((FilePath, Int, Int), Token)]
-> Either ParseError a
forall s t u a.
Stream s Identity t =>
Parsec s u a -> u -> FilePath -> s -> Either ParseError a
runParser (Maybe (Int, Int)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (m :: * -> *) s u.
Monad m =>
Maybe (Int, Int) -> ParsecT s u m ()
setPos Maybe (Int, Int)
p ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser a -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser a
parser Parser a
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof)
>                   Dialect
d FilePath
f ([((FilePath, Int, Int), Token)] -> Either ParseError a)
-> [((FilePath, Int, Int), Token)] -> Either ParseError a
forall a b. (a -> b) -> a -> b
$ (((FilePath, Int, Int), Token) -> Bool)
-> [((FilePath, Int, Int), Token)]
-> [((FilePath, Int, Int), Token)]
forall a. (a -> Bool) -> [a] -> [a]
filter ((FilePath, Int, Int), Token) -> Bool
forall a. (a, Token) -> Bool
keep [((FilePath, Int, Int), Token)]
lx
>   where
>     setPos :: Maybe (Int, Int) -> ParsecT s u m ()
setPos Nothing = () -> ParsecT s u m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
>     setPos (Just (l :: Int
l,c :: Int
c)) = (SourcePos -> SourcePos)
-> ParsecT s u m SourcePos -> ParsecT s u m SourcePos
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SourcePos -> SourcePos
up ParsecT s u m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition ParsecT s u m SourcePos
-> (SourcePos -> ParsecT s u m ()) -> ParsecT s u m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= SourcePos -> ParsecT s u m ()
forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition
>       where up :: SourcePos -> SourcePos
up = (SourcePos -> Int -> SourcePos) -> Int -> SourcePos -> SourcePos
forall a b c. (a -> b -> c) -> b -> a -> c
flip SourcePos -> Int -> SourcePos
setSourceColumn Int
c (SourcePos -> SourcePos)
-> (SourcePos -> SourcePos) -> SourcePos -> SourcePos
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SourcePos -> Int -> SourcePos) -> Int -> SourcePos -> SourcePos
forall a b c. (a -> b -> c) -> b -> a -> c
flip SourcePos -> Int -> SourcePos
setSourceLine Int
l
>     keep :: (a, Token) -> Bool
keep (_,L.Whitespace {}) = Bool
False
>     keep (_,L.LineComment {}) = Bool
False
>     keep (_,L.BlockComment {}) = Bool
False
>     keep _ = Bool
True


------------------------------------------------

= Names

Names represent identifiers and a few other things. The parser here
handles regular identifiers, dotten chain identifiers, quoted
identifiers and unicode quoted identifiers.

Dots: dots in identifier chains are parsed here and represented in the
Iden constructor usually. If parts of the chains are non identifier
scalar expressions, then this is represented by a BinOp "."
instead. Dotten chain identifiers which appear in other contexts (such
as function names, table names, are represented as [Name] only.

Identifier grammar:

unquoted:
underscore <|> letter : many (underscore <|> alphanum

example
_example123

quoted:

double quote, many (non quote character or two double quotes
together), double quote

"example quoted"
"example with "" quote"

unicode quoted is the same as quoted in this parser, except it starts
with U& or u&

u&"example quoted"

> name :: Parser Name
> name :: Parser Name
name = do
>     Dialect
d <- ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Dialect
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
>     (Maybe (FilePath, FilePath) -> FilePath -> Name)
-> (Maybe (FilePath, FilePath), FilePath) -> Name
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Maybe (FilePath, FilePath) -> FilePath -> Name
Name ((Maybe (FilePath, FilePath), FilePath) -> Name)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (FilePath, FilePath), FilePath)
-> Parser Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (FilePath, FilePath), FilePath)
identifierTok (Dialect -> [FilePath]
blacklist Dialect
d)

todo: replace (:[]) with a named function all over

> names :: Parser [Name]
> names :: Parser [Name]
names = [Name] -> [Name]
forall a. [a] -> [a]
reverse ([Name] -> [Name]) -> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (((Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[]) (Name -> [Name]) -> Parser Name -> Parser [Name]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
name) Parser [Name]
-> GenParser
     ((FilePath, Int, Int), Token) Dialect ([Name] -> [Name])
-> Parser [Name]
forall t s a.
GenParser t s a -> GenParser t s (a -> a) -> GenParser t s a
<??*> GenParser ((FilePath, Int, Int), Token) Dialect ([Name] -> [Name])
anotherName)
>   -- can't use a simple chain here since we
>   -- want to wrap the . + name in a try
>   -- this will change when this is left factored
>   where
>     anotherName :: Parser ([Name] -> [Name])
>     anotherName :: GenParser ((FilePath, Int, Int), Token) Dialect ([Name] -> [Name])
anotherName = GenParser ((FilePath, Int, Int), Token) Dialect ([Name] -> [Name])
-> GenParser
     ((FilePath, Int, Int), Token) Dialect ([Name] -> [Name])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ((:) (Name -> [Name] -> [Name])
-> Parser Name
-> GenParser
     ((FilePath, Int, Int), Token) Dialect ([Name] -> [Name])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FilePath -> Parser FilePath
symbol "." Parser FilePath -> Parser Name -> Parser Name
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name
name))

= Type Names

Typenames are used in casts, and also in the typed literal syntax,
which is a typename followed by a string literal.

Here are the grammar notes:

== simple type name

just an identifier chain or a multi word identifier (this is a fixed
list of possibilities, e.g. as 'character varying', see below in the
parser code for the exact list).

<simple-type-name> ::= <identifier-chain>
     | multiword-type-identifier

== Precision type name

<precision-type-name> ::= <simple-type-name> <left paren> <unsigned-int> <right paren>

e.g. char(5)

note: above and below every where a simple type name can appear, this
means a single identifier/quoted or a dotted chain, or a multi word
identifier

== Precision scale type name

<precision-type-name> ::= <simple-type-name> <left paren> <unsigned-int> <comma> <unsigned-int> <right paren>

e.g. decimal(15,2)

== Lob type name

this is a variation on the precision type name with some extra info on
the units:

<lob-type-name> ::=
   <simple-type-name> <left paren> <unsigned integer> [ <multiplier> ] [ <char length units> ] <right paren>

<multiplier>    ::=   K | M | G
<char length units>    ::=   CHARACTERS | CODE_UNITS | OCTETS

(if both multiplier and char length units are missing, then this will
parse as a precision type name)

e.g.
clob(5M octets)

== char type name

this is a simple type with optional precision which allows the
character set or the collation to appear as a suffix:

<char type name> ::=
    <simple type name>
    [ <left paren> <unsigned-int> <right paren> ]
    [ CHARACTER SET <identifier chain> ]
    [ COLLATE <identifier chain> ]

e.g.

char(5) character set my_charset collate my_collation

= Time typename

this is typename with optional precision and either 'with time zone'
or 'without time zone' suffix, e.g.:

<datetime type> ::=
    [ <left paren> <unsigned-int> <right paren> ]
    <with or without time zone>
<with or without time zone> ::= WITH TIME ZONE | WITHOUT TIME ZONE
    WITH TIME ZONE | WITHOUT TIME ZONE

= row type name

<row type> ::=
    ROW <left paren> <field definition> [ { <comma> <field definition> }... ] <right paren>

<field definition> ::= <identifier> <type name>

e.g.
row(a int, b char(5))

= interval type name

<interval type> ::= INTERVAL <interval datetime field> [TO <interval datetime field>]

<interval datetime field> ::=
  <datetime field> [ <left paren> <unsigned int> [ <comma> <unsigned int> ] <right paren> ]

= array type name

<array type> ::= <data type> ARRAY [ <left bracket> <unsigned integer> <right bracket> ]

= multiset type name

<multiset type>    ::=   <data type> MULTISET

A type name will parse into the 'smallest' constructor it will fit in
syntactically, e.g. a clob(5) will parse to a precision type name, not
a lob type name.

Unfortunately, to improve the error messages, there is a lot of (left)
factoring in this function, and it is a little dense.

> typeName :: Parser TypeName
> typeName :: Parser TypeName
typeName =
>     (Parser TypeName
rowTypeName Parser TypeName -> Parser TypeName -> Parser TypeName
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser TypeName
intervalTypeName Parser TypeName -> Parser TypeName -> Parser TypeName
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser TypeName
otherTypeName)
>     Parser TypeName
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
-> Parser TypeName
forall t s a.
GenParser t s a -> GenParser t s (a -> a) -> GenParser t s a
<??*> GenParser
  ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
tnSuffix
>   where
>     rowTypeName :: Parser TypeName
rowTypeName =
>         [(Name, TypeName)] -> TypeName
RowTypeName ([(Name, TypeName)] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [(Name, TypeName)]
-> Parser TypeName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "row" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [(Name, TypeName)]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [(Name, TypeName)]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [(Name, TypeName)]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [(Name, TypeName)]
forall a. Parser a -> Parser a
parens (Parser (Name, TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [(Name, TypeName)]
forall a. Parser a -> Parser [a]
commaSep1 Parser (Name, TypeName)
rowField))
>     rowField :: Parser (Name, TypeName)
rowField = (,) (Name -> TypeName -> (Name, TypeName))
-> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (TypeName -> (Name, TypeName))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
name ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (TypeName -> (Name, TypeName))
-> Parser TypeName -> Parser (Name, TypeName)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser TypeName
typeName
>     ----------------------------
>     intervalTypeName :: Parser TypeName
intervalTypeName =
>         FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "interval" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser TypeName -> Parser TypeName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
>         ((IntervalTypeField -> Maybe IntervalTypeField -> TypeName)
-> (IntervalTypeField, Maybe IntervalTypeField) -> TypeName
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry IntervalTypeField -> Maybe IntervalTypeField -> TypeName
IntervalTypeName ((IntervalTypeField, Maybe IntervalTypeField) -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (IntervalTypeField, Maybe IntervalTypeField)
-> Parser TypeName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (IntervalTypeField, Maybe IntervalTypeField)
intervalQualifier)
>     ----------------------------
>     otherTypeName :: Parser TypeName
otherTypeName =
>         Parser [Name]
nameOfType Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> TypeName)
-> Parser TypeName
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**>
>             (ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> TypeName)
typeNameWithParens
>              ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Maybe Integer
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Integer)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Integer
forall a. Maybe a
Nothing ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Integer)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> TypeName)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> [Name] -> TypeName)
timeTypeName ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> [Name] -> TypeName)
charTypeName)
>              ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ([Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> TypeName)
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Name] -> TypeName
TypeName)
>     nameOfType :: Parser [Name]
nameOfType = Parser [Name]
reservedTypeNames Parser [Name] -> Parser [Name] -> Parser [Name]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser [Name]
names
>     charTypeName :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> [Name] -> TypeName)
charTypeName = Parser [Name]
charSet Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ([Name] -> Parser [Name] -> Parser [Name]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] Parser [Name]
tcollate Parser [Name]
-> ([Name] -> Maybe Integer -> [Name] -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> Maybe Integer -> [Name] -> TypeName)
forall (f :: * -> *) d a b c t.
Applicative f =>
f d -> (a -> b -> c -> d -> t) -> f (c -> b -> a -> t)
<$$$$> [Name] -> Maybe Integer -> [Name] -> [Name] -> TypeName
CharTypeName)
>                    ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [Name] -> Parser [Name]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [] Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (Parser [Name]
tcollate Parser [Name]
-> ([Name] -> Maybe Integer -> [Name] -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> Maybe Integer -> [Name] -> TypeName)
forall (f :: * -> *) d a b c t.
Applicative f =>
f d -> (a -> b -> c -> d -> t) -> f (c -> b -> a -> t)
<$$$$> [Name] -> Maybe Integer -> [Name] -> [Name] -> TypeName
CharTypeName)
>     typeNameWithParens :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> TypeName)
typeNameWithParens =
>         (Parser Char
openParen Parser Char
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
unsignedInteger)
>         ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> TypeName)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (Parser Char
closeParen Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
precMaybeSuffix
>               ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
precScaleTypeName ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
precLengthTypeName) ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
-> Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Char
closeParen)
>     precMaybeSuffix :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
precMaybeSuffix = ((Maybe Integer -> [Name] -> TypeName)
-> (Integer -> Maybe Integer) -> Integer -> [Name] -> TypeName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Maybe Integer
forall a. a -> Maybe a
Just) ((Maybe Integer -> [Name] -> TypeName)
 -> Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> [Name] -> TypeName)
timeTypeName ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> [Name] -> TypeName)
charTypeName)
>                       ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (([Name] -> Integer -> TypeName) -> Integer -> [Name] -> TypeName
forall a b c. (a -> b -> c) -> b -> a -> c
flip [Name] -> Integer -> TypeName
PrecTypeName)
>     precScaleTypeName :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
precScaleTypeName = (Parser Char
comma Parser Char
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
unsignedInteger) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ([Name] -> Integer -> Integer -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall (f :: * -> *) c a b t.
Applicative f =>
f c -> (a -> b -> c -> t) -> f (b -> a -> t)
<$$$> [Name] -> Integer -> Integer -> TypeName
PrecScaleTypeName
>     precLengthTypeName :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
precLengthTypeName =
>         PrecMultiplier -> Maybe PrecMultiplier
forall a. a -> Maybe a
Just (PrecMultiplier -> Maybe PrecMultiplier)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe PrecMultiplier)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
lobPrecSuffix
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe PrecMultiplier)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe PrecMultiplier -> Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (ParsecT [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe PrecUnits)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
lobUnits ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe PrecUnits)
-> ([Name]
    -> Integer -> Maybe PrecMultiplier -> Maybe PrecUnits -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe PrecMultiplier -> Integer -> [Name] -> TypeName)
forall (f :: * -> *) d a b c t.
Applicative f =>
f d -> (a -> b -> c -> d -> t) -> f (c -> b -> a -> t)
<$$$$> [Name]
-> Integer -> Maybe PrecMultiplier -> Maybe PrecUnits -> TypeName
PrecLengthTypeName)
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Maybe PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe PrecMultiplier)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe PrecMultiplier
forall a. Maybe a
Nothing ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe PrecMultiplier)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe PrecMultiplier -> Integer -> [Name] -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> [Name] -> TypeName)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ((PrecUnits -> Maybe PrecUnits
forall a. a -> Maybe a
Just (PrecUnits -> Maybe PrecUnits)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe PrecUnits)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
lobUnits) ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe PrecUnits)
-> ([Name]
    -> Integer -> Maybe PrecMultiplier -> Maybe PrecUnits -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe PrecMultiplier -> Integer -> [Name] -> TypeName)
forall (f :: * -> *) d a b c t.
Applicative f =>
f d -> (a -> b -> c -> d -> t) -> f (c -> b -> a -> t)
<$$$$> [Name]
-> Integer -> Maybe PrecMultiplier -> Maybe PrecUnits -> TypeName
PrecLengthTypeName)
>     timeTypeName :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> [Name] -> TypeName)
timeTypeName = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
tz ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ([Name] -> Maybe Integer -> Bool -> TypeName)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> [Name] -> TypeName)
forall (f :: * -> *) c a b t.
Applicative f =>
f c -> (a -> b -> c -> t) -> f (b -> a -> t)
<$$$> [Name] -> Maybe Integer -> Bool -> TypeName
TimeTypeName
>     ----------------------------
>     lobPrecSuffix :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
lobPrecSuffix = PrecMultiplier
PrecK PrecMultiplier
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "k"
>                     ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> PrecMultiplier
PrecM PrecMultiplier
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "m"
>                     ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> PrecMultiplier
PrecG PrecMultiplier
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "g"
>                     ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> PrecMultiplier
PrecT PrecMultiplier
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "t"
>                     ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> PrecMultiplier
PrecP PrecMultiplier
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecMultiplier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "p"
>     lobUnits :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
lobUnits = PrecUnits
PrecCharacters PrecUnits
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "characters"
>                -- char and byte are the oracle spelling
>                -- todo: move these to oracle dialect
>                ParsecT [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> PrecUnits
PrecCharacters PrecUnits
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "char"
>                ParsecT [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> PrecUnits
PrecOctets PrecUnits
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "octets"
>                ParsecT [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> PrecUnits
PrecOctets PrecUnits
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrecUnits
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "byte"
>     tz :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
tz = Bool
True Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["with", "time","zone"]
>          ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool
False Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["without", "time","zone"]
>     charSet :: Parser [Name]
charSet = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["character", "set"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser [Name]
names
>     tcollate :: Parser [Name]
tcollate = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "collate" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser [Name]
names
>     ----------------------------
>     tnSuffix :: GenParser
  ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
tnSuffix = GenParser
  ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
multiset GenParser
  ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> GenParser
  ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
array
>     multiset :: GenParser
  ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
multiset = TypeName -> TypeName
MultisetTypeName (TypeName -> TypeName)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "multiset"
>     array :: GenParser
  ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
array = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "array" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
>         (ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Integer)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall a. Parser a -> Parser a
brackets ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
unsignedInteger) ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Integer)
-> (TypeName -> Maybe Integer -> TypeName)
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (TypeName -> TypeName)
forall (f :: * -> *) b a c.
Applicative f =>
f b -> (a -> b -> c) -> f (a -> c)
<$$> TypeName -> Maybe Integer -> TypeName
ArrayTypeName)
>     ----------------------------
>     -- this parser handles the fixed set of multi word
>     -- type names, plus all the type names which are
>     -- reserved words
>     reservedTypeNames :: Parser [Name]
reservedTypeNames = do
>         Dialect
d <- ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Dialect
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
>         (Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[]) (Name -> [Name]) -> ([FilePath] -> Name) -> [FilePath] -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing (FilePath -> Name)
-> ([FilePath] -> FilePath) -> [FilePath] -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [FilePath] -> FilePath
unwords ([FilePath] -> [Name])
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> Parser [Name]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
makeKeywordTree (Dialect -> [FilePath]
diSpecialTypeNames Dialect
d)
>         

= Scalar expressions

== simple literals

See the stringToken lexer below for notes on string literal syntax.

> stringLit :: Parser ScalarExpr
> stringLit :: Parser ScalarExpr
stringLit = (\(s :: FilePath
s,e :: FilePath
e,t :: FilePath
t) -> FilePath -> FilePath -> FilePath -> ScalarExpr
StringLit FilePath
s FilePath
e FilePath
t) ((FilePath, FilePath, FilePath) -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FilePath, FilePath, FilePath)
-> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (FilePath, FilePath, FilePath)
stringTokExtend

> numberLit :: Parser ScalarExpr
> numberLit :: Parser ScalarExpr
numberLit = FilePath -> ScalarExpr
NumLit (FilePath -> ScalarExpr) -> Parser FilePath -> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> Parser FilePath
sqlNumberTok Bool
False

> simpleLiteral :: Parser ScalarExpr
> simpleLiteral :: Parser ScalarExpr
simpleLiteral = Parser ScalarExpr
numberLit Parser ScalarExpr -> Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser ScalarExpr
stringLit

== star, param, host param

=== star

used in select *, select x.*, and agg(*) variations, and some other
places as well. The parser doesn't attempt to check that the star is
in a valid context, it parses it OK in any scalar expression context.

> star :: Parser ScalarExpr
> star :: Parser ScalarExpr
star = ScalarExpr
Star ScalarExpr -> Parser FilePath -> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
symbol "*"

== parameter

unnamed parameter or named parameter
use in e.g. select * from t where a = ?
select x from t where x > :param

> parameter :: Parser ScalarExpr
> parameter :: Parser ScalarExpr
parameter = [Parser ScalarExpr] -> Parser ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [ScalarExpr
Parameter ScalarExpr -> Parser Char -> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser Char
questionMark
>     ,FilePath -> Maybe FilePath -> ScalarExpr
HostParameter
>      (FilePath -> Maybe FilePath -> ScalarExpr)
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe FilePath -> ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser FilePath
hostParamTok
>      ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe FilePath -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe FilePath)
-> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe FilePath)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath -> Parser FilePath
keyword "indicator" Parser FilePath -> Parser FilePath -> Parser FilePath
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser FilePath
hostParamTok)]

== positional arg

> positionalArg :: Parser ScalarExpr
> positionalArg :: Parser ScalarExpr
positionalArg = Int -> ScalarExpr
PositionalArg (Int -> ScalarExpr)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Int
-> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Int
positionalArgTok

== parens

scalar expression parens, row ctor and scalar subquery

> parensExpr :: Parser ScalarExpr
> parensExpr :: Parser ScalarExpr
parensExpr = Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens (Parser ScalarExpr -> Parser ScalarExpr)
-> Parser ScalarExpr -> Parser ScalarExpr
forall a b. (a -> b) -> a -> b
$ [Parser ScalarExpr] -> Parser ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [SubQueryExprType -> QueryExpr -> ScalarExpr
SubQueryExpr SubQueryExprType
SqSq (QueryExpr -> ScalarExpr) -> Parser QueryExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser QueryExpr
queryExpr
>     ,[ScalarExpr] -> ScalarExpr
ctor ([ScalarExpr] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep1 Parser ScalarExpr
scalarExpr]
>   where
>     ctor :: [ScalarExpr] -> ScalarExpr
ctor [a :: ScalarExpr
a] = ScalarExpr -> ScalarExpr
Parens ScalarExpr
a
>     ctor as :: [ScalarExpr]
as = [Name] -> [ScalarExpr] -> ScalarExpr
SpecialOp [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing "rowctor"] [ScalarExpr]
as

== case, cast, exists, unique, array/multiset constructor, interval

All of these start with a fixed keyword which is reserved, so no other
syntax can start with the same keyword.

=== case expression

> caseExpr :: Parser ScalarExpr
> caseExpr :: Parser ScalarExpr
caseExpr =
>     Maybe ScalarExpr
-> [([ScalarExpr], ScalarExpr)] -> Maybe ScalarExpr -> ScalarExpr
Case (Maybe ScalarExpr
 -> [([ScalarExpr], ScalarExpr)] -> Maybe ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([([ScalarExpr], ScalarExpr)] -> Maybe ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "case" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe Parser ScalarExpr
scalarExpr)
>          ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([([ScalarExpr], ScalarExpr)] -> Maybe ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [([ScalarExpr], ScalarExpr)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr], ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [([ScalarExpr], ScalarExpr)]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr], ScalarExpr)
whenClause
>          ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe Parser ScalarExpr
elseClause
>          Parser ScalarExpr
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "end"
>   where
>    whenClause :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr], ScalarExpr)
whenClause = (,) ([ScalarExpr] -> ScalarExpr -> ([ScalarExpr], ScalarExpr))
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ([ScalarExpr], ScalarExpr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "when" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep1 Parser ScalarExpr
scalarExpr)
>                     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ([ScalarExpr], ScalarExpr))
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr], ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "then" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr)
>    elseClause :: Parser ScalarExpr
elseClause = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "else" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr

=== cast

cast: cast(expr as type)

> cast :: Parser ScalarExpr
> cast :: Parser ScalarExpr
cast = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "cast" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
>        Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens (ScalarExpr -> TypeName -> ScalarExpr
Cast (ScalarExpr -> TypeName -> ScalarExpr)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (TypeName -> ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
scalarExpr
>                     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (TypeName -> ScalarExpr)
-> Parser TypeName -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "as" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser TypeName -> Parser TypeName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TypeName
typeName))

=== exists, unique

subquery expression:
[exists|unique] (queryexpr)

> subquery :: Parser ScalarExpr
> subquery :: Parser ScalarExpr
subquery = SubQueryExprType -> QueryExpr -> ScalarExpr
SubQueryExpr (SubQueryExprType -> QueryExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SubQueryExprType
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (QueryExpr -> ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity SubQueryExprType
sqkw ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (QueryExpr -> ScalarExpr)
-> Parser QueryExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser QueryExpr -> Parser QueryExpr
forall a. Parser a -> Parser a
parens Parser QueryExpr
queryExpr
>   where
>     sqkw :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity SubQueryExprType
sqkw = SubQueryExprType
SqExists SubQueryExprType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SubQueryExprType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "exists" ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity SubQueryExprType
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SubQueryExprType
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SubQueryExprType
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SubQueryExprType
SqUnique SubQueryExprType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SubQueryExprType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "unique"

=== array/multiset constructor

> arrayCtor :: Parser ScalarExpr
> arrayCtor :: Parser ScalarExpr
arrayCtor = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "array" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Parser ScalarExpr] -> Parser ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [QueryExpr -> ScalarExpr
ArrayCtor (QueryExpr -> ScalarExpr) -> Parser QueryExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser QueryExpr -> Parser QueryExpr
forall a. Parser a -> Parser a
parens Parser QueryExpr
queryExpr
>     ,ScalarExpr -> [ScalarExpr] -> ScalarExpr
Array ([Name] -> ScalarExpr
Iden [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing "array"]) ([ScalarExpr] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser a
brackets (Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep Parser ScalarExpr
scalarExpr)]

As far as I can tell, table(query expr) is just syntax sugar for
multiset(query expr). It must be there for compatibility or something.

> multisetCtor :: Parser ScalarExpr
> multisetCtor :: Parser ScalarExpr
multisetCtor =
>     [Parser ScalarExpr] -> Parser ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "multiset" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>      [Parser ScalarExpr] -> Parser ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>      [QueryExpr -> ScalarExpr
MultisetQueryCtor (QueryExpr -> ScalarExpr) -> Parser QueryExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser QueryExpr -> Parser QueryExpr
forall a. Parser a -> Parser a
parens Parser QueryExpr
queryExpr
>      ,[ScalarExpr] -> ScalarExpr
MultisetCtor ([ScalarExpr] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser a
brackets (Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep Parser ScalarExpr
scalarExpr)]
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "table" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>      QueryExpr -> ScalarExpr
MultisetQueryCtor (QueryExpr -> ScalarExpr) -> Parser QueryExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser QueryExpr -> Parser QueryExpr
forall a. Parser a -> Parser a
parens Parser QueryExpr
queryExpr]

> nextValueFor :: Parser ScalarExpr
> nextValueFor :: Parser ScalarExpr
nextValueFor = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["next","value","for"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> ScalarExpr
NextValueFor ([Name] -> ScalarExpr) -> Parser [Name] -> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names

=== interval

interval literals are a special case and we follow the grammar less
permissively here

parse SQL interval literals, something like
interval '5' day (3)
or
interval '5' month

if the literal looks like this:
interval 'something'

then it is parsed as a regular typed literal. It must have a
interval-datetime-field suffix to parse as an intervallit

It uses try because of a conflict with interval type names: todo, fix
this. also fix the monad -> applicative

> intervalLit :: Parser ScalarExpr
> intervalLit :: Parser ScalarExpr
intervalLit = Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "interval" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> do
>     Maybe Sign
s <- ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Sign
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Sign)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Sign
 -> ParsecT
      [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Sign))
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Sign
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Sign)
forall a b. (a -> b) -> a -> b
$ [ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Sign]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Sign
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [Sign
Plus Sign
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Sign
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
symbol_ "+"
>                               ,Sign
Minus Sign
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Sign
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
symbol_ "-"]
>     FilePath
lit <- Parser FilePath
singleQuotesOnlyStringTok
>     Maybe (IntervalTypeField, Maybe IntervalTypeField)
q <- ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (IntervalTypeField, Maybe IntervalTypeField)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (IntervalTypeField, Maybe IntervalTypeField))
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (IntervalTypeField, Maybe IntervalTypeField)
intervalQualifier
>     Maybe Sign
-> FilePath
-> Maybe (IntervalTypeField, Maybe IntervalTypeField)
-> Parser ScalarExpr
forall (f :: * -> *).
MonadFail f =>
Maybe Sign
-> FilePath
-> Maybe (IntervalTypeField, Maybe IntervalTypeField)
-> f ScalarExpr
mkIt Maybe Sign
s FilePath
lit Maybe (IntervalTypeField, Maybe IntervalTypeField)
q)
>   where
>     mkIt :: Maybe Sign
-> FilePath
-> Maybe (IntervalTypeField, Maybe IntervalTypeField)
-> f ScalarExpr
mkIt Nothing val :: FilePath
val Nothing = ScalarExpr -> f ScalarExpr
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScalarExpr -> f ScalarExpr) -> ScalarExpr -> f ScalarExpr
forall a b. (a -> b) -> a -> b
$ TypeName -> FilePath -> ScalarExpr
TypedLit ([Name] -> TypeName
TypeName [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing "interval"]) FilePath
val
>     mkIt s :: Maybe Sign
s val :: FilePath
val (Just (a :: IntervalTypeField
a,b :: Maybe IntervalTypeField
b)) = ScalarExpr -> f ScalarExpr
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScalarExpr -> f ScalarExpr) -> ScalarExpr -> f ScalarExpr
forall a b. (a -> b) -> a -> b
$ Maybe Sign
-> FilePath
-> IntervalTypeField
-> Maybe IntervalTypeField
-> ScalarExpr
IntervalLit Maybe Sign
s FilePath
val IntervalTypeField
a Maybe IntervalTypeField
b
>     mkIt (Just {}) _val :: FilePath
_val Nothing = FilePath -> f ScalarExpr
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail "cannot use sign without interval qualifier"

== typed literal, app, special, aggregate, window, iden

All of these start with identifiers (some of the special functions
start with reserved keywords).

they are all variations on suffixes on the basic identifier parser

The windows is a suffix on the app parser

=== iden prefix term

all the scalar expressions which start with an identifier

(todo: really put all of them here instead of just some of them)

> idenExpr :: Parser ScalarExpr
> idenExpr :: Parser ScalarExpr
idenExpr =
>     -- todo: work out how to left factor this
>     Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TypeName -> FilePath -> ScalarExpr
TypedLit (TypeName -> FilePath -> ScalarExpr)
-> Parser TypeName
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FilePath -> ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TypeName
typeName ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (FilePath -> ScalarExpr)
-> Parser FilePath -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FilePath
singleQuotesOnlyStringTok)
>     Parser ScalarExpr -> Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Parser [Name]
names Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
-> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ([Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [Name] -> ScalarExpr
Iden ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> ScalarExpr)
app)
>     Parser ScalarExpr -> Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser ScalarExpr
keywordFunctionOrIden
>   where
>     -- special cases for keywords that can be parsed as an iden or app
>     keywordFunctionOrIden :: Parser ScalarExpr
keywordFunctionOrIden = Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Parser ScalarExpr -> Parser ScalarExpr)
-> Parser ScalarExpr -> Parser ScalarExpr
forall a b. (a -> b) -> a -> b
$ do
>         FilePath
x <- [FilePath] -> Maybe FilePath -> Parser FilePath
unquotedIdentifierTok [] Maybe FilePath
forall a. Maybe a
Nothing
>         Dialect
d <- ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Dialect
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
>         let i :: Bool
i = (Char -> Char) -> FilePath -> FilePath
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower FilePath
x FilePath -> [FilePath] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` Dialect -> [FilePath]
diIdentifierKeywords Dialect
d
>             a :: Bool
a = (Char -> Char) -> FilePath -> FilePath
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower FilePath
x FilePath -> [FilePath] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` Dialect -> [FilePath]
diAppKeywords Dialect
d
>         case () of
>             _  | Bool
i Bool -> Bool -> Bool
&& Bool
a -> [Name] -> Parser [Name]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing FilePath
x] Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
-> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ([Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [Name] -> ScalarExpr
Iden ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> ScalarExpr)
app
>                | Bool
i -> ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Name] -> ScalarExpr
Iden [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing FilePath
x])
>                | Bool
a -> [Name] -> Parser [Name]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing FilePath
x] Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
-> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> ScalarExpr)
app
>                | Bool
otherwise -> FilePath -> Parser ScalarExpr
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail ""


=== special

These are keyword operators which don't look like normal prefix,
postfix or infix binary operators. They mostly look like function
application but with keywords in the argument list instead of commas
to separate the arguments.

the special op keywords
parse an operator which is
operatorname(firstArg keyword0 arg0 keyword1 arg1 etc.)

> data SpecialOpKFirstArg = SOKNone
>                         | SOKOptional
>                         | SOKMandatory

> specialOpK :: String -- name of the operator
>            -> SpecialOpKFirstArg -- has a first arg without a keyword
>            -> [(String,Bool)] -- the other args with their keywords
>                               -- and whether they are optional
>            -> Parser ScalarExpr
> specialOpK :: FilePath
-> SpecialOpKFirstArg -> [(FilePath, Bool)] -> Parser ScalarExpr
specialOpK opName :: FilePath
opName firstArg :: SpecialOpKFirstArg
firstArg kws :: [(FilePath, Bool)]
kws =
>     FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ FilePath
opName ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> do
>     Parser Char
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Parser Char
openParen
>     let pfa :: Parser ScalarExpr
pfa = do
>               ScalarExpr
e <- Parser ScalarExpr
scalarExpr
>               -- check we haven't parsed the first
>               -- keyword as an identifier
>               case (ScalarExpr
e,[(FilePath, Bool)]
kws) of
>                   (Iden [Name Nothing i :: FilePath
i], (k :: FilePath
k,_):_)
>                       | (Char -> Char) -> FilePath -> FilePath
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower FilePath
i FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== FilePath
k ->
>                           FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath
 -> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ())
-> FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall a b. (a -> b) -> a -> b
$ "cannot use keyword here: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
i
>                   _ -> () -> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
>               ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScalarExpr
e
>     Maybe ScalarExpr
fa <- case SpecialOpKFirstArg
firstArg of
>          SOKNone -> Maybe ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe ScalarExpr
forall a. Maybe a
Nothing
>          SOKOptional -> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ScalarExpr
pfa)
>          SOKMandatory -> ScalarExpr -> Maybe ScalarExpr
forall a. a -> Maybe a
Just (ScalarExpr -> Maybe ScalarExpr)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
pfa
>     [Maybe (FilePath, ScalarExpr)]
as <- ((FilePath, Bool)
 -> ParsecT
      [((FilePath, Int, Int), Token)]
      Dialect
      Identity
      (Maybe (FilePath, ScalarExpr)))
-> [(FilePath, Bool)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [Maybe (FilePath, ScalarExpr)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (FilePath, Bool)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (FilePath, ScalarExpr))
parseArg [(FilePath, Bool)]
kws
>     Parser Char
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Parser Char
closeParen
>     ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScalarExpr -> Parser ScalarExpr)
-> ScalarExpr -> Parser ScalarExpr
forall a b. (a -> b) -> a -> b
$ [Name]
-> Maybe ScalarExpr -> [(FilePath, ScalarExpr)] -> ScalarExpr
SpecialOpK [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing FilePath
opName] Maybe ScalarExpr
fa ([(FilePath, ScalarExpr)] -> ScalarExpr)
-> [(FilePath, ScalarExpr)] -> ScalarExpr
forall a b. (a -> b) -> a -> b
$ [Maybe (FilePath, ScalarExpr)] -> [(FilePath, ScalarExpr)]
forall a. [Maybe a] -> [a]
catMaybes [Maybe (FilePath, ScalarExpr)]
as
>   where
>     parseArg :: (FilePath, Bool)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (FilePath, ScalarExpr))
parseArg (nm :: FilePath
nm,mand :: Bool
mand) =
>         let p :: Parser ScalarExpr
p = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ FilePath
nm ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ScalarExpr
scalarExpr
>         in (ScalarExpr -> (FilePath, ScalarExpr))
-> Maybe ScalarExpr -> Maybe (FilePath, ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (FilePath
nm,) (Maybe ScalarExpr -> Maybe (FilePath, ScalarExpr))
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (FilePath, ScalarExpr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> if Bool
mand
>                           then ScalarExpr -> Maybe ScalarExpr
forall a. a -> Maybe a
Just (ScalarExpr -> Maybe ScalarExpr)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
p
>                           else Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ScalarExpr
p)

The actual operators:

EXTRACT( date_part FROM expression )

POSITION( string1 IN string2 )

SUBSTRING(extraction_string FROM starting_position [FOR length]
[COLLATE collation_name])

CONVERT(char_value USING conversion_char_name)

TRANSLATE(char_value USING translation_name)

OVERLAY(string PLACING embedded_string FROM start
[FOR length])

TRIM( [ [{LEADING | TRAILING | BOTH}] [removal_char] FROM ]
target_string
[COLLATE collation_name] )

> specialOpKs :: Parser ScalarExpr
> specialOpKs :: Parser ScalarExpr
specialOpKs = [Parser ScalarExpr] -> Parser ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([Parser ScalarExpr] -> Parser ScalarExpr)
-> [Parser ScalarExpr] -> Parser ScalarExpr
forall a b. (a -> b) -> a -> b
$ (Parser ScalarExpr -> Parser ScalarExpr)
-> [Parser ScalarExpr] -> [Parser ScalarExpr]
forall a b. (a -> b) -> [a] -> [b]
map Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try
>     [Parser ScalarExpr
extract, Parser ScalarExpr
position, Parser ScalarExpr
substring, Parser ScalarExpr
convert, Parser ScalarExpr
translate, Parser ScalarExpr
overlay, Parser ScalarExpr
trim]

> extract :: Parser ScalarExpr
> extract :: Parser ScalarExpr
extract = FilePath
-> SpecialOpKFirstArg -> [(FilePath, Bool)] -> Parser ScalarExpr
specialOpK "extract" SpecialOpKFirstArg
SOKMandatory [("from", Bool
True)]

> position :: Parser ScalarExpr
> position :: Parser ScalarExpr
position = FilePath
-> SpecialOpKFirstArg -> [(FilePath, Bool)] -> Parser ScalarExpr
specialOpK "position" SpecialOpKFirstArg
SOKMandatory [("in", Bool
True)]

strictly speaking, the substring must have at least one of from and
for, but the parser doens't enforce this

> substring :: Parser ScalarExpr
> substring :: Parser ScalarExpr
substring = FilePath
-> SpecialOpKFirstArg -> [(FilePath, Bool)] -> Parser ScalarExpr
specialOpK "substring" SpecialOpKFirstArg
SOKMandatory
>                 [("from", Bool
False),("for", Bool
False)]

> convert :: Parser ScalarExpr
> convert :: Parser ScalarExpr
convert = FilePath
-> SpecialOpKFirstArg -> [(FilePath, Bool)] -> Parser ScalarExpr
specialOpK "convert" SpecialOpKFirstArg
SOKMandatory [("using", Bool
True)]


> translate :: Parser ScalarExpr
> translate :: Parser ScalarExpr
translate = FilePath
-> SpecialOpKFirstArg -> [(FilePath, Bool)] -> Parser ScalarExpr
specialOpK "translate" SpecialOpKFirstArg
SOKMandatory [("using", Bool
True)]

> overlay :: Parser ScalarExpr
> overlay :: Parser ScalarExpr
overlay = FilePath
-> SpecialOpKFirstArg -> [(FilePath, Bool)] -> Parser ScalarExpr
specialOpK "overlay" SpecialOpKFirstArg
SOKMandatory
>                 [("placing", Bool
True),("from", Bool
True),("for", Bool
False)]

trim is too different because of the optional char, so a custom parser
the both ' ' is filled in as the default if either parts are missing
in the source

> trim :: Parser ScalarExpr
> trim :: Parser ScalarExpr
trim =
>     FilePath -> Parser FilePath
keyword "trim" Parser FilePath -> Parser ScalarExpr -> Parser ScalarExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens (FilePath -> FilePath -> ScalarExpr -> ScalarExpr
mkTrim
>             (FilePath -> FilePath -> ScalarExpr -> ScalarExpr)
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FilePath -> ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> Parser FilePath -> Parser FilePath
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "both" Parser FilePath
sides
>             ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (FilePath -> ScalarExpr -> ScalarExpr)
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FilePath -> Parser FilePath -> Parser FilePath
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option " " Parser FilePath
singleQuotesOnlyStringTok
>             ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "from" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr))
>   where
>     sides :: Parser FilePath
sides = [Parser FilePath] -> Parser FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ["leading" FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser FilePath
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "leading"
>                    ,"trailing" FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser FilePath
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "trailing"
>                    ,"both" FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser FilePath
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "both"]
>     mkTrim :: FilePath -> FilePath -> ScalarExpr -> ScalarExpr
mkTrim fa :: FilePath
fa ch :: FilePath
ch fr :: ScalarExpr
fr =
>       [Name]
-> Maybe ScalarExpr -> [(FilePath, ScalarExpr)] -> ScalarExpr
SpecialOpK [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing "trim"] Maybe ScalarExpr
forall a. Maybe a
Nothing
>           ([(FilePath, ScalarExpr)] -> ScalarExpr)
-> [(FilePath, ScalarExpr)] -> ScalarExpr
forall a b. (a -> b) -> a -> b
$ [Maybe (FilePath, ScalarExpr)] -> [(FilePath, ScalarExpr)]
forall a. [Maybe a] -> [a]
catMaybes [(FilePath, ScalarExpr) -> Maybe (FilePath, ScalarExpr)
forall a. a -> Maybe a
Just (FilePath
fa,FilePath -> FilePath -> FilePath -> ScalarExpr
StringLit "'" "'" FilePath
ch)
>                       ,(FilePath, ScalarExpr) -> Maybe (FilePath, ScalarExpr)
forall a. a -> Maybe a
Just ("from", ScalarExpr
fr)]

=== app, aggregate, window

This parses all these variations:
normal function application with just a csv of scalar exprs
aggregate variations (distinct, order by in parens, filter and where
  suffixes)
window apps (fn/agg followed by over)

This code is also a little dense like the typename code because of
left factoring, later they will even have to be partially combined
together.

> app :: Parser ([Name] -> ScalarExpr)
> app :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> ScalarExpr)
app =
>     Parser Char
openParen Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [ParsecT
   [((FilePath, Int, Int), Token)]
   Dialect
   Identity
   ([Name] -> ScalarExpr)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [Parser SetQuantifier
duplicates
>      Parser SetQuantifier
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (SetQuantifier -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep1 Parser ScalarExpr
scalarExpr
>            ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> SetQuantifier -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (SetQuantifier -> [Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ((([SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
orderBy) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Char
closeParen)
>                  ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SortSpec]
      -> [ScalarExpr] -> SetQuantifier -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> SetQuantifier -> [Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe Parser ScalarExpr
afilter ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> ([Name]
    -> SetQuantifier
    -> [ScalarExpr]
    -> [SortSpec]
    -> Maybe ScalarExpr
    -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SortSpec]
      -> [ScalarExpr] -> SetQuantifier -> [Name] -> ScalarExpr)
forall (f :: * -> *) e a b c d t.
Applicative f =>
f e -> (a -> b -> c -> d -> e -> t) -> f (d -> c -> b -> a -> t)
<$$$$$> [Name]
-> SetQuantifier
-> [ScalarExpr]
-> [SortSpec]
-> Maybe ScalarExpr
-> ScalarExpr
AggregateApp)))
>      -- separate cases with no all or distinct which must have at
>      -- least one scalar expr
>     ,Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep1 Parser ScalarExpr
scalarExpr
>      ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> [ParsecT
   [((FilePath, Int, Int), Token)]
   Dialect
   Identity
   ([ScalarExpr] -> [Name] -> ScalarExpr)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>           [Parser Char
closeParen Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [ParsecT
   [((FilePath, Int, Int), Token)]
   Dialect
   Identity
   ([ScalarExpr] -> [Name] -> ScalarExpr)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>                          [ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr] -> [Name] -> ScalarExpr)
window
>                          ,ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr] -> [Name] -> ScalarExpr)
withinGroup
>                          ,(ScalarExpr -> Maybe ScalarExpr
forall a. a -> Maybe a
Just (ScalarExpr -> Maybe ScalarExpr)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
afilter) ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> ([Name] -> [ScalarExpr] -> Maybe ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall (f :: * -> *) c a b t.
Applicative f =>
f c -> (a -> b -> c -> t) -> f (b -> a -> t)
<$$$> [Name] -> [ScalarExpr] -> Maybe ScalarExpr -> ScalarExpr
aggAppWithoutDupeOrd
>                          ,([ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (([Name] -> [ScalarExpr] -> ScalarExpr)
-> [ScalarExpr] -> [Name] -> ScalarExpr
forall a b c. (a -> b -> c) -> b -> a -> c
flip [Name] -> [ScalarExpr] -> ScalarExpr
App)]
>           ,ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
orderBy ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Char
closeParen
>            ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SortSpec] -> [ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe Parser ScalarExpr
afilter ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> ([Name]
    -> [ScalarExpr] -> [SortSpec] -> Maybe ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SortSpec] -> [ScalarExpr] -> [Name] -> ScalarExpr)
forall (f :: * -> *) d a b c t.
Applicative f =>
f d -> (a -> b -> c -> d -> t) -> f (c -> b -> a -> t)
<$$$$> [Name]
-> [ScalarExpr] -> [SortSpec] -> Maybe ScalarExpr -> ScalarExpr
aggAppWithoutDupe)]
>      -- no scalarExprs: duplicates and order by not allowed
>     ,([] [ScalarExpr]
-> Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser Char
closeParen) ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ([ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (([Name] -> [ScalarExpr] -> ScalarExpr)
-> [ScalarExpr] -> [Name] -> ScalarExpr
forall a b c. (a -> b -> c) -> b -> a -> c
flip [Name] -> [ScalarExpr] -> ScalarExpr
App) (ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr] -> [Name] -> ScalarExpr)
window ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr] -> [Name] -> ScalarExpr)
withinGroup)
>     ]
>   where
>     aggAppWithoutDupeOrd :: [Name] -> [ScalarExpr] -> Maybe ScalarExpr -> ScalarExpr
aggAppWithoutDupeOrd n :: [Name]
n es :: [ScalarExpr]
es f :: Maybe ScalarExpr
f = [Name]
-> SetQuantifier
-> [ScalarExpr]
-> [SortSpec]
-> Maybe ScalarExpr
-> ScalarExpr
AggregateApp [Name]
n SetQuantifier
SQDefault [ScalarExpr]
es [] Maybe ScalarExpr
f
>     aggAppWithoutDupe :: [Name]
-> [ScalarExpr] -> [SortSpec] -> Maybe ScalarExpr -> ScalarExpr
aggAppWithoutDupe n :: [Name]
n = [Name]
-> SetQuantifier
-> [ScalarExpr]
-> [SortSpec]
-> Maybe ScalarExpr
-> ScalarExpr
AggregateApp [Name]
n SetQuantifier
SQDefault

> afilter :: Parser ScalarExpr
> afilter :: Parser ScalarExpr
afilter = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "filter" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "where" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr)

> withinGroup :: Parser ([ScalarExpr] -> [Name] -> ScalarExpr)
> withinGroup :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr] -> [Name] -> ScalarExpr)
withinGroup =
>     ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["within", "group"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
forall a. Parser a -> Parser a
parens ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
orderBy) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ([Name] -> [ScalarExpr] -> [SortSpec] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall (f :: * -> *) c a b t.
Applicative f =>
f c -> (a -> b -> c -> t) -> f (b -> a -> t)
<$$$> [Name] -> [ScalarExpr] -> [SortSpec] -> ScalarExpr
AggregateAppGroup

==== window

parse a window call as a suffix of a regular function call
this looks like this:
functionname(args) over ([partition by ids] [order by orderitems])

No support for explicit frames yet.

TODO: add window support for other aggregate variations, needs some
changes to the syntax also

> window :: Parser ([ScalarExpr] -> [Name] -> ScalarExpr)
> window :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr] -> [Name] -> ScalarExpr)
window =
>   FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "over" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Char -> Parser Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Char
openParen Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
partitionBy
>   ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ([SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
orderBy
>         ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SortSpec]
      -> [ScalarExpr] -> [ScalarExpr] -> [Name] -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> [ScalarExpr] -> [Name] -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (((ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Frame
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Frame)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Frame
frameClause) ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Frame)
-> Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Frame)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Char
closeParen) ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Frame)
-> ([Name]
    -> [ScalarExpr]
    -> [ScalarExpr]
    -> [SortSpec]
    -> Maybe Frame
    -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SortSpec]
      -> [ScalarExpr] -> [ScalarExpr] -> [Name] -> ScalarExpr)
forall (f :: * -> *) e a b c d t.
Applicative f =>
f e -> (a -> b -> c -> d -> e -> t) -> f (d -> c -> b -> a -> t)
<$$$$$> [Name]
-> [ScalarExpr]
-> [ScalarExpr]
-> [SortSpec]
-> Maybe Frame
-> ScalarExpr
WindowApp))
>   where
>     partitionBy :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
partitionBy = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["partition","by"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep1 Parser ScalarExpr
scalarExpr
>     frameClause :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Frame
frameClause =
>         ParsecT [((FilePath, Int, Int), Token)] Dialect Identity FrameRows
frameRowsRange -- TODO: this 'and' could be an issue
>         ParsecT [((FilePath, Int, Int), Token)] Dialect Identity FrameRows
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FrameRows -> Frame)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Frame
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ([ParsecT
   [((FilePath, Int, Int), Token)]
   Dialect
   Identity
   (FrameRows -> Frame)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FrameRows -> Frame)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [(FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "between" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
frameLimit Bool
True)
>                       ParsecT [((FilePath, Int, Int), Token)] Dialect Identity FramePos
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FramePos -> FrameRows -> Frame)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FrameRows -> Frame)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> ((FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "and" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
frameLimit Bool
True)
>                             ParsecT [((FilePath, Int, Int), Token)] Dialect Identity FramePos
-> (FrameRows -> FramePos -> FramePos -> Frame)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FramePos -> FrameRows -> Frame)
forall (f :: * -> *) c a b t.
Applicative f =>
f c -> (a -> b -> c -> t) -> f (b -> a -> t)
<$$$> FrameRows -> FramePos -> FramePos -> Frame
FrameBetween)
>                       -- maybe this should still use a b expression
>                       -- for consistency
>                      ,Bool
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
frameLimit Bool
False ParsecT [((FilePath, Int, Int), Token)] Dialect Identity FramePos
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FramePos -> FrameRows -> Frame)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FrameRows -> Frame)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (FramePos -> FrameRows -> Frame)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FramePos -> FrameRows -> Frame)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((FrameRows -> FramePos -> Frame) -> FramePos -> FrameRows -> Frame
forall a b c. (a -> b -> c) -> b -> a -> c
flip FrameRows -> FramePos -> Frame
FrameFrom)])
>     frameRowsRange :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity FrameRows
frameRowsRange = FrameRows
FrameRows FrameRows
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FrameRows
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "rows"
>                      ParsecT [((FilePath, Int, Int), Token)] Dialect Identity FrameRows
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FrameRows
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FrameRows
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> FrameRows
FrameRange FrameRows
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FrameRows
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "range"
>     frameLimit :: Bool
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
frameLimit useB :: Bool
useB =
>         [ParsecT [((FilePath, Int, Int), Token)] Dialect Identity FramePos]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>         [FramePos
Current FramePos
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["current", "row"]
>          -- todo: create an automatic left factor for stuff like this
>         ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "unbounded" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
>          [ParsecT [((FilePath, Int, Int), Token)] Dialect Identity FramePos]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [FramePos
UnboundedPreceding FramePos
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "preceding"
>                 ,FramePos
UnboundedFollowing FramePos
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "following"]
>         ,(if Bool
useB then Parser ScalarExpr
scalarExprB else Parser ScalarExpr
scalarExpr)
>          Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> FramePos)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity FramePos
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (ScalarExpr -> FramePos
Preceding (ScalarExpr -> FramePos)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> FramePos)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "preceding"
>                ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> FramePos)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> FramePos)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> FramePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ScalarExpr -> FramePos
Following (ScalarExpr -> FramePos)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> FramePos)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "following")
>         ]

== suffixes

These are all generic suffixes on any scalar expr

=== in

in: two variations:
a in (expr0, expr1, ...)
a in (queryexpr)

> inSuffix :: Parser (ScalarExpr -> ScalarExpr)
> inSuffix :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
inSuffix =
>     Bool -> InPredValue -> ScalarExpr -> ScalarExpr
mkIn (Bool -> InPredValue -> ScalarExpr -> ScalarExpr)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (InPredValue -> ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
inty
>          ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (InPredValue -> ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InPredValue
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity InPredValue
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InPredValue
forall a. Parser a -> Parser a
parens ([ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity InPredValue]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InPredValue
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>                      [QueryExpr -> InPredValue
InQueryExpr (QueryExpr -> InPredValue)
-> Parser QueryExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InPredValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser QueryExpr
queryExpr
>                      ,[ScalarExpr] -> InPredValue
InList ([ScalarExpr] -> InPredValue)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InPredValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep1 Parser ScalarExpr
scalarExpr])
>   where
>     inty :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
inty = [ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [Bool
True Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "in"
>                   ,Bool
False Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["not","in"]]
>     mkIn :: Bool -> InPredValue -> ScalarExpr -> ScalarExpr
mkIn i :: Bool
i v :: InPredValue
v = \e :: ScalarExpr
e -> Bool -> ScalarExpr -> InPredValue -> ScalarExpr
In Bool
i ScalarExpr
e InPredValue
v

=== between

between:
expr between expr and expr

There is a complication when parsing between - when parsing the second
expression it is ambiguous when you hit an 'and' whether it is a
binary operator or part of the between. This code follows what
postgres does, which might be standard across SQL implementations,
which is that you can't have a binary and operator in the middle
expression in a between unless it is wrapped in parens. The 'bExpr
parsing' is used to create alternative scalar expression parser which
is identical to the normal one expect it doesn't recognise the binary
and operator. This is the call to scalarExprB.

> betweenSuffix :: Parser (ScalarExpr -> ScalarExpr)
> betweenSuffix :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
betweenSuffix =
>     Name -> ScalarExpr -> ScalarExpr -> ScalarExpr -> ScalarExpr
makeOp (Name -> ScalarExpr -> ScalarExpr -> ScalarExpr -> ScalarExpr)
-> (FilePath -> Name)
-> FilePath
-> ScalarExpr
-> ScalarExpr
-> ScalarExpr
-> ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing (FilePath -> ScalarExpr -> ScalarExpr -> ScalarExpr -> ScalarExpr)
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr -> ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser FilePath
opName
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr -> ScalarExpr -> ScalarExpr)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ScalarExpr
scalarExprB
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr -> ScalarExpr)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "and" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExprB)
>   where
>     opName :: Parser FilePath
opName = [Parser FilePath] -> Parser FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>              ["between" FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser FilePath
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "between"
>              ,"not between" FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser FilePath
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["not","between"])]
>     makeOp :: Name -> ScalarExpr -> ScalarExpr -> ScalarExpr -> ScalarExpr
makeOp n :: Name
n b :: ScalarExpr
b c :: ScalarExpr
c = \a :: ScalarExpr
a -> [Name] -> [ScalarExpr] -> ScalarExpr
SpecialOp [Name
n] [ScalarExpr
a,ScalarExpr
b,ScalarExpr
c]

=== quantified comparison

a = any (select * from t)

> quantifiedComparisonSuffix :: Parser (ScalarExpr -> ScalarExpr)
> quantifiedComparisonSuffix :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
quantifiedComparisonSuffix = do
>     Name
c <- Parser Name
comp
>     CompPredQuantifier
cq <- ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity CompPredQuantifier
compQuan
>     QueryExpr
q <- Parser QueryExpr -> Parser QueryExpr
forall a. Parser a -> Parser a
parens Parser QueryExpr
queryExpr
>     (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((ScalarExpr -> ScalarExpr)
 -> ParsecT
      [((FilePath, Int, Int), Token)]
      Dialect
      Identity
      (ScalarExpr -> ScalarExpr))
-> (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall a b. (a -> b) -> a -> b
$ \v :: ScalarExpr
v -> ScalarExpr
-> [Name] -> CompPredQuantifier -> QueryExpr -> ScalarExpr
QuantifiedComparison ScalarExpr
v [Name
c] CompPredQuantifier
cq QueryExpr
q
>   where
>     comp :: Parser Name
comp = Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing (FilePath -> Name) -> Parser FilePath -> Parser Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Parser FilePath] -> Parser FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ((FilePath -> Parser FilePath) -> [FilePath] -> [Parser FilePath]
forall a b. (a -> b) -> [a] -> [b]
map FilePath -> Parser FilePath
symbol
>            ["=", "<>", "<=", "<", ">", ">="])
>     compQuan :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity CompPredQuantifier
compQuan = [ParsecT
   [((FilePath, Int, Int), Token)]
   Dialect
   Identity
   CompPredQuantifier]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity CompPredQuantifier
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>                [CompPredQuantifier
CPAny CompPredQuantifier
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity CompPredQuantifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "any"
>                ,CompPredQuantifier
CPSome CompPredQuantifier
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity CompPredQuantifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "some"
>                ,CompPredQuantifier
CPAll CompPredQuantifier
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity CompPredQuantifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "all"]

=== match

a match (select a from t)

> matchPredicateSuffix :: Parser (ScalarExpr -> ScalarExpr)
> matchPredicateSuffix :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
matchPredicateSuffix = do
>     FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "match"
>     Bool
u <- Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "unique")
>     QueryExpr
q <- Parser QueryExpr -> Parser QueryExpr
forall a. Parser a -> Parser a
parens Parser QueryExpr
queryExpr
>     (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((ScalarExpr -> ScalarExpr)
 -> ParsecT
      [((FilePath, Int, Int), Token)]
      Dialect
      Identity
      (ScalarExpr -> ScalarExpr))
-> (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall a b. (a -> b) -> a -> b
$ \v :: ScalarExpr
v -> ScalarExpr -> Bool -> QueryExpr -> ScalarExpr
Match ScalarExpr
v Bool
u QueryExpr
q

=== array subscript

> arraySuffix :: Parser (ScalarExpr -> ScalarExpr)
> arraySuffix :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
arraySuffix = do
>     [ScalarExpr]
es <- ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser a
brackets (Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep Parser ScalarExpr
scalarExpr)
>     (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((ScalarExpr -> ScalarExpr)
 -> ParsecT
      [((FilePath, Int, Int), Token)]
      Dialect
      Identity
      (ScalarExpr -> ScalarExpr))
-> (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall a b. (a -> b) -> a -> b
$ \v :: ScalarExpr
v -> ScalarExpr -> [ScalarExpr] -> ScalarExpr
Array ScalarExpr
v [ScalarExpr]
es

=== escape

It is going to be really difficult to support an arbitrary character
for the escape now there is a separate lexer ...

TODO: this needs fixing. Escape is only part of other nodes, and not a
separate suffix.

> {-escapeSuffix :: Parser (ScalarExpr -> ScalarExpr)
> escapeSuffix = do
>     ctor <- choice
>             [Escape <$ keyword_ "escape"
>             ,UEscape <$ keyword_ "uescape"]
>     c <- escapeChar
>     pure $ \v -> ctor v c
>   where
>     escapeChar :: Parser Char
>     escapeChar = (identifierTok [] Nothing <|> symbolTok Nothing) >>= oneOnly
>     oneOnly :: String -> Parser Char
>     oneOnly c = case c of
>                    [c'] -> return c'
>                    _ -> fail "escape char must be single char"
> -}

=== collate

> collateSuffix:: Parser (ScalarExpr -> ScalarExpr)
> collateSuffix :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
collateSuffix = do
>     FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "collate"
>     [Name]
i <- Parser [Name]
names
>     (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((ScalarExpr -> ScalarExpr)
 -> ParsecT
      [((FilePath, Int, Int), Token)]
      Dialect
      Identity
      (ScalarExpr -> ScalarExpr))
-> (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall a b. (a -> b) -> a -> b
$ \v :: ScalarExpr
v -> ScalarExpr -> [Name] -> ScalarExpr
Collate ScalarExpr
v [Name]
i

== odbc syntax

the parser supports three kinds of odbc syntax, two of which are
scalar expressions (the other is a variation on joins)


> odbcExpr :: Parser ScalarExpr
> odbcExpr :: Parser ScalarExpr
odbcExpr = Parser FilePath
-> Parser FilePath -> Parser ScalarExpr -> Parser ScalarExpr
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (FilePath -> Parser FilePath
symbol "{") (FilePath -> Parser FilePath
symbol "}")
>            (Parser ScalarExpr
odbcTimeLit Parser ScalarExpr -> Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser ScalarExpr
odbcFunc)
>   where
>     odbcTimeLit :: Parser ScalarExpr
odbcTimeLit =
>         OdbcLiteralType -> FilePath -> ScalarExpr
OdbcLiteral (OdbcLiteralType -> FilePath -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity OdbcLiteralType
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FilePath -> ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity OdbcLiteralType]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity OdbcLiteralType
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [OdbcLiteralType
OLDate OdbcLiteralType
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity OdbcLiteralType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
keyword "d"
>                                ,OdbcLiteralType
OLTime OdbcLiteralType
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity OdbcLiteralType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
keyword "t"
>                                ,OdbcLiteralType
OLTimestamp OdbcLiteralType
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity OdbcLiteralType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
keyword "ts"]
>                     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (FilePath -> ScalarExpr)
-> Parser FilePath -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FilePath
singleQuotesOnlyStringTok
>     -- todo: this parser is too general, the expr part
>     -- should be only a function call (from a whitelist of functions)
>     -- or the extract operator
>     odbcFunc :: Parser ScalarExpr
odbcFunc = ScalarExpr -> ScalarExpr
OdbcFunc (ScalarExpr -> ScalarExpr)
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FilePath -> Parser FilePath
keyword "fn" Parser FilePath -> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr)

==  operators

The 'regular' operators in this parsing and in the abstract syntax are
unary prefix, unary postfix and binary infix operators. The operators
can be symbols (a + b), single keywords (a and b) or multiple keywords
(a is similar to b).

TODO: carefully review the precedences and associativities.

TODO: to fix the parsing completely, I think will need to parse
without precedence and associativity and fix up afterwards, since SQL
syntax is way too messy. It might be possible to avoid this if we
wanted to avoid extensibility and to not be concerned with parse error
messages, but both of these are too important.

> opTable :: Bool -> [[E.Operator [Token] ParseState Identity ScalarExpr]]
> opTable :: Bool
-> [[Operator
       [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]]
opTable bExpr :: Bool
bExpr =
>         [-- parse match and quantified comparisons as postfix ops
>           -- todo: left factor the quantified comparison with regular
>           -- binary comparison, somehow
>          [ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m (a -> a) -> Operator s u m a
E.Postfix (ParsecT
   [((FilePath, Int, Int), Token)]
   Dialect
   Identity
   (ScalarExpr -> ScalarExpr)
 -> Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall a b. (a -> b) -> a -> b
$ ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
quantifiedComparisonSuffix
>          ,ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m (a -> a) -> Operator s u m a
E.Postfix ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
matchPredicateSuffix
>          ]

>         ,[FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "." Assoc
E.AssocLeft]

>         ,[ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m (a -> a) -> Operator s u m a
postfix' ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
arraySuffix
>          ,ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m (a -> a) -> Operator s u m a
postfix' ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
collateSuffix]

>         ,[FilePath
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
prefixSym "+", FilePath
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
prefixSym "-"]

>         ,[FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "^" Assoc
E.AssocLeft]

>         ,[FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "*" Assoc
E.AssocLeft
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "/" Assoc
E.AssocLeft
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "%" Assoc
E.AssocLeft]

>         ,[FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "+" Assoc
E.AssocLeft
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "-" Assoc
E.AssocLeft]

>         ,[FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "||" Assoc
E.AssocRight
>          ,FilePath
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
prefixSym "~"
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "&" Assoc
E.AssocRight
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "|" Assoc
E.AssocRight]

>         ,[FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binaryKeyword "overlaps" Assoc
E.AssocNone]

>         ,[FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binaryKeyword "like" Assoc
E.AssocNone
>          -- have to use try with inSuffix because of a conflict
>          -- with 'in' in position function, and not between
>          -- between also has a try in it to deal with 'not'
>          -- ambiguity
>          ,ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m (a -> a) -> Operator s u m a
E.Postfix (ParsecT
   [((FilePath, Int, Int), Token)]
   Dialect
   Identity
   (ScalarExpr -> ScalarExpr)
 -> Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall a b. (a -> b) -> a -> b
$ ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
inSuffix
>          ,ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m (a -> a) -> Operator s u m a
E.Postfix ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr)
betweenSuffix]
>          -- todo: figure out where to put the try?
>          [Operator
   [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]
-> [Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]
-> [Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]
forall a. [a] -> [a] -> [a]
++ [ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s u (m :: * -> *).
ParsecT s u m [FilePath] -> Operator s u m ScalarExpr
binaryKeywords (ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
 -> Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall a b. (a -> b) -> a -> b
$ [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
makeKeywordTree
>              ["not like"
>              ,"is similar to"
>              ,"is not similar to"]]
>          [Operator
   [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]
-> [Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]
-> [Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]
forall a. [a] -> [a] -> [a]
++ [Operator
  [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
multisetBinOp]

>         ,[FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "<" Assoc
E.AssocNone
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym ">" Assoc
E.AssocNone
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym ">=" Assoc
E.AssocNone
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "<=" Assoc
E.AssocNone
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "!=" Assoc
E.AssocRight
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "<>" Assoc
E.AssocRight
>          ,FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym "=" Assoc
E.AssocRight]

>         ,[ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s (m :: * -> *) t u.
Stream s m t =>
ParsecT s u m [FilePath] -> Operator s u m ScalarExpr
postfixKeywords (ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
 -> Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall a b. (a -> b) -> a -> b
$ [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
makeKeywordTree
>              ["is null"
>              ,"is not null"
>              ,"is true"
>              ,"is not true"
>              ,"is false"
>              ,"is not false"
>              ,"is unknown"
>              ,"is not unknown"]]
>          [Operator
   [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]
-> [Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]
-> [Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]
forall a. [a] -> [a] -> [a]
++ [ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s u (m :: * -> *).
ParsecT s u m [FilePath] -> Operator s u m ScalarExpr
binaryKeywords (ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
 -> Operator
      [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall a b. (a -> b) -> a -> b
$ [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
makeKeywordTree
>              ["is distinct from"
>              ,"is not distinct from"]]

>         ,[FilePath
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
prefixKeyword "not"]

>         ,if Bool
bExpr then [] else [FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binaryKeyword "and" Assoc
E.AssocLeft]

>         ,[FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binaryKeyword "or" Assoc
E.AssocLeft]

>        ]
>   where
>     binarySym :: FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binarySym nm :: FilePath
nm assoc :: Assoc
assoc = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> Assoc -> Operator s u m ScalarExpr
binary (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
symbol_ FilePath
nm) FilePath
nm Assoc
assoc
>     binaryKeyword :: FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
binaryKeyword nm :: FilePath
nm assoc :: Assoc
assoc = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> FilePath
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> Assoc -> Operator s u m ScalarExpr
binary (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ FilePath
nm) FilePath
nm Assoc
assoc
>     binaryKeywords :: ParsecT s u m [FilePath] -> Operator s u m ScalarExpr
binaryKeywords p :: ParsecT s u m [FilePath]
p =
>         ParsecT s u m (ScalarExpr -> ScalarExpr -> ScalarExpr)
-> Assoc -> Operator s u m ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m (a -> a -> a) -> Assoc -> Operator s u m a
E.Infix (do
>                  [FilePath]
o <- ParsecT s u m [FilePath] -> ParsecT s u m [FilePath]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT s u m [FilePath]
p
>                  (ScalarExpr -> ScalarExpr -> ScalarExpr)
-> ParsecT s u m (ScalarExpr -> ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (\a :: ScalarExpr
a b :: ScalarExpr
b -> ScalarExpr -> [Name] -> ScalarExpr -> ScalarExpr
BinOp ScalarExpr
a [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing (FilePath -> Name) -> FilePath -> Name
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
unwords [FilePath]
o] ScalarExpr
b))
>             Assoc
E.AssocNone
>     postfixKeywords :: ParsecT s u m [FilePath] -> Operator s u m ScalarExpr
postfixKeywords p :: ParsecT s u m [FilePath]
p =
>       ParsecT s u m (ScalarExpr -> ScalarExpr)
-> Operator s u m ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m (a -> a) -> Operator s u m a
postfix' (ParsecT s u m (ScalarExpr -> ScalarExpr)
 -> Operator s u m ScalarExpr)
-> ParsecT s u m (ScalarExpr -> ScalarExpr)
-> Operator s u m ScalarExpr
forall a b. (a -> b) -> a -> b
$ do
>           [FilePath]
o <- ParsecT s u m [FilePath] -> ParsecT s u m [FilePath]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT s u m [FilePath]
p
>           (ScalarExpr -> ScalarExpr)
-> ParsecT s u m (ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((ScalarExpr -> ScalarExpr)
 -> ParsecT s u m (ScalarExpr -> ScalarExpr))
-> (ScalarExpr -> ScalarExpr)
-> ParsecT s u m (ScalarExpr -> ScalarExpr)
forall a b. (a -> b) -> a -> b
$ [Name] -> ScalarExpr -> ScalarExpr
PostfixOp [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing (FilePath -> Name) -> FilePath -> Name
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
unwords [FilePath]
o]
>     binary :: ParsecT s u m a -> FilePath -> Assoc -> Operator s u m ScalarExpr
binary p :: ParsecT s u m a
p nm :: FilePath
nm assoc :: Assoc
assoc =
>       ParsecT s u m (ScalarExpr -> ScalarExpr -> ScalarExpr)
-> Assoc -> Operator s u m ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m (a -> a -> a) -> Assoc -> Operator s u m a
E.Infix (ParsecT s u m a
p ParsecT s u m a
-> ParsecT s u m (ScalarExpr -> ScalarExpr -> ScalarExpr)
-> ParsecT s u m (ScalarExpr -> ScalarExpr -> ScalarExpr)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (ScalarExpr -> ScalarExpr -> ScalarExpr)
-> ParsecT s u m (ScalarExpr -> ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (\a :: ScalarExpr
a b :: ScalarExpr
b -> ScalarExpr -> [Name] -> ScalarExpr -> ScalarExpr
BinOp ScalarExpr
a [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing FilePath
nm] ScalarExpr
b)) Assoc
assoc
>     multisetBinOp :: Operator
  [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
multisetBinOp = ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> ScalarExpr -> ScalarExpr)
-> Assoc
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m (a -> a -> a) -> Assoc -> Operator s u m a
E.Infix (do
>         FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "multiset"
>         SetOperatorName
o <- [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [SetOperatorName
Union SetOperatorName
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "union"
>                     ,SetOperatorName
Intersect SetOperatorName
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "intersect"
>                     ,SetOperatorName
Except SetOperatorName
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "except"]
>         SetQuantifier
d <- SetQuantifier -> Parser SetQuantifier -> Parser SetQuantifier
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option SetQuantifier
SQDefault Parser SetQuantifier
duplicates
>         (ScalarExpr -> ScalarExpr -> ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (\a :: ScalarExpr
a b :: ScalarExpr
b -> ScalarExpr
-> SetOperatorName -> SetQuantifier -> ScalarExpr -> ScalarExpr
MultisetBinOp ScalarExpr
a SetOperatorName
o SetQuantifier
d ScalarExpr
b))
>           Assoc
E.AssocLeft
>     prefixKeyword :: FilePath
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
prefixKeyword nm :: FilePath
nm = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> FilePath
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> FilePath -> Operator s u m ScalarExpr
prefix (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ FilePath
nm) FilePath
nm
>     prefixSym :: FilePath
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
prefixSym nm :: FilePath
nm = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> FilePath
-> Operator
     [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> FilePath -> Operator s u m ScalarExpr
prefix (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
symbol_ FilePath
nm) FilePath
nm
>     prefix :: ParsecT s u m a -> FilePath -> Operator s u m ScalarExpr
prefix p :: ParsecT s u m a
p nm :: FilePath
nm = ParsecT s u m (ScalarExpr -> ScalarExpr)
-> Operator s u m ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m (a -> a) -> Operator s u m a
prefix' (ParsecT s u m a
p ParsecT s u m a
-> ParsecT s u m (ScalarExpr -> ScalarExpr)
-> ParsecT s u m (ScalarExpr -> ScalarExpr)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (ScalarExpr -> ScalarExpr)
-> ParsecT s u m (ScalarExpr -> ScalarExpr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Name] -> ScalarExpr -> ScalarExpr
PrefixOp [Maybe (FilePath, FilePath) -> FilePath -> Name
Name Maybe (FilePath, FilePath)
forall a. Maybe a
Nothing FilePath
nm]))
>     -- hack from here
>     -- http://stackoverflow.com/questions/10475337/parsec-expr-repeated-prefix-postfix-operator-not-supported
>     -- not implemented properly yet
>     -- I don't think this will be enough for all cases
>     -- at least it works for 'not not a'
>     -- ok: "x is not true is not true"
>     -- no work: "x is not true is not null"
>     prefix' :: ParsecT s u m (a -> a) -> Operator s u m a
prefix'  p :: ParsecT s u m (a -> a)
p = ParsecT s u m (a -> a) -> Operator s u m a
forall s u (m :: * -> *) a.
ParsecT s u m (a -> a) -> Operator s u m a
E.Prefix  (ParsecT s u m (a -> a) -> Operator s u m a)
-> (ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
    -> ParsecT s u m (a -> a))
-> ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
-> Operator s u m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT s u m (a -> a)
-> ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
-> ParsecT s u m (a -> a)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> ParsecT s u m a
chainl1 ParsecT s u m (a -> a)
p (ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
 -> Operator s u m a)
-> ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
-> Operator s u m a
forall a b. (a -> b) -> a -> b
$ ((a -> a) -> (a -> a) -> a -> a)
-> ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure       (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.)
>     postfix' :: ParsecT s u m (a -> a) -> Operator s u m a
postfix' p :: ParsecT s u m (a -> a)
p = ParsecT s u m (a -> a) -> Operator s u m a
forall s u (m :: * -> *) a.
ParsecT s u m (a -> a) -> Operator s u m a
E.Postfix (ParsecT s u m (a -> a) -> Operator s u m a)
-> (ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
    -> ParsecT s u m (a -> a))
-> ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
-> Operator s u m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT s u m (a -> a)
-> ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
-> ParsecT s u m (a -> a)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> ParsecT s u m a
chainl1 ParsecT s u m (a -> a)
p (ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
 -> Operator s u m a)
-> ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
-> Operator s u m a
forall a b. (a -> b) -> a -> b
$ ((a -> a) -> (a -> a) -> a -> a)
-> ParsecT s u m ((a -> a) -> (a -> a) -> a -> a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (((a -> a) -> (a -> a) -> a -> a) -> (a -> a) -> (a -> a) -> a -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.))

== scalar expression top level

This parses most of the scalar exprs.The order of the parsers and use
of try is carefully done to make everything work. It is a little
fragile and could at least do with some heavy explanation. Update: the
'try's have migrated into the individual parsers, they still need
documenting/fixing.

> scalarExpr :: Parser ScalarExpr
> scalarExpr :: Parser ScalarExpr
scalarExpr = [[Operator
    [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]]
-> Parser ScalarExpr -> Parser ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
OperatorTable s u m a -> ParsecT s u m a -> ParsecT s u m a
E.buildExpressionParser (Bool
-> [[Operator
       [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]]
opTable Bool
False) Parser ScalarExpr
term

> term :: Parser ScalarExpr
> term :: Parser ScalarExpr
term = [Parser ScalarExpr] -> Parser ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [Parser ScalarExpr
simpleLiteral
>               ,Parser ScalarExpr
parameter
>               ,Parser ScalarExpr
positionalArg
>               ,Parser ScalarExpr
star
>               ,Parser ScalarExpr
parensExpr
>               ,Parser ScalarExpr
caseExpr
>               ,Parser ScalarExpr
cast
>               ,Parser ScalarExpr
arrayCtor
>               ,Parser ScalarExpr
multisetCtor
>               ,Parser ScalarExpr
nextValueFor
>               ,Parser ScalarExpr
subquery
>               ,Parser ScalarExpr
intervalLit
>               ,Parser ScalarExpr
specialOpKs
>               ,Parser ScalarExpr
idenExpr
>               ,Parser ScalarExpr
odbcExpr]
>        Parser ScalarExpr -> FilePath -> Parser ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> "scalar expression"

expose the b expression for window frame clause range between

> scalarExprB :: Parser ScalarExpr
> scalarExprB :: Parser ScalarExpr
scalarExprB = [[Operator
    [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]]
-> Parser ScalarExpr -> Parser ScalarExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
OperatorTable s u m a -> ParsecT s u m a -> ParsecT s u m a
E.buildExpressionParser (Bool
-> [[Operator
       [((FilePath, Int, Int), Token)] Dialect Identity ScalarExpr]]
opTable Bool
True) Parser ScalarExpr
term

== helper parsers

This is used in interval literals and in interval type names.

> intervalQualifier :: Parser (IntervalTypeField,Maybe IntervalTypeField)
> intervalQualifier :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (IntervalTypeField, Maybe IntervalTypeField)
intervalQualifier =
>     (,) (IntervalTypeField
 -> Maybe IntervalTypeField
 -> (IntervalTypeField, Maybe IntervalTypeField))
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IntervalTypeField
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe IntervalTypeField
      -> (IntervalTypeField, Maybe IntervalTypeField))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity IntervalTypeField
intervalField
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe IntervalTypeField
   -> (IntervalTypeField, Maybe IntervalTypeField))
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe IntervalTypeField)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (IntervalTypeField, Maybe IntervalTypeField)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity IntervalTypeField
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe IntervalTypeField)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "to" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IntervalTypeField
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IntervalTypeField
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity IntervalTypeField
intervalField)
>   where
>     intervalField :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity IntervalTypeField
intervalField =
>         FilePath -> Maybe (Integer, Maybe Integer) -> IntervalTypeField
Itf
>         (FilePath -> Maybe (Integer, Maybe Integer) -> IntervalTypeField)
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (Integer, Maybe Integer) -> IntervalTypeField)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser FilePath
datetimeField
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe (Integer, Maybe Integer) -> IntervalTypeField)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (Integer, Maybe Integer))
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IntervalTypeField
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer, Maybe Integer)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (Integer, Maybe Integer))
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe
>             (ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer, Maybe Integer)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer, Maybe Integer)
forall a. Parser a -> Parser a
parens ((,) (Integer -> Maybe Integer -> (Integer, Maybe Integer))
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Integer -> (Integer, Maybe Integer))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
unsignedInteger
>                          ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Integer -> (Integer, Maybe Integer))
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Integer)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer, Maybe Integer)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Integer)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Parser Char
comma Parser Char
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
unsignedInteger)))

TODO: use datetime field in extract also
use a data type for the datetime field?

> datetimeField :: Parser String
> datetimeField :: Parser FilePath
datetimeField = [Parser FilePath] -> Parser FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ((FilePath -> Parser FilePath) -> [FilePath] -> [Parser FilePath]
forall a b. (a -> b) -> [a] -> [b]
map FilePath -> Parser FilePath
keyword ["year","month","day"
>                                     ,"hour","minute","second"])
>                 Parser FilePath -> FilePath -> Parser FilePath
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> "datetime field"

This is used in multiset operations (scalar expr), selects (query expr)
and set operations (query expr).

> duplicates :: Parser SetQuantifier
> duplicates :: Parser SetQuantifier
duplicates =
>     [Parser SetQuantifier] -> Parser SetQuantifier
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [SetQuantifier
All SetQuantifier
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser SetQuantifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "all"
>            ,SetQuantifier
Distinct SetQuantifier -> Parser FilePath -> Parser SetQuantifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
keyword "distinct"]

-------------------------------------------------

= query expressions

== select lists

> selectItem :: Parser (ScalarExpr,Maybe Name)
> selectItem :: Parser (ScalarExpr, Maybe Name)
selectItem = (,) (ScalarExpr -> Maybe Name -> (ScalarExpr, Maybe Name))
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Name -> (ScalarExpr, Maybe Name))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
scalarExpr ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Name -> (ScalarExpr, Maybe Name))
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
-> Parser (ScalarExpr, Maybe Name)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe Parser Name
als
>   where als :: Parser Name
als = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "as") ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Name -> Parser Name
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name
name

> selectList :: Parser [(ScalarExpr,Maybe Name)]
> selectList :: Parser [(ScalarExpr, Maybe Name)]
selectList = Parser (ScalarExpr, Maybe Name)
-> Parser [(ScalarExpr, Maybe Name)]
forall a. Parser a -> Parser [a]
commaSep1 Parser (ScalarExpr, Maybe Name)
selectItem

== from

Here is the rough grammar for joins

tref
(cross | [natural] ([inner] | (left | right | full) [outer])) join
tref
[on expr | using (...)]

TODO: either use explicit 'operator precedence' parsers or build
expression parser for the 'tref operators' such as joins, lateral,
aliases.

> from :: Parser [TableRef]
> from :: Parser [TableRef]
from = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "from" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [TableRef] -> Parser [TableRef]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TableRef -> Parser [TableRef]
forall a. Parser a -> Parser [a]
commaSep1 Parser TableRef
tref
>   where
>     -- TODO: use P (a->) for the join tref suffix
>     -- chainl or buildexpressionparser
>     tref :: Parser TableRef
tref = Parser TableRef
nonJoinTref Parser TableRef -> (TableRef -> Parser TableRef) -> Parser TableRef
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (TableRef -> Parser TableRef) -> TableRef -> Parser TableRef
forall a t s. (a -> GenParser t s a) -> a -> GenParser t s a
optionSuffix TableRef -> Parser TableRef
joinTrefSuffix
>     nonJoinTref :: Parser TableRef
nonJoinTref = [Parser TableRef] -> Parser TableRef
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>         [Parser TableRef -> Parser TableRef
forall a. Parser a -> Parser a
parens (Parser TableRef -> Parser TableRef)
-> Parser TableRef -> Parser TableRef
forall a b. (a -> b) -> a -> b
$ [Parser TableRef] -> Parser TableRef
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>              [QueryExpr -> TableRef
TRQueryExpr (QueryExpr -> TableRef) -> Parser QueryExpr -> Parser TableRef
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser QueryExpr
queryExpr
>              ,TableRef -> TableRef
TRParens (TableRef -> TableRef) -> Parser TableRef -> Parser TableRef
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TableRef
tref]
>         ,TableRef -> TableRef
TRLateral (TableRef -> TableRef) -> Parser TableRef -> Parser TableRef
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "lateral"
>                         ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser TableRef -> Parser TableRef
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TableRef
nonJoinTref)
>         ,do
>          [Name]
n <- Parser [Name]
names
>          [Parser TableRef] -> Parser TableRef
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [[Name] -> [ScalarExpr] -> TableRef
TRFunction [Name]
n
>                  ([ScalarExpr] -> TableRef)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> Parser TableRef
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser a
parens (Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep Parser ScalarExpr
scalarExpr)
>                 ,TableRef -> Parser TableRef
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TableRef -> Parser TableRef) -> TableRef -> Parser TableRef
forall a b. (a -> b) -> a -> b
$ [Name] -> TableRef
TRSimple [Name]
n]
>          -- todo: I think you can only have outer joins inside the oj,
>          -- not sure.
>         ,TableRef -> TableRef
TROdbc (TableRef -> TableRef) -> Parser TableRef -> Parser TableRef
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FilePath -> Parser FilePath
symbol "{" Parser FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "oj" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser TableRef -> Parser TableRef
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TableRef
tref Parser TableRef -> Parser FilePath -> Parser TableRef
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* FilePath -> Parser FilePath
symbol "}")
>         ] Parser TableRef
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (TableRef -> TableRef)
-> Parser TableRef
forall t s a.
GenParser t s a -> GenParser t s (a -> a) -> GenParser t s a
<??> GenParser
  ((FilePath, Int, Int), Token) Dialect (TableRef -> TableRef)
aliasSuffix
>     aliasSuffix :: GenParser
  ((FilePath, Int, Int), Token) Dialect (TableRef -> TableRef)
aliasSuffix = Parser Alias
fromAlias Parser Alias
-> (TableRef -> Alias -> TableRef)
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (TableRef -> TableRef)
forall (f :: * -> *) b a c.
Applicative f =>
f b -> (a -> b -> c) -> f (a -> c)
<$$> TableRef -> Alias -> TableRef
TRAlias
>     joinTrefSuffix :: TableRef -> Parser TableRef
joinTrefSuffix t :: TableRef
t =
>         (TableRef
-> Bool -> JoinType -> TableRef -> Maybe JoinCondition -> TableRef
TRJoin TableRef
t (Bool -> JoinType -> TableRef -> Maybe JoinCondition -> TableRef)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (JoinType -> TableRef -> Maybe JoinCondition -> TableRef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "natural")
>                   ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (JoinType -> TableRef -> Maybe JoinCondition -> TableRef)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (TableRef -> Maybe JoinCondition -> TableRef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
joinType
>                   ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (TableRef -> Maybe JoinCondition -> TableRef)
-> Parser TableRef
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe JoinCondition -> TableRef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser TableRef
nonJoinTref
>                   ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe JoinCondition -> TableRef)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe JoinCondition)
-> Parser TableRef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe JoinCondition)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
joinCondition)
>         Parser TableRef -> (TableRef -> Parser TableRef) -> Parser TableRef
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (TableRef -> Parser TableRef) -> TableRef -> Parser TableRef
forall a t s. (a -> GenParser t s a) -> a -> GenParser t s a
optionSuffix TableRef -> Parser TableRef
joinTrefSuffix

TODO: factor the join stuff to produce better error messages (and make
it more readable)

> joinType :: Parser JoinType
> joinType :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
joinType = [ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [JoinType
JCross JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "cross" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "join"
>     ,JoinType
JInner JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "inner" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "join"
>     ,JoinType
JLeft JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "left"
>            ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "outer")
>            ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "join"
>     ,JoinType
JRight JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "right"
>             ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "outer")
>             ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "join"
>     ,JoinType
JFull JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "full"
>            ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "outer")
>            ParsecT [((FilePath, Int, Int), Token)] Dialect Identity JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "join"
>     ,JoinType
JInner JoinType
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinType
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "join"]

> joinCondition :: Parser JoinCondition
> joinCondition :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
joinCondition = [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "on" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ScalarExpr -> JoinCondition
JoinOn (ScalarExpr -> JoinCondition)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
scalarExpr
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "using" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Name] -> JoinCondition
JoinUsing ([Name] -> JoinCondition)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity JoinCondition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep1 Parser Name
name)]

> fromAlias :: Parser Alias
> fromAlias :: Parser Alias
fromAlias = Name -> Maybe [Name] -> Alias
Alias (Name -> Maybe [Name] -> Alias)
-> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe [Name] -> Alias)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
tableAlias ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name] -> Alias)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
-> Parser Alias
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
columnAliases
>   where
>     tableAlias :: Parser Name
tableAlias = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "as") ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Name -> Parser Name
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name
name
>     columnAliases :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
columnAliases = Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Parser [Name]
 -> ParsecT
      [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name]))
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall a b. (a -> b) -> a -> b
$ Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser [Name] -> Parser [Name]) -> Parser [Name] -> Parser [Name]
forall a b. (a -> b) -> a -> b
$ Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep1 Parser Name
name

== simple other parts

Parsers for where, group by, having, order by and limit, which are
pretty trivial.

> whereClause :: Parser ScalarExpr
> whereClause :: Parser ScalarExpr
whereClause = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "where" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr

> groupByClause :: Parser [GroupingExpr]
> groupByClause :: Parser [GroupingExpr]
groupByClause = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["group","by"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [GroupingExpr] -> Parser [GroupingExpr]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser GroupingExpr -> Parser [GroupingExpr]
forall a. Parser a -> Parser [a]
commaSep1 Parser GroupingExpr
groupingExpression
>   where
>     groupingExpression :: Parser GroupingExpr
groupingExpression = [Parser GroupingExpr] -> Parser GroupingExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>       [FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "cube" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser GroupingExpr -> Parser GroupingExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>        [GroupingExpr] -> GroupingExpr
Cube ([GroupingExpr] -> GroupingExpr)
-> Parser [GroupingExpr] -> Parser GroupingExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [GroupingExpr] -> Parser [GroupingExpr]
forall a. Parser a -> Parser a
parens (Parser GroupingExpr -> Parser [GroupingExpr]
forall a. Parser a -> Parser [a]
commaSep Parser GroupingExpr
groupingExpression)
>       ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "rollup" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser GroupingExpr -> Parser GroupingExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>        [GroupingExpr] -> GroupingExpr
Rollup ([GroupingExpr] -> GroupingExpr)
-> Parser [GroupingExpr] -> Parser GroupingExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [GroupingExpr] -> Parser [GroupingExpr]
forall a. Parser a -> Parser a
parens (Parser GroupingExpr -> Parser [GroupingExpr]
forall a. Parser a -> Parser [a]
commaSep Parser GroupingExpr
groupingExpression)
>       ,[GroupingExpr] -> GroupingExpr
GroupingParens ([GroupingExpr] -> GroupingExpr)
-> Parser [GroupingExpr] -> Parser GroupingExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [GroupingExpr] -> Parser [GroupingExpr]
forall a. Parser a -> Parser a
parens (Parser GroupingExpr -> Parser [GroupingExpr]
forall a. Parser a -> Parser [a]
commaSep Parser GroupingExpr
groupingExpression)
>       ,[FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["grouping", "sets"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser GroupingExpr -> Parser GroupingExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>        [GroupingExpr] -> GroupingExpr
GroupingSets ([GroupingExpr] -> GroupingExpr)
-> Parser [GroupingExpr] -> Parser GroupingExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [GroupingExpr] -> Parser [GroupingExpr]
forall a. Parser a -> Parser a
parens (Parser GroupingExpr -> Parser [GroupingExpr]
forall a. Parser a -> Parser [a]
commaSep Parser GroupingExpr
groupingExpression)
>       ,ScalarExpr -> GroupingExpr
SimpleGroup (ScalarExpr -> GroupingExpr)
-> Parser ScalarExpr -> Parser GroupingExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
scalarExpr
>       ]

> having :: Parser ScalarExpr
> having :: Parser ScalarExpr
having = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "having" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr

> orderBy :: Parser [SortSpec]
> orderBy :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
orderBy = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["order","by"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser SortSpec
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
forall a. Parser a -> Parser [a]
commaSep1 Parser SortSpec
ob
>   where
>     ob :: Parser SortSpec
ob = ScalarExpr -> Direction -> NullsOrder -> SortSpec
SortSpec
>          (ScalarExpr -> Direction -> NullsOrder -> SortSpec)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Direction -> NullsOrder -> SortSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
scalarExpr
>          ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Direction -> NullsOrder -> SortSpec)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Direction
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (NullsOrder -> SortSpec)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Direction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Direction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Direction
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Direction
DirDefault ([ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity Direction]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Direction
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [Direction
Asc Direction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Direction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "asc"
>                                        ,Direction
Desc Direction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Direction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "desc"])
>          ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (NullsOrder -> SortSpec)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity NullsOrder
-> Parser SortSpec
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> NullsOrder
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity NullsOrder
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity NullsOrder
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option NullsOrder
NullsOrderDefault
>              -- todo: left factor better
>              (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "nulls" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity NullsOrder
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity NullsOrder
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                     [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity NullsOrder]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity NullsOrder
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [NullsOrder
NullsFirst NullsOrder
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity NullsOrder
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
keyword "first"
>                            ,NullsOrder
NullsLast NullsOrder
-> Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity NullsOrder
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
keyword "last"])

allows offset and fetch in either order
+ postgresql offset without row(s) and limit instead of fetch also

> offsetFetch :: Parser (Maybe ScalarExpr, Maybe ScalarExpr)
> offsetFetch :: Parser (Maybe ScalarExpr, Maybe ScalarExpr)
offsetFetch = StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe ScalarExpr, Maybe ScalarExpr)
-> Parser (Maybe ScalarExpr, Maybe ScalarExpr)
forall s tok st a.
Stream s Identity tok =>
StreamPermParser s st a -> Parsec s st a
permute ((,) (Maybe ScalarExpr
 -> Maybe ScalarExpr -> (Maybe ScalarExpr, Maybe ScalarExpr))
-> (Maybe ScalarExpr,
    ParsecT
      [((FilePath, Int, Int), Token)]
      Dialect
      Identity
      (Maybe ScalarExpr))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe ScalarExpr -> (Maybe ScalarExpr, Maybe ScalarExpr))
forall s tok a b st.
Stream s Identity tok =>
(a -> b) -> (a, Parsec s st a) -> StreamPermParser s st b
<$?> (Maybe ScalarExpr
forall a. Maybe a
Nothing, ScalarExpr -> Maybe ScalarExpr
forall a. a -> Maybe a
Just (ScalarExpr -> Maybe ScalarExpr)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
offset)
>                            StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe ScalarExpr -> (Maybe ScalarExpr, Maybe ScalarExpr))
-> (Maybe ScalarExpr,
    ParsecT
      [((FilePath, Int, Int), Token)]
      Dialect
      Identity
      (Maybe ScalarExpr))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe ScalarExpr, Maybe ScalarExpr)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Maybe ScalarExpr
forall a. Maybe a
Nothing, ScalarExpr -> Maybe ScalarExpr
forall a. a -> Maybe a
Just (ScalarExpr -> Maybe ScalarExpr)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
fetch))

> offset :: Parser ScalarExpr
> offset :: Parser ScalarExpr
offset = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "offset" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr
>          Parser ScalarExpr
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option () ([ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "rows"
>                               ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "row"])

> fetch :: Parser ScalarExpr
> fetch :: Parser ScalarExpr
fetch = Parser ScalarExpr
fetchFirst Parser ScalarExpr -> Parser ScalarExpr -> Parser ScalarExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser ScalarExpr
limit
>   where
>     fetchFirst :: Parser ScalarExpr
fetchFirst = (Dialect -> Bool)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
guardDialect Dialect -> Bool
diFetchFirst
>                  ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
fs ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
ro
>     fs :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
fs = [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
makeKeywordTree ["fetch first", "fetch next"]
>     ro :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
ro = [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
makeKeywordTree ["rows only", "row only"]
>     -- todo: not in ansi sql dialect
>     limit :: Parser ScalarExpr
limit = (Dialect -> Bool)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
guardDialect Dialect -> Bool
diLimit ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
>             FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "limit" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr

== common table expressions

> with :: Parser QueryExpr
> with :: Parser QueryExpr
with = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "with" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser QueryExpr -> Parser QueryExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     Bool -> [(Alias, QueryExpr)] -> QueryExpr -> QueryExpr
With (Bool -> [(Alias, QueryExpr)] -> QueryExpr -> QueryExpr)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([(Alias, QueryExpr)] -> QueryExpr -> QueryExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "recursive")
>          ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([(Alias, QueryExpr)] -> QueryExpr -> QueryExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [(Alias, QueryExpr)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (QueryExpr -> QueryExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Alias, QueryExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [(Alias, QueryExpr)]
forall a. Parser a -> Parser [a]
commaSep1 Parser (Alias, QueryExpr)
withQuery ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (QueryExpr -> QueryExpr)
-> Parser QueryExpr -> Parser QueryExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser QueryExpr
queryExpr
>   where
>     withQuery :: Parser (Alias, QueryExpr)
withQuery = (,) (Alias -> QueryExpr -> (Alias, QueryExpr))
-> Parser Alias
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (QueryExpr -> (Alias, QueryExpr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser Alias
withAlias Parser Alias
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Alias
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "as")
>                     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (QueryExpr -> (Alias, QueryExpr))
-> Parser QueryExpr -> Parser (Alias, QueryExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser QueryExpr -> Parser QueryExpr
forall a. Parser a -> Parser a
parens Parser QueryExpr
queryExpr
>     withAlias :: Parser Alias
withAlias = Name -> Maybe [Name] -> Alias
Alias (Name -> Maybe [Name] -> Alias)
-> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe [Name] -> Alias)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
name ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name] -> Alias)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
-> Parser Alias
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
columnAliases
>     columnAliases :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
columnAliases = Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Parser [Name]
 -> ParsecT
      [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name]))
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall a b. (a -> b) -> a -> b
$ Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser [Name] -> Parser [Name]) -> Parser [Name] -> Parser [Name]
forall a b. (a -> b) -> a -> b
$ Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep1 Parser Name
name


== query expression

This parser parses any query expression variant: normal select, cte,
and union, etc..

> queryExpr :: Parser QueryExpr
> queryExpr :: Parser QueryExpr
queryExpr = [Parser QueryExpr] -> Parser QueryExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [Parser QueryExpr
with
>     ,Parser QueryExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (QueryExpr -> QueryExpr -> QueryExpr)
-> Parser QueryExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> ParsecT s u m a
chainr1 ([Parser QueryExpr] -> Parser QueryExpr
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [Parser QueryExpr
values,Parser QueryExpr
table, Parser QueryExpr
select]) ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (QueryExpr -> QueryExpr -> QueryExpr)
setOp]
>   where
>     select :: Parser QueryExpr
select = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "select" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser QueryExpr -> Parser QueryExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>         SetQuantifier
-> [(ScalarExpr, Maybe Name)] -> Maybe TableExpression -> QueryExpr
mkSelect
>         (SetQuantifier
 -> [(ScalarExpr, Maybe Name)]
 -> Maybe TableExpression
 -> QueryExpr)
-> Parser SetQuantifier
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([(ScalarExpr, Maybe Name)] -> Maybe TableExpression -> QueryExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SetQuantifier -> Parser SetQuantifier -> Parser SetQuantifier
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option SetQuantifier
SQDefault Parser SetQuantifier
duplicates
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([(ScalarExpr, Maybe Name)] -> Maybe TableExpression -> QueryExpr)
-> Parser [(ScalarExpr, Maybe Name)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe TableExpression -> QueryExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [(ScalarExpr, Maybe Name)]
selectList
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe TableExpression -> QueryExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe TableExpression)
-> Parser QueryExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableExpression
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe TableExpression)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableExpression
tableExpression
>     mkSelect :: SetQuantifier
-> [(ScalarExpr, Maybe Name)] -> Maybe TableExpression -> QueryExpr
mkSelect d :: SetQuantifier
d sl :: [(ScalarExpr, Maybe Name)]
sl Nothing =
>         QueryExpr
makeSelect{qeSetQuantifier :: SetQuantifier
qeSetQuantifier = SetQuantifier
d, qeSelectList :: [(ScalarExpr, Maybe Name)]
qeSelectList = [(ScalarExpr, Maybe Name)]
sl}
>     mkSelect d :: SetQuantifier
d sl :: [(ScalarExpr, Maybe Name)]
sl (Just (TableExpression f :: [TableRef]
f w :: Maybe ScalarExpr
w g :: [GroupingExpr]
g h :: Maybe ScalarExpr
h od :: [SortSpec]
od ofs :: Maybe ScalarExpr
ofs fe :: Maybe ScalarExpr
fe)) =
>         SetQuantifier
-> [(ScalarExpr, Maybe Name)]
-> [TableRef]
-> Maybe ScalarExpr
-> [GroupingExpr]
-> Maybe ScalarExpr
-> [SortSpec]
-> Maybe ScalarExpr
-> Maybe ScalarExpr
-> QueryExpr
Select SetQuantifier
d [(ScalarExpr, Maybe Name)]
sl [TableRef]
f Maybe ScalarExpr
w [GroupingExpr]
g Maybe ScalarExpr
h [SortSpec]
od Maybe ScalarExpr
ofs Maybe ScalarExpr
fe
>     values :: Parser QueryExpr
values = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "values"
>              ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser QueryExpr -> Parser QueryExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [[ScalarExpr]] -> QueryExpr
Values ([[ScalarExpr]] -> QueryExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [[ScalarExpr]]
-> Parser QueryExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [[ScalarExpr]]
forall a. Parser a -> Parser [a]
commaSep (ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser a
parens (Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep Parser ScalarExpr
scalarExpr))
>     table :: Parser QueryExpr
table = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "table" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser QueryExpr -> Parser QueryExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Name] -> QueryExpr
Table ([Name] -> QueryExpr) -> Parser [Name] -> Parser QueryExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names

local data type to help with parsing the bit after the select list,
called 'table expression' in the ansi sql grammar. Maybe this should
be in the public syntax?

> data TableExpression
>     = TableExpression
>       {TableExpression -> [TableRef]
_teFrom :: [TableRef]
>       ,TableExpression -> Maybe ScalarExpr
_teWhere :: Maybe ScalarExpr
>       ,TableExpression -> [GroupingExpr]
_teGroupBy :: [GroupingExpr]
>       ,TableExpression -> Maybe ScalarExpr
_teHaving :: Maybe ScalarExpr
>       ,TableExpression -> [SortSpec]
_teOrderBy :: [SortSpec]
>       ,TableExpression -> Maybe ScalarExpr
_teOffset :: Maybe ScalarExpr
>       ,TableExpression -> Maybe ScalarExpr
_teFetchFirst :: Maybe ScalarExpr}

> tableExpression :: Parser TableExpression
> tableExpression :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableExpression
tableExpression = [TableRef]
-> Maybe ScalarExpr
-> [GroupingExpr]
-> Maybe ScalarExpr
-> [SortSpec]
-> (Maybe ScalarExpr, Maybe ScalarExpr)
-> TableExpression
mkTe ([TableRef]
 -> Maybe ScalarExpr
 -> [GroupingExpr]
 -> Maybe ScalarExpr
 -> [SortSpec]
 -> (Maybe ScalarExpr, Maybe ScalarExpr)
 -> TableExpression)
-> Parser [TableRef]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe ScalarExpr
      -> [GroupingExpr]
      -> Maybe ScalarExpr
      -> [SortSpec]
      -> (Maybe ScalarExpr, Maybe ScalarExpr)
      -> TableExpression)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [TableRef]
from
>                        ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe ScalarExpr
   -> [GroupingExpr]
   -> Maybe ScalarExpr
   -> [SortSpec]
   -> (Maybe ScalarExpr, Maybe ScalarExpr)
   -> TableExpression)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([GroupingExpr]
      -> Maybe ScalarExpr
      -> [SortSpec]
      -> (Maybe ScalarExpr, Maybe ScalarExpr)
      -> TableExpression)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe Parser ScalarExpr
whereClause
>                        ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([GroupingExpr]
   -> Maybe ScalarExpr
   -> [SortSpec]
   -> (Maybe ScalarExpr, Maybe ScalarExpr)
   -> TableExpression)
-> Parser [GroupingExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe ScalarExpr
      -> [SortSpec]
      -> (Maybe ScalarExpr, Maybe ScalarExpr)
      -> TableExpression)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [GroupingExpr] -> Parser [GroupingExpr] -> Parser [GroupingExpr]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] Parser [GroupingExpr]
groupByClause
>                        ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe ScalarExpr
   -> [SortSpec]
   -> (Maybe ScalarExpr, Maybe ScalarExpr)
   -> TableExpression)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SortSpec]
      -> (Maybe ScalarExpr, Maybe ScalarExpr) -> TableExpression)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe Parser ScalarExpr
having
>                        ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([SortSpec]
   -> (Maybe ScalarExpr, Maybe ScalarExpr) -> TableExpression)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ((Maybe ScalarExpr, Maybe ScalarExpr) -> TableExpression)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [SortSpec]
orderBy
>                        ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ((Maybe ScalarExpr, Maybe ScalarExpr) -> TableExpression)
-> Parser (Maybe ScalarExpr, Maybe ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableExpression
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Maybe ScalarExpr, Maybe ScalarExpr)
offsetFetch
>  where
>     mkTe :: [TableRef]
-> Maybe ScalarExpr
-> [GroupingExpr]
-> Maybe ScalarExpr
-> [SortSpec]
-> (Maybe ScalarExpr, Maybe ScalarExpr)
-> TableExpression
mkTe f :: [TableRef]
f w :: Maybe ScalarExpr
w g :: [GroupingExpr]
g h :: Maybe ScalarExpr
h od :: [SortSpec]
od (ofs :: Maybe ScalarExpr
ofs,fe :: Maybe ScalarExpr
fe) =
>         [TableRef]
-> Maybe ScalarExpr
-> [GroupingExpr]
-> Maybe ScalarExpr
-> [SortSpec]
-> Maybe ScalarExpr
-> Maybe ScalarExpr
-> TableExpression
TableExpression [TableRef]
f Maybe ScalarExpr
w [GroupingExpr]
g Maybe ScalarExpr
h [SortSpec]
od Maybe ScalarExpr
ofs Maybe ScalarExpr
fe

> setOp :: Parser (QueryExpr -> QueryExpr -> QueryExpr)
> setOp :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (QueryExpr -> QueryExpr -> QueryExpr)
setOp = SetOperatorName
-> SetQuantifier
-> Corresponding
-> QueryExpr
-> QueryExpr
-> QueryExpr
cq
>         (SetOperatorName
 -> SetQuantifier
 -> Corresponding
 -> QueryExpr
 -> QueryExpr
 -> QueryExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (SetQuantifier
      -> Corresponding -> QueryExpr -> QueryExpr -> QueryExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
setOpK
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (SetQuantifier
   -> Corresponding -> QueryExpr -> QueryExpr -> QueryExpr)
-> Parser SetQuantifier
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Corresponding -> QueryExpr -> QueryExpr -> QueryExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SetQuantifier -> Parser SetQuantifier -> Parser SetQuantifier
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option SetQuantifier
SQDefault Parser SetQuantifier
duplicates
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Corresponding -> QueryExpr -> QueryExpr -> QueryExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Corresponding
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (QueryExpr -> QueryExpr -> QueryExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity Corresponding
corr
>   where
>     cq :: SetOperatorName
-> SetQuantifier
-> Corresponding
-> QueryExpr
-> QueryExpr
-> QueryExpr
cq o :: SetOperatorName
o d :: SetQuantifier
d c :: Corresponding
c q0 :: QueryExpr
q0 q1 :: QueryExpr
q1 = QueryExpr
-> SetOperatorName
-> SetQuantifier
-> Corresponding
-> QueryExpr
-> QueryExpr
QueryExprSetOp QueryExpr
q0 SetOperatorName
o SetQuantifier
d Corresponding
c QueryExpr
q1
>     setOpK :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
setOpK = [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [SetOperatorName
Union SetOperatorName
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "union"
>                     ,SetOperatorName
Intersect SetOperatorName
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "intersect"
>                     ,SetOperatorName
Except SetOperatorName
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "except"]
>             ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
-> FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity SetOperatorName
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> "set operator"
>     corr :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity Corresponding
corr = Corresponding
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Corresponding
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Corresponding
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Corresponding
Respectively (Corresponding
Corresponding Corresponding
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity Corresponding
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "corresponding")


wrapper for query expr which ignores optional trailing semicolon.

TODO: change style

> topLevelQueryExpr :: Parser QueryExpr
> topLevelQueryExpr :: Parser QueryExpr
topLevelQueryExpr = Parser QueryExpr
queryExpr Parser QueryExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (QueryExpr -> QueryExpr)
-> Parser QueryExpr
forall t s a.
GenParser t s a -> GenParser t s (a -> a) -> GenParser t s a
<??> (QueryExpr -> QueryExpr
forall a. a -> a
id (QueryExpr -> QueryExpr)
-> Parser Char
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (QueryExpr -> QueryExpr)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser Char
semi)

> topLevelStatement :: Parser Statement
> topLevelStatement :: Parser Statement
topLevelStatement = Parser Statement
statement Parser Statement
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (Statement -> Statement)
-> Parser Statement
forall t s a.
GenParser t s a -> GenParser t s (a -> a) -> GenParser t s a
<??> (Statement -> Statement
forall a. a -> a
id (Statement -> Statement)
-> Parser Char
-> GenParser
     ((FilePath, Int, Int), Token) Dialect (Statement -> Statement)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser Char
semi)

-------------------------

= Statements

> statement :: Parser Statement
> statement :: Parser Statement
statement = [Parser Statement] -> Parser Statement
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "create" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [Parser Statement] -> Parser Statement
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [Parser Statement
createSchema
>                                  ,Parser Statement
createTable
>                                  ,Parser Statement
createView
>                                  ,Parser Statement
createDomain
>                                  ,Parser Statement
createSequence
>                                  ,Parser Statement
createRole
>                                  ,Parser Statement
createAssertion]
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "alter" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [Parser Statement] -> Parser Statement
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [Parser Statement
alterTable
>                                 ,Parser Statement
alterDomain
>                                 ,Parser Statement
alterSequence]
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "drop" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [Parser Statement] -> Parser Statement
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [Parser Statement
dropSchema
>                                ,Parser Statement
dropTable
>                                ,Parser Statement
dropView
>                                ,Parser Statement
dropDomain
>                                ,Parser Statement
dropSequence
>                                ,Parser Statement
dropRole
>                                ,Parser Statement
dropAssertion]
>     ,Parser Statement
delete
>     ,Parser Statement
truncateSt
>     ,Parser Statement
insert
>     ,Parser Statement
update
>     ,Parser Statement
startTransaction
>     ,Parser Statement
savepoint
>     ,Parser Statement
releaseSavepoint
>     ,Parser Statement
commit
>     ,Parser Statement
rollback
>     ,Parser Statement
grant
>     ,Parser Statement
revoke
>     ,QueryExpr -> Statement
SelectStatement (QueryExpr -> Statement) -> Parser QueryExpr -> Parser Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser QueryExpr
queryExpr
>     ]

> createSchema :: Parser Statement
> createSchema :: Parser Statement
createSchema = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "schema" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> Statement
CreateSchema ([Name] -> Statement) -> Parser [Name] -> Parser Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names

> createTable :: Parser Statement
> createTable :: Parser Statement
createTable = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "table" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> [TableElement] -> Statement
CreateTable
>     ([Name] -> [TableElement] -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([TableElement] -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     -- todo: is this order mandatory or is it a perm?
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([TableElement] -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [TableElement]
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [TableElement]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [TableElement]
forall a. Parser a -> Parser a
parens (Parser TableElement
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [TableElement]
forall a. Parser a -> Parser [a]
commaSep1 ((Maybe [Name] -> TableConstraint -> TableElement)
-> (Maybe [Name], TableConstraint) -> TableElement
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Maybe [Name] -> TableConstraint -> TableElement
TableConstraintDef ((Maybe [Name], TableConstraint) -> TableElement)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe [Name], TableConstraint)
-> Parser TableElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name], TableConstraint)
tableConstraintDef
>                            Parser TableElement -> Parser TableElement -> Parser TableElement
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ColumnDef -> TableElement
TableColumnDef (ColumnDef -> TableElement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColumnDef
-> Parser TableElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ColumnDef
columnDef))

> columnDef :: Parser ColumnDef
> columnDef :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ColumnDef
columnDef = Name
-> TypeName
-> Maybe DefaultClause
-> [ColConstraintDef]
-> ColumnDef
ColumnDef (Name
 -> TypeName
 -> Maybe DefaultClause
 -> [ColConstraintDef]
 -> ColumnDef)
-> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (TypeName
      -> Maybe DefaultClause -> [ColConstraintDef] -> ColumnDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
name ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (TypeName
   -> Maybe DefaultClause -> [ColConstraintDef] -> ColumnDef)
-> Parser TypeName
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe DefaultClause -> [ColConstraintDef] -> ColumnDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser TypeName
typeName
>             ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe DefaultClause -> [ColConstraintDef] -> ColumnDef)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe DefaultClause)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ColConstraintDef] -> ColumnDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe DefaultClause)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
defaultClause
>             ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ColConstraintDef] -> ColumnDef)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ColConstraintDef]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColumnDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [ColConstraintDef]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ColConstraintDef]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ColConstraintDef]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraintDef
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ColConstraintDef]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraintDef
colConstraintDef)
>   where
>     defaultClause :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
defaultClause = [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [
>         FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "default" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>         ScalarExpr -> DefaultClause
DefaultClause (ScalarExpr -> DefaultClause)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
scalarExpr
>         -- todo: left factor
>        ,ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["generated","always","as"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>              ScalarExpr -> DefaultClause
GenerationClause (ScalarExpr -> DefaultClause)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens Parser ScalarExpr
scalarExpr)
>        ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "generated" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>         IdentityWhen -> [SequenceGeneratorOption] -> DefaultClause
IdentityColumnSpec
>         (IdentityWhen -> [SequenceGeneratorOption] -> DefaultClause)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityWhen
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SequenceGeneratorOption] -> DefaultClause)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (IdentityWhen
GeneratedAlways IdentityWhen
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityWhen
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "always"
>              ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity IdentityWhen
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityWhen
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityWhen
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> IdentityWhen
GeneratedByDefault IdentityWhen
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityWhen
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["by", "default"])
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([SequenceGeneratorOption] -> DefaultClause)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [SequenceGeneratorOption]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DefaultClause
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["as", "identity"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [SequenceGeneratorOption]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [SequenceGeneratorOption]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
>              [SequenceGeneratorOption]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [SequenceGeneratorOption]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [SequenceGeneratorOption]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  [SequenceGeneratorOption]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [SequenceGeneratorOption]
forall a. Parser a -> Parser a
parens ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  [SequenceGeneratorOption]
sequenceGeneratorOptions))
>        ]

> tableConstraintDef :: Parser (Maybe [Name], TableConstraint)
> tableConstraintDef :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name], TableConstraint)
tableConstraintDef =
>     (,)
>     (Maybe [Name]
 -> TableConstraint -> (Maybe [Name], TableConstraint))
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (TableConstraint -> (Maybe [Name], TableConstraint))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "constraint" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser [Name]
names))
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (TableConstraint -> (Maybe [Name], TableConstraint))
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe [Name], TableConstraint)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
unique ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
primaryKey ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
check ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
references)
>   where
>     unique :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
unique = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "unique" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>         [Name] -> TableConstraint
TableUniqueConstraint ([Name] -> TableConstraint)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep1 Parser Name
name)
>     primaryKey :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
primaryKey = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["primary", "key"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>         [Name] -> TableConstraint
TablePrimaryKeyConstraint ([Name] -> TableConstraint)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep1 Parser Name
name)
>     check :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
check = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "check" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ScalarExpr -> TableConstraint
TableCheckConstraint (ScalarExpr -> TableConstraint)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens Parser ScalarExpr
scalarExpr
>     references :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
references = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["foreign", "key"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>         (\cs :: [Name]
cs ft :: [Name]
ft ftcs :: Maybe [Name]
ftcs m :: ReferenceMatch
m (u :: ReferentialAction
u,d :: ReferentialAction
d) -> [Name]
-> [Name]
-> Maybe [Name]
-> ReferenceMatch
-> ReferentialAction
-> ReferentialAction
-> TableConstraint
TableReferencesConstraint [Name]
cs [Name]
ft Maybe [Name]
ftcs ReferenceMatch
m ReferentialAction
u ReferentialAction
d)
>         ([Name]
 -> [Name]
 -> Maybe [Name]
 -> ReferenceMatch
 -> (ReferentialAction, ReferentialAction)
 -> TableConstraint)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name]
      -> Maybe [Name]
      -> ReferenceMatch
      -> (ReferentialAction, ReferentialAction)
      -> TableConstraint)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep1 Parser Name
name)
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name]
   -> Maybe [Name]
   -> ReferenceMatch
   -> (ReferentialAction, ReferentialAction)
   -> TableConstraint)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe [Name]
      -> ReferenceMatch
      -> (ReferentialAction, ReferentialAction)
      -> TableConstraint)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "references" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser [Name]
names)
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name]
   -> ReferenceMatch
   -> (ReferentialAction, ReferentialAction)
   -> TableConstraint)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ReferenceMatch
      -> (ReferentialAction, ReferentialAction) -> TableConstraint)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser [Name] -> Parser [Name]) -> Parser [Name] -> Parser [Name]
forall a b. (a -> b) -> a -> b
$ Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep1 Parser Name
name)
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ReferenceMatch
   -> (ReferentialAction, ReferentialAction) -> TableConstraint)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ((ReferentialAction, ReferentialAction) -> TableConstraint)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
refMatch
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ((ReferentialAction, ReferentialAction) -> TableConstraint)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ReferentialAction, ReferentialAction)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity TableConstraint
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ReferentialAction, ReferentialAction)
refActions

> refMatch :: Parser ReferenceMatch
> refMatch :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
refMatch = ReferenceMatch
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option ReferenceMatch
DefaultReferenceMatch
>             (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "match" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
>              [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ReferenceMatch
MatchFull ReferenceMatch
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "full"
>                     ,ReferenceMatch
MatchPartial ReferenceMatch
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "partial"
>                     ,ReferenceMatch
MatchSimple ReferenceMatch
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "simple"])
> refActions :: Parser (ReferentialAction,ReferentialAction)
> refActions :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ReferentialAction, ReferentialAction)
refActions = StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (ReferentialAction, ReferentialAction)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ReferentialAction, ReferentialAction)
forall s tok st a.
Stream s Identity tok =>
StreamPermParser s st a -> Parsec s st a
permute ((,) (ReferentialAction
 -> ReferentialAction -> (ReferentialAction, ReferentialAction))
-> (ReferentialAction,
    Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction)
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (ReferentialAction -> (ReferentialAction, ReferentialAction))
forall s tok a b st.
Stream s Identity tok =>
(a -> b) -> (a, Parsec s st a) -> StreamPermParser s st b
<$?> (ReferentialAction
DefaultReferentialAction, Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
onUpdate)
>                           StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (ReferentialAction -> (ReferentialAction, ReferentialAction))
-> (ReferentialAction,
    Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction)
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (ReferentialAction, ReferentialAction)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (ReferentialAction
DefaultReferentialAction, Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
onDelete))
>   where
>     -- todo: left factor?
>     onUpdate :: Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
onUpdate = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["on", "update"]) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
referentialAction
>     onDelete :: Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
onDelete = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["on", "delete"]) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
referentialAction
>     referentialAction :: Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
referentialAction = [Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction]
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [
>          ReferentialAction
RefCascade ReferentialAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "cascade"
>          -- todo: left factor?
>         ,ReferentialAction
RefSetNull ReferentialAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["set", "null"])
>         ,ReferentialAction
RefSetDefault ReferentialAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["set", "default"])
>         ,ReferentialAction
RefRestrict ReferentialAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "restrict"
>         ,ReferentialAction
RefNoAction ReferentialAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parsec [((FilePath, Int, Int), Token)] Dialect ReferentialAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["no", "action"]]

> colConstraintDef :: Parser ColConstraintDef
> colConstraintDef :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraintDef
colConstraintDef =
>     Maybe [Name] -> ColConstraint -> ColConstraintDef
ColConstraintDef
>     (Maybe [Name] -> ColConstraint -> ColConstraintDef)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ColConstraint -> ColConstraintDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "constraint" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser [Name]
names))
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ColConstraint -> ColConstraintDef)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraintDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
notNull ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
unique ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
primaryKey ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
check ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
references)
>   where
>     notNull :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
notNull = ColConstraint
ColNotNullConstraint ColConstraint
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["not", "null"]
>     unique :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
unique = ColConstraint
ColUniqueConstraint ColConstraint
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "unique"
>     primaryKey :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
primaryKey = ColConstraint
ColPrimaryKeyConstraint ColConstraint
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["primary", "key"]
>     check :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
check = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "check" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ScalarExpr -> ColConstraint
ColCheckConstraint (ScalarExpr -> ColConstraint)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens Parser ScalarExpr
scalarExpr
>     references :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
references = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "references" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>         (\t :: [Name]
t c :: Maybe Name
c m :: ReferenceMatch
m (ou :: ReferentialAction
ou,od :: ReferentialAction
od) -> [Name]
-> Maybe Name
-> ReferenceMatch
-> ReferentialAction
-> ReferentialAction
-> ColConstraint
ColReferencesConstraint [Name]
t Maybe Name
c ReferenceMatch
m ReferentialAction
ou ReferentialAction
od)
>         ([Name]
 -> Maybe Name
 -> ReferenceMatch
 -> (ReferentialAction, ReferentialAction)
 -> ColConstraint)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Name
      -> ReferenceMatch
      -> (ReferentialAction, ReferentialAction)
      -> ColConstraint)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Name
   -> ReferenceMatch
   -> (ReferentialAction, ReferentialAction)
   -> ColConstraint)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ReferenceMatch
      -> (ReferentialAction, ReferentialAction) -> ColConstraint)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Parser Name -> Parser Name
forall a. Parser a -> Parser a
parens Parser Name
name)
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ReferenceMatch
   -> (ReferentialAction, ReferentialAction) -> ColConstraint)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ((ReferentialAction, ReferentialAction) -> ColConstraint)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity ReferenceMatch
refMatch
>         ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ((ReferentialAction, ReferentialAction) -> ColConstraint)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ReferentialAction, ReferentialAction)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColConstraint
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ReferentialAction, ReferentialAction)
refActions

slightly hacky parser for signed integers

> signedInteger :: Parser Integer
> signedInteger :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
signedInteger =
>     Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
(*) (Integer -> Integer -> Integer)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Integer -> Integer)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option 1 (1 Integer
-> Parser FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
symbol "+" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (-1) Integer
-> Parser FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
symbol "-")
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Integer -> Integer)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
unsignedInteger

> sequenceGeneratorOptions :: Parser [SequenceGeneratorOption]
> sequenceGeneratorOptions :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  [SequenceGeneratorOption]
sequenceGeneratorOptions =
>          -- todo: could try to combine exclusive options
>          -- such as cycle and nocycle
>          -- sort out options which are sometimes not allowed
>          -- as datatype, and restart with
>     StreamPermParser
  [((FilePath, Int, Int), Token)] Dialect [SequenceGeneratorOption]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [SequenceGeneratorOption]
forall s tok st a.
Stream s Identity tok =>
StreamPermParser s st a -> Parsec s st a
permute ((\a :: Maybe SequenceGeneratorOption
a b :: Maybe SequenceGeneratorOption
b c :: Maybe SequenceGeneratorOption
c d :: Maybe SequenceGeneratorOption
d e :: Maybe SequenceGeneratorOption
e f :: Maybe SequenceGeneratorOption
f g :: Maybe SequenceGeneratorOption
g h :: Maybe SequenceGeneratorOption
h j :: Maybe SequenceGeneratorOption
j k :: Maybe SequenceGeneratorOption
k -> [Maybe SequenceGeneratorOption] -> [SequenceGeneratorOption]
forall a. [Maybe a] -> [a]
catMaybes [Maybe SequenceGeneratorOption
a,Maybe SequenceGeneratorOption
b,Maybe SequenceGeneratorOption
c,Maybe SequenceGeneratorOption
d,Maybe SequenceGeneratorOption
e,Maybe SequenceGeneratorOption
f,Maybe SequenceGeneratorOption
g,Maybe SequenceGeneratorOption
h,Maybe SequenceGeneratorOption
j,Maybe SequenceGeneratorOption
k])
>                   (Maybe SequenceGeneratorOption
 -> Maybe SequenceGeneratorOption
 -> Maybe SequenceGeneratorOption
 -> Maybe SequenceGeneratorOption
 -> Maybe SequenceGeneratorOption
 -> Maybe SequenceGeneratorOption
 -> Maybe SequenceGeneratorOption
 -> Maybe SequenceGeneratorOption
 -> Maybe SequenceGeneratorOption
 -> Maybe SequenceGeneratorOption
 -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> [SequenceGeneratorOption])
forall s tok a b st.
Stream s Identity tok =>
(a -> b) -> (a, Parsec s st a) -> StreamPermParser s st b
<$?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
startWith
>                   StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> [SequenceGeneratorOption])
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
dataType
>                   StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> [SequenceGeneratorOption])
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
restart
>                   StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> [SequenceGeneratorOption])
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
incrementBy
>                   StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> [SequenceGeneratorOption])
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
maxValue
>                   StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> [SequenceGeneratorOption])
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
noMaxValue
>                   StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption
      -> [SequenceGeneratorOption])
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
minValue
>                   StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption
   -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe SequenceGeneratorOption
      -> Maybe SequenceGeneratorOption -> [SequenceGeneratorOption])
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
noMinValue
>                   StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe SequenceGeneratorOption
   -> Maybe SequenceGeneratorOption -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)]
     Dialect
     (Maybe SequenceGeneratorOption -> [SequenceGeneratorOption])
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
scycle
>                   StreamPermParser
  [((FilePath, Int, Int), Token)]
  Dialect
  (Maybe SequenceGeneratorOption -> [SequenceGeneratorOption])
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
-> StreamPermParser
     [((FilePath, Int, Int), Token)] Dialect [SequenceGeneratorOption]
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
-> (Maybe SequenceGeneratorOption,
    Parsec
      [((FilePath, Int, Int), Token)]
      Dialect
      (Maybe SequenceGeneratorOption))
forall (f :: * -> *) a a.
Functor f =>
f a -> (Maybe a, f (Maybe a))
nj ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
noCycle
>                  )
>   where
>     nj :: f a -> (Maybe a, f (Maybe a))
nj p :: f a
p = (Maybe a
forall a. Maybe a
Nothing,a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> f a -> f (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
p)
>     startWith :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
startWith = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["start", "with"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                 Integer -> SequenceGeneratorOption
SGOStartWith (Integer -> SequenceGeneratorOption)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
signedInteger
>     dataType :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
dataType = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "as" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                TypeName -> SequenceGeneratorOption
SGODataType (TypeName -> SequenceGeneratorOption)
-> Parser TypeName
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TypeName
typeName
>     restart :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
restart = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "restart" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>               Maybe Integer -> SequenceGeneratorOption
SGORestart (Maybe Integer -> SequenceGeneratorOption)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Integer)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Integer)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "with" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
signedInteger)
>     incrementBy :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
incrementBy = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["increment", "by"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                 Integer -> SequenceGeneratorOption
SGOIncrementBy (Integer -> SequenceGeneratorOption)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
signedInteger
>     maxValue :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
maxValue = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "maxvalue" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                 Integer -> SequenceGeneratorOption
SGOMaxValue (Integer -> SequenceGeneratorOption)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
signedInteger
>     noMaxValue :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
noMaxValue = SequenceGeneratorOption
SGONoMaxValue SequenceGeneratorOption
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["no","maxvalue"])
>     minValue :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
minValue = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "minvalue" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                 Integer -> SequenceGeneratorOption
SGOMinValue (Integer -> SequenceGeneratorOption)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
signedInteger
>     noMinValue :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
noMinValue = SequenceGeneratorOption
SGONoMinValue SequenceGeneratorOption
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["no","minvalue"])
>     scycle :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
scycle = SequenceGeneratorOption
SGOCycle SequenceGeneratorOption
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "cycle"
>     noCycle :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  SequenceGeneratorOption
noCycle = SequenceGeneratorOption
SGONoCycle SequenceGeneratorOption
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     SequenceGeneratorOption
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["no","cycle"])


> alterTable :: Parser Statement
> alterTable :: Parser Statement
alterTable = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "table" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     -- the choices have been ordered so that it works
>     [Name] -> AlterTableAction -> Statement
AlterTable ([Name] -> AlterTableAction -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (AlterTableAction -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (AlterTableAction -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
addConstraint
>                                     ,ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
dropConstraint
>                                     ,ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
addColumnDef
>                                     ,ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
alterColumn
>                                     ,ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
dropColumn
>                                     ]
>   where
>     addColumnDef :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
addColumnDef = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "add"
>                         ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "column")) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                    ColumnDef -> AlterTableAction
AddColumnDef (ColumnDef -> AlterTableAction)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity ColumnDef
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ColumnDef
columnDef
>     alterColumn :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
alterColumn = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "alter" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "column") ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                   Parser Name
name Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> [ParsecT
   [((FilePath, Int, Int), Token)]
   Dialect
   Identity
   (Name -> AlterTableAction)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
setDefault
>                                    ,ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
dropDefault
>                                    ,ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
setNotNull
>                                    ,ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
dropNotNull
>                                    ,ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
setDataType]
>     setDefault :: Parser (Name -> AlterTableAction)
>     -- todo: left factor
>     setDefault :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
setDefault = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["set","default"]) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                  Parser ScalarExpr
scalarExpr Parser ScalarExpr
-> (Name -> ScalarExpr -> AlterTableAction)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
forall (f :: * -> *) b a c.
Applicative f =>
f b -> (a -> b -> c) -> f (a -> c)
<$$> Name -> ScalarExpr -> AlterTableAction
AlterColumnSetDefault
>     dropDefault :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
dropDefault = Name -> AlterTableAction
AlterColumnDropDefault (Name -> AlterTableAction)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["drop","default"])
>     setNotNull :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
setNotNull = Name -> AlterTableAction
AlterColumnSetNotNull (Name -> AlterTableAction)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["set","not","null"])
>     dropNotNull :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
dropNotNull = Name -> AlterTableAction
AlterColumnDropNotNull (Name -> AlterTableAction)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["drop","not","null"])
>     setDataType :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Name -> AlterTableAction)
setDataType = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["set","data","type"]) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                   Parser TypeName
typeName Parser TypeName
-> (Name -> TypeName -> AlterTableAction)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Name -> AlterTableAction)
forall (f :: * -> *) b a c.
Applicative f =>
f b -> (a -> b -> c) -> f (a -> c)
<$$> Name -> TypeName -> AlterTableAction
AlterColumnSetDataType
>     dropColumn :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
dropColumn = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "drop" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "column")) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>                  Name -> DropBehaviour -> AlterTableAction
DropColumn (Name -> DropBehaviour -> AlterTableAction)
-> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> AlterTableAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
name ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> AlterTableAction)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour
>     -- todo: left factor, this try is especially bad
>     addConstraint :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
addConstraint = ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "add" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>         (Maybe [Name] -> TableConstraint -> AlterTableAction)
-> (Maybe [Name], TableConstraint) -> AlterTableAction
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Maybe [Name] -> TableConstraint -> AlterTableAction
AddTableConstraintDef ((Maybe [Name], TableConstraint) -> AlterTableAction)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe [Name], TableConstraint)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name], TableConstraint)
tableConstraintDef)
>     dropConstraint :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
dropConstraint = ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["drop","constraint"]) ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>         [Name] -> DropBehaviour -> AlterTableAction
DropTableConstraintDef ([Name] -> DropBehaviour -> AlterTableAction)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> AlterTableAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> AlterTableAction)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterTableAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour


> dropSchema :: Parser Statement
> dropSchema :: Parser Statement
dropSchema = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "schema" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> DropBehaviour -> Statement
DropSchema ([Name] -> DropBehaviour -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour

> dropTable :: Parser Statement
> dropTable :: Parser Statement
dropTable = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "table" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> DropBehaviour -> Statement
DropTable ([Name] -> DropBehaviour -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour

> createView :: Parser Statement
> createView :: Parser Statement
createView =
>     Bool
-> [Name]
-> Maybe [Name]
-> QueryExpr
-> Maybe CheckOption
-> Statement
CreateView
>     (Bool
 -> [Name]
 -> Maybe [Name]
 -> QueryExpr
 -> Maybe CheckOption
 -> Statement)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name]
      -> Maybe [Name] -> QueryExpr -> Maybe CheckOption -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "recursive") ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Bool
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "view")
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name]
   -> Maybe [Name] -> QueryExpr -> Maybe CheckOption -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe [Name] -> QueryExpr -> Maybe CheckOption -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name] -> QueryExpr -> Maybe CheckOption -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (QueryExpr -> Maybe CheckOption -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep1 Parser Name
name))
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (QueryExpr -> Maybe CheckOption -> Statement)
-> Parser QueryExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe CheckOption -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "as" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser QueryExpr -> Parser QueryExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser QueryExpr
queryExpr)
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe CheckOption -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe CheckOption)
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity CheckOption
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe CheckOption)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ([ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity CheckOption]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity CheckOption
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [
>             -- todo: left factor
>             CheckOption
DefaultCheckOption CheckOption
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity CheckOption
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["with", "check", "option"])
>            ,CheckOption
CascadedCheckOption CheckOption
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity CheckOption
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["with", "cascaded", "check", "option"])
>            ,CheckOption
LocalCheckOption CheckOption
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity CheckOption
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["with", "local", "check", "option"])
>             ])

> dropView :: Parser Statement
> dropView :: Parser Statement
dropView = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "view" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> DropBehaviour -> Statement
DropView ([Name] -> DropBehaviour -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour

> createDomain :: Parser Statement
> createDomain :: Parser Statement
createDomain = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "domain" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name]
-> TypeName
-> Maybe ScalarExpr
-> [(Maybe [Name], ScalarExpr)]
-> Statement
CreateDomain
>     ([Name]
 -> TypeName
 -> Maybe ScalarExpr
 -> [(Maybe [Name], ScalarExpr)]
 -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (TypeName
      -> Maybe ScalarExpr -> [(Maybe [Name], ScalarExpr)] -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (TypeName
   -> Maybe ScalarExpr -> [(Maybe [Name], ScalarExpr)] -> Statement)
-> Parser TypeName
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe ScalarExpr -> [(Maybe [Name], ScalarExpr)] -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "as") ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser TypeName -> Parser TypeName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TypeName
typeName)
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe ScalarExpr -> [(Maybe [Name], ScalarExpr)] -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([(Maybe [Name], ScalarExpr)] -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "default" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr)
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([(Maybe [Name], ScalarExpr)] -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [(Maybe [Name], ScalarExpr)]
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name], ScalarExpr)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [(Maybe [Name], ScalarExpr)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name], ScalarExpr)
con
>   where
>     con :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name], ScalarExpr)
con = (,) (Maybe [Name] -> ScalarExpr -> (Maybe [Name], ScalarExpr))
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> (Maybe [Name], ScalarExpr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "constraint" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser [Name]
names)
>           ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> (Maybe [Name], ScalarExpr))
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe [Name], ScalarExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "check" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens Parser ScalarExpr
scalarExpr)

> alterDomain :: Parser Statement
> alterDomain :: Parser Statement
alterDomain = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "domain" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> AlterDomainAction -> Statement
AlterDomain
>     ([Name] -> AlterDomainAction -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (AlterDomainAction -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (AlterDomainAction -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
setDefault ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
constraint
>          ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "drop" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
dropDefault ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
dropConstraint)))
>   where
>     setDefault :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
setDefault = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["set", "default"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ScalarExpr -> AlterDomainAction
ADSetDefault (ScalarExpr -> AlterDomainAction)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ScalarExpr
scalarExpr
>     constraint :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
constraint = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "add" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>        Maybe [Name] -> ScalarExpr -> AlterDomainAction
ADAddConstraint
>        (Maybe [Name] -> ScalarExpr -> AlterDomainAction)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> AlterDomainAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "constraint" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser [Name]
names)
>        ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> AlterDomainAction)
-> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "check" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens Parser ScalarExpr
scalarExpr)
>     dropDefault :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
dropDefault = AlterDomainAction
ADDropDefault AlterDomainAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "default"
>     dropConstraint :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
dropConstraint = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "constraint" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Name] -> AlterDomainAction
ADDropConstraint ([Name] -> AlterDomainAction)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AlterDomainAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names

> dropDomain :: Parser Statement
> dropDomain :: Parser Statement
dropDomain = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "domain" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> DropBehaviour -> Statement
DropDomain ([Name] -> DropBehaviour -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour

> createSequence :: Parser Statement
> createSequence :: Parser Statement
createSequence = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "sequence" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> [SequenceGeneratorOption] -> Statement
CreateSequence
>     ([Name] -> [SequenceGeneratorOption] -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SequenceGeneratorOption] -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([SequenceGeneratorOption] -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [SequenceGeneratorOption]
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  [SequenceGeneratorOption]
sequenceGeneratorOptions

> alterSequence :: Parser Statement
> alterSequence :: Parser Statement
alterSequence = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "sequence" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> [SequenceGeneratorOption] -> Statement
AlterSequence
>     ([Name] -> [SequenceGeneratorOption] -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SequenceGeneratorOption] -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([SequenceGeneratorOption] -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     [SequenceGeneratorOption]
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  [SequenceGeneratorOption]
sequenceGeneratorOptions

> dropSequence :: Parser Statement
> dropSequence :: Parser Statement
dropSequence = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "sequence" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> DropBehaviour -> Statement
DropSequence ([Name] -> DropBehaviour -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour

> createAssertion :: Parser Statement
> createAssertion :: Parser Statement
createAssertion = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "assertion" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> ScalarExpr -> Statement
CreateAssertion
>     ([Name] -> ScalarExpr -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> Statement)
-> Parser ScalarExpr -> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "check" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr -> Parser ScalarExpr
forall a. Parser a -> Parser a
parens Parser ScalarExpr
scalarExpr)


> dropAssertion :: Parser Statement
> dropAssertion :: Parser Statement
dropAssertion = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "assertion" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> DropBehaviour -> Statement
DropAssertion ([Name] -> DropBehaviour -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour

-----------------

= dml

> delete :: Parser Statement
> delete :: Parser Statement
delete = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["delete","from"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> Maybe Name -> Maybe ScalarExpr -> Statement
Delete
>     ([Name] -> Maybe Name -> Maybe ScalarExpr -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Name -> Maybe ScalarExpr -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Name -> Maybe ScalarExpr -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe ScalarExpr -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "as") ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Name -> Parser Name
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name
name)
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe ScalarExpr -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "where" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr)

> truncateSt :: Parser Statement
> truncateSt :: Parser Statement
truncateSt = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["truncate", "table"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> IdentityRestart -> Statement
Truncate
>     ([Name] -> IdentityRestart -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (IdentityRestart -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (IdentityRestart -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityRestart
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IdentityRestart
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityRestart
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityRestart
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option IdentityRestart
DefaultIdentityRestart
>         (IdentityRestart
ContinueIdentity IdentityRestart
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityRestart
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["continue","identity"]
>          ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity IdentityRestart
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityRestart
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityRestart
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> IdentityRestart
RestartIdentity IdentityRestart
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity IdentityRestart
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["restart","identity"])

> insert :: Parser Statement
> insert :: Parser Statement
insert = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["insert", "into"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name] -> Maybe [Name] -> InsertSource -> Statement
Insert
>     ([Name] -> Maybe [Name] -> InsertSource -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe [Name] -> InsertSource -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe [Name] -> InsertSource -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (InsertSource -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe [Name])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser [Name] -> Parser [Name]) -> Parser [Name] -> Parser [Name]
forall a b. (a -> b) -> a -> b
$ Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep1 Parser Name
name)
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (InsertSource -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InsertSource
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (InsertSource
DefaultInsertValues InsertSource
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InsertSource
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["default", "values"]
>          ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity InsertSource
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InsertSource
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InsertSource
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> QueryExpr -> InsertSource
InsertQuery (QueryExpr -> InsertSource)
-> Parser QueryExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity InsertSource
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser QueryExpr
queryExpr)

> update :: Parser Statement
> update :: Parser Statement
update = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["update"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     [Name]
-> Maybe Name -> [SetClause] -> Maybe ScalarExpr -> Statement
Update
>     ([Name]
 -> Maybe Name -> [SetClause] -> Maybe ScalarExpr -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe Name -> [SetClause] -> Maybe ScalarExpr -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe Name -> [SetClause] -> Maybe ScalarExpr -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([SetClause] -> Maybe ScalarExpr -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "as") ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Name -> Parser Name
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name
name)
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([SetClause] -> Maybe ScalarExpr -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SetClause]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe ScalarExpr -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "set" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SetClause]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SetClause]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser SetClause
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [SetClause]
forall a. Parser a -> Parser [a]
commaSep1 Parser SetClause
setClause)
>     ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (Maybe ScalarExpr -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe ScalarExpr)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "where" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr)
>   where
>     setClause :: Parser SetClause
setClause = Parser SetClause
multipleSet Parser SetClause -> Parser SetClause -> Parser SetClause
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser SetClause
singleSet
>     multipleSet :: Parser SetClause
multipleSet = [[Name]] -> [ScalarExpr] -> SetClause
SetMultiple
>                   ([[Name]] -> [ScalarExpr] -> SetClause)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [[Name]]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([ScalarExpr] -> SetClause)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [[Name]]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [[Name]]
forall a. Parser a -> Parser a
parens (Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [[Name]]
forall a. Parser a -> Parser [a]
commaSep1 Parser [Name]
names)
>                   ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([ScalarExpr] -> SetClause)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> Parser SetClause
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath -> Parser FilePath
symbol "=" Parser FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser a
parens (Parser ScalarExpr
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [ScalarExpr]
forall a. Parser a -> Parser [a]
commaSep1 Parser ScalarExpr
scalarExpr))
>     singleSet :: Parser SetClause
singleSet = [Name] -> ScalarExpr -> SetClause
Set
>                 ([Name] -> ScalarExpr -> SetClause)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (ScalarExpr -> SetClause)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>                 ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (ScalarExpr -> SetClause)
-> Parser ScalarExpr -> Parser SetClause
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath -> Parser FilePath
symbol "=" Parser FilePath -> Parser ScalarExpr -> Parser ScalarExpr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ScalarExpr
scalarExpr)

> dropBehaviour :: Parser DropBehaviour
> dropBehaviour :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour =
>     DropBehaviour
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option DropBehaviour
DefaultDropBehaviour
>     (DropBehaviour
Restrict DropBehaviour
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "restrict"
>     ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DropBehaviour
Cascade DropBehaviour
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "cascade")

-----------------------------

= transaction management

> startTransaction :: Parser Statement
> startTransaction :: Parser Statement
startTransaction = Statement
StartTransaction Statement
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["start","transaction"]

> savepoint :: Parser Statement
> savepoint :: Parser Statement
savepoint = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "savepoint" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     Name -> Statement
Savepoint (Name -> Statement) -> Parser Name -> Parser Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
name

> releaseSavepoint :: Parser Statement
> releaseSavepoint :: Parser Statement
releaseSavepoint = [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["release","savepoint"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     Name -> Statement
ReleaseSavepoint (Name -> Statement) -> Parser Name -> Parser Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
name

> commit :: Parser Statement
> commit :: Parser Statement
commit = Statement
Commit Statement
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "commit" Parser Statement
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "work")

> rollback :: Parser Statement
> rollback :: Parser Statement
rollback = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "rollback" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "work") ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     Maybe Name -> Statement
Rollback (Maybe Name -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
-> Parser Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity (Maybe Name)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ([FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["to", "savepoint"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Name -> Parser Name
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name
name)


------------------------------

= Access control

TODO: fix try at the 'on'

> grant :: Parser Statement
> grant :: Parser Statement
grant = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "grant" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Parser Statement -> Parser Statement
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser Statement
priv Parser Statement -> Parser Statement -> Parser Statement
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser Statement
role)
>   where
>     priv :: Parser Statement
priv = [PrivilegeAction]
-> PrivilegeObject -> [Name] -> GrantOption -> Statement
GrantPrivilege
>            ([PrivilegeAction]
 -> PrivilegeObject -> [Name] -> GrantOption -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [PrivilegeAction]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (PrivilegeObject -> [Name] -> GrantOption -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser PrivilegeAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [PrivilegeAction]
forall a. Parser a -> Parser [a]
commaSep Parser PrivilegeAction
privilegeAction
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (PrivilegeObject -> [Name] -> GrantOption -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> GrantOption -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "on" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
privilegeObject)
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> GrantOption -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (GrantOption -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "to" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name)
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (GrantOption -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity GrantOption
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GrantOption
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity GrantOption
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity GrantOption
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option GrantOption
WithoutGrantOption
>                (GrantOption
WithGrantOption GrantOption
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity GrantOption
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["with","grant","option"])
>     role :: Parser Statement
role = [Name] -> [Name] -> AdminOption -> Statement
GrantRole
>            ([Name] -> [Name] -> AdminOption -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> AdminOption -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> AdminOption -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (AdminOption -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "to" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name)
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (AdminOption -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AdminOption
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AdminOption
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AdminOption
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AdminOption
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option AdminOption
WithoutAdminOption
>                (AdminOption
WithAdminOption AdminOption
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AdminOption
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["with","admin","option"])

> createRole :: Parser Statement
> createRole :: Parser Statement
createRole = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "role" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     Name -> Statement
CreateRole (Name -> Statement) -> Parser Name -> Parser Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
name

> dropRole :: Parser Statement
> dropRole :: Parser Statement
dropRole = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "role" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>     Name -> Statement
DropRole (Name -> Statement) -> Parser Name -> Parser Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Name
name

TODO: fix try at the 'on'

> revoke :: Parser Statement
> revoke :: Parser Statement
revoke = FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "revoke" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser Statement -> Parser Statement
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Parser Statement -> Parser Statement
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser Statement
priv Parser Statement -> Parser Statement -> Parser Statement
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser Statement
role)
>   where
>     priv :: Parser Statement
priv = GrantOptionFor
-> [PrivilegeAction]
-> PrivilegeObject
-> [Name]
-> DropBehaviour
-> Statement
RevokePrivilege
>            (GrantOptionFor
 -> [PrivilegeAction]
 -> PrivilegeObject
 -> [Name]
 -> DropBehaviour
 -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity GrantOptionFor
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([PrivilegeAction]
      -> PrivilegeObject -> [Name] -> DropBehaviour -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GrantOptionFor
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity GrantOptionFor
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity GrantOptionFor
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option GrantOptionFor
NoGrantOptionFor
>                (GrantOptionFor
GrantOptionFor GrantOptionFor
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity GrantOptionFor
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["grant","option","for"])
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([PrivilegeAction]
   -> PrivilegeObject -> [Name] -> DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [PrivilegeAction]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (PrivilegeObject -> [Name] -> DropBehaviour -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PrivilegeAction
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [PrivilegeAction]
forall a. Parser a -> Parser [a]
commaSep Parser PrivilegeAction
privilegeAction
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (PrivilegeObject -> [Name] -> DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> DropBehaviour -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "on" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
privilegeObject)
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> DropBehaviour -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "from" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name)
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour
>     role :: Parser Statement
role = AdminOptionFor -> [Name] -> [Name] -> DropBehaviour -> Statement
RevokeRole
>            (AdminOptionFor -> [Name] -> [Name] -> DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AdminOptionFor
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> [Name] -> DropBehaviour -> Statement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AdminOptionFor
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AdminOptionFor
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AdminOptionFor
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option AdminOptionFor
NoAdminOptionFor
>                (AdminOptionFor
AdminOptionFor AdminOptionFor
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity AdminOptionFor
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["admin","option", "for"])
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> [Name] -> DropBehaviour -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     ([Name] -> DropBehaviour -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  ([Name] -> DropBehaviour -> Statement)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (DropBehaviour -> Statement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "from" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser [Name] -> Parser [Name]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name)
>            ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (DropBehaviour -> Statement)
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
-> Parser Statement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity DropBehaviour
dropBehaviour

> privilegeAction :: Parser PrivilegeAction
> privilegeAction :: Parser PrivilegeAction
privilegeAction = [Parser PrivilegeAction] -> Parser PrivilegeAction
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [PrivilegeAction
PrivAll PrivilegeAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser PrivilegeAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["all","privileges"]
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "select" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser PrivilegeAction -> Parser PrivilegeAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>      [Name] -> PrivilegeAction
PrivSelect ([Name] -> PrivilegeAction)
-> Parser [Name] -> Parser PrivilegeAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Name] -> Parser [Name] -> Parser [Name]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser [Name] -> Parser [Name]) -> Parser [Name] -> Parser [Name]
forall a b. (a -> b) -> a -> b
$ Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name)
>     ,PrivilegeAction
PrivDelete PrivilegeAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser PrivilegeAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "delete"
>     ,PrivilegeAction
PrivUsage PrivilegeAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser PrivilegeAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "usage"
>     ,PrivilegeAction
PrivTrigger PrivilegeAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser PrivilegeAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "trigger"
>     ,PrivilegeAction
PrivExecute PrivilegeAction
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser PrivilegeAction
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "execute"
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "insert" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser PrivilegeAction -> Parser PrivilegeAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>      [Name] -> PrivilegeAction
PrivInsert ([Name] -> PrivilegeAction)
-> Parser [Name] -> Parser PrivilegeAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Name] -> Parser [Name] -> Parser [Name]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser [Name] -> Parser [Name]) -> Parser [Name] -> Parser [Name]
forall a b. (a -> b) -> a -> b
$ Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name)
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "update" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser PrivilegeAction -> Parser PrivilegeAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>      [Name] -> PrivilegeAction
PrivUpdate ([Name] -> PrivilegeAction)
-> Parser [Name] -> Parser PrivilegeAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Name] -> Parser [Name] -> Parser [Name]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser [Name] -> Parser [Name]) -> Parser [Name] -> Parser [Name]
forall a b. (a -> b) -> a -> b
$ Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name)
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "references" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> Parser PrivilegeAction -> Parser PrivilegeAction
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
>      [Name] -> PrivilegeAction
PrivReferences ([Name] -> PrivilegeAction)
-> Parser [Name] -> Parser PrivilegeAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Name] -> Parser [Name] -> Parser [Name]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (Parser [Name] -> Parser [Name]
forall a. Parser a -> Parser a
parens (Parser [Name] -> Parser [Name]) -> Parser [Name] -> Parser [Name]
forall a b. (a -> b) -> a -> b
$ Parser Name -> Parser [Name]
forall a. Parser a -> Parser [a]
commaSep Parser Name
name)
>     ]

> privilegeObject :: Parser PrivilegeObject
> privilegeObject :: ParsecT
  [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
privilegeObject = [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
>     [FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "domain" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Name] -> PrivilegeObject
PrivDomain ([Name] -> PrivilegeObject)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "type" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Name] -> PrivilegeObject
PrivType ([Name] -> PrivilegeObject)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ,FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "sequence" ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Name] -> PrivilegeObject
PrivSequence ([Name] -> PrivilegeObject)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ,[FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ["specific","function"] ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Name] -> PrivilegeObject
PrivFunction ([Name] -> PrivilegeObject)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ,ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ "table") ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Name] -> PrivilegeObject
PrivTable ([Name] -> PrivilegeObject)
-> Parser [Name]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity PrivilegeObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Name]
names
>     ]


----------------------------

wrapper to parse a series of statements. They must be separated by
semicolon, but for the last statement, the trailing semicolon is
optional.

TODO: change style

> statements :: Parser [Statement]
> statements :: Parser [Statement]
statements = (Statement -> [Statement] -> [Statement]
forall a. a -> [a] -> [a]
:[]) (Statement -> [Statement])
-> Parser Statement -> Parser [Statement]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Statement
statement
>              Parser [Statement]
-> ([Statement] -> Parser [Statement]) -> Parser [Statement]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([Statement] -> Parser [Statement])
-> [Statement] -> Parser [Statement]
forall a t s. (a -> GenParser t s a) -> a -> GenParser t s a
optionSuffix ((Parser Char
semi Parser Char -> Parser [Statement] -> Parser [Statement]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>) (Parser [Statement] -> Parser [Statement])
-> ([Statement] -> Parser [Statement])
-> [Statement]
-> Parser [Statement]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Statement] -> Parser [Statement]
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
>              Parser [Statement]
-> ([Statement] -> Parser [Statement]) -> Parser [Statement]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([Statement] -> Parser [Statement])
-> [Statement] -> Parser [Statement]
forall a t s. (a -> GenParser t s a) -> a -> GenParser t s a
optionSuffix (\p :: [Statement]
p -> ([Statement]
p[Statement] -> [Statement] -> [Statement]
forall a. [a] -> [a] -> [a]
++) ([Statement] -> [Statement])
-> Parser [Statement] -> Parser [Statement]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Statement]
statements)

----------------------------------------------

= multi keyword helper

This helper is to help parsing multiple options of multiple keywords
with similar prefixes, e.g. parsing 'is null' and 'is not null'.

use to left factor/ improve:
typed literal and general identifiers
not like, not in, not between operators
help with factoring keyword functions and other app-likes
the join keyword sequences
fetch first/next
row/rows only

There is probably a simpler way of doing this but I am a bit
thick.

> makeKeywordTree :: [String] -> Parser [String]
> makeKeywordTree :: [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
makeKeywordTree sets :: [FilePath]
sets =
>     [[FilePath]]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
parseTrees ([[FilePath]] -> [[FilePath]]
forall a. Ord a => [a] -> [a]
sort ([[FilePath]] -> [[FilePath]]) -> [[FilePath]] -> [[FilePath]]
forall a b. (a -> b) -> a -> b
$ (FilePath -> [FilePath]) -> [FilePath] -> [[FilePath]]
forall a b. (a -> b) -> [a] -> [b]
map FilePath -> [FilePath]
words [FilePath]
sets)
>   where
>     parseTrees :: [[String]] -> Parser [String]
>     parseTrees :: [[FilePath]]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
parseTrees ws :: [[FilePath]]
ws = do
>       let gs :: [[[String]]]
>           gs :: [[[FilePath]]]
gs = ([FilePath] -> [FilePath] -> Bool)
-> [[FilePath]] -> [[[FilePath]]]
forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy (Maybe FilePath -> Maybe FilePath -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Maybe FilePath -> Maybe FilePath -> Bool)
-> ([FilePath] -> Maybe FilePath)
-> [FilePath]
-> [FilePath]
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` [FilePath] -> Maybe FilePath
forall a. [a] -> Maybe a
safeHead) [[FilePath]]
ws
>       [ParsecT
   [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([ParsecT
    [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]]
 -> ParsecT
      [((FilePath, Int, Int), Token)] Dialect Identity [FilePath])
-> [ParsecT
      [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
forall a b. (a -> b) -> a -> b
$ ([[FilePath]]
 -> ParsecT
      [((FilePath, Int, Int), Token)] Dialect Identity [FilePath])
-> [[[FilePath]]]
-> [ParsecT
      [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]]
forall a b. (a -> b) -> [a] -> [b]
map [[FilePath]]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
parseGroup [[[FilePath]]]
gs
>     parseGroup :: [[String]] -> Parser [String]
>     parseGroup :: [[FilePath]]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
parseGroup l :: [[FilePath]]
l@((k :: FilePath
k:_):_) = do
>         FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ FilePath
k
>         let tls :: [[FilePath]]
tls = [Maybe [FilePath]] -> [[FilePath]]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe [FilePath]] -> [[FilePath]])
-> [Maybe [FilePath]] -> [[FilePath]]
forall a b. (a -> b) -> a -> b
$ ([FilePath] -> Maybe [FilePath])
-> [[FilePath]] -> [Maybe [FilePath]]
forall a b. (a -> b) -> [a] -> [b]
map [FilePath] -> Maybe [FilePath]
forall a. [a] -> Maybe [a]
safeTail [[FilePath]]
l
>             pr :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
pr = (FilePath
kFilePath -> [FilePath] -> [FilePath]
forall a. a -> [a] -> [a]
:) ([FilePath] -> [FilePath])
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[FilePath]]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
parseTrees [[FilePath]]
tls
>         if ([Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ([Bool] -> Bool) -> [Bool] -> Bool
forall a b. (a -> b) -> a -> b
$ ([FilePath] -> Bool) -> [[FilePath]] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map [FilePath] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[FilePath]]
tls)
>           then ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
pr ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [FilePath
k]
>           else ParsecT [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
pr
>     parseGroup _ = Bool -> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
False ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FilePath
-> ParsecT
     [((FilePath, Int, Int), Token)] Dialect Identity [FilePath]
forall a. HasCallStack => FilePath -> a
error "impossible"
>     safeHead :: [a] -> Maybe a
safeHead (x :: a
x:_) = a -> Maybe a
forall a. a -> Maybe a
Just a
x
>     safeHead [] = Maybe a
forall a. Maybe a
Nothing
>     safeTail :: [a] -> Maybe [a]
safeTail (_:x :: [a]
x) = [a] -> Maybe [a]
forall a. a -> Maybe a
Just [a]
x
>     safeTail [] = Maybe [a]
forall a. Maybe a
Nothing

------------------------------------------------

= lexing

TODO: push checks into here:
keyword blacklists
unsigned integer match
symbol matching
keyword matching

> stringTok :: Parser (String,String,String)
> stringTok :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (FilePath, FilePath, FilePath)
stringTok = (Token -> Maybe (FilePath, FilePath, FilePath))
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FilePath, FilePath, FilePath)
forall a. (Token -> Maybe a) -> Parser a
mytoken (\tok :: Token
tok ->
>     case Token
tok of
>       L.SqlString s :: FilePath
s e :: FilePath
e t :: FilePath
t -> (FilePath, FilePath, FilePath)
-> Maybe (FilePath, FilePath, FilePath)
forall a. a -> Maybe a
Just (FilePath
s,FilePath
e,FilePath
t)
>       _ -> Maybe (FilePath, FilePath, FilePath)
forall a. Maybe a
Nothing)

> singleQuotesOnlyStringTok :: Parser String
> singleQuotesOnlyStringTok :: Parser FilePath
singleQuotesOnlyStringTok = (Token -> Maybe FilePath) -> Parser FilePath
forall a. (Token -> Maybe a) -> Parser a
mytoken (\tok :: Token
tok ->
>     case Token
tok of
>       L.SqlString "'" "'" t :: FilePath
t -> FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
t
>       _ -> Maybe FilePath
forall a. Maybe a
Nothing)

This is to support SQL strings where you can write
'part of a string' ' another part'
and it will parse as a single string

It is only allowed when all the strings are quoted with ' atm.

> stringTokExtend :: Parser (String,String,String)
> stringTokExtend :: ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (FilePath, FilePath, FilePath)
stringTokExtend = do
>     (s :: FilePath
s,e :: FilePath
e,x :: FilePath
x) <- ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (FilePath, FilePath, FilePath)
stringTok
>     [ParsecT
   [((FilePath, Int, Int), Token)]
   Dialect
   Identity
   (FilePath, FilePath, FilePath)]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FilePath, FilePath, FilePath)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [
>          do
>          Bool -> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (FilePath
s FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== "'" Bool -> Bool -> Bool
&& FilePath
e FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== "'")
>          (s' :: FilePath
s',e' :: FilePath
e',y :: FilePath
y) <- ParsecT
  [((FilePath, Int, Int), Token)]
  Dialect
  Identity
  (FilePath, FilePath, FilePath)
stringTokExtend
>          Bool -> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (FilePath
s' FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== "'" Bool -> Bool -> Bool
&& FilePath
e' FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== "'")
>          (FilePath, FilePath, FilePath)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FilePath, FilePath, FilePath)
forall (m :: * -> *) a. Monad m => a -> m a
return ((FilePath, FilePath, FilePath)
 -> ParsecT
      [((FilePath, Int, Int), Token)]
      Dialect
      Identity
      (FilePath, FilePath, FilePath))
-> (FilePath, FilePath, FilePath)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FilePath, FilePath, FilePath)
forall a b. (a -> b) -> a -> b
$ (FilePath
s,FilePath
e,FilePath
x FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
y)
>         ,(FilePath, FilePath, FilePath)
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (FilePath, FilePath, FilePath)
forall (m :: * -> *) a. Monad m => a -> m a
return (FilePath
s,FilePath
e,FilePath
x)
>         ]

> hostParamTok :: Parser String
> hostParamTok :: Parser FilePath
hostParamTok = (Token -> Maybe FilePath) -> Parser FilePath
forall a. (Token -> Maybe a) -> Parser a
mytoken (\tok :: Token
tok ->
>     case Token
tok of
>       L.PrefixedVariable c :: Char
c p :: FilePath
p -> FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (Char
cChar -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:FilePath
p)
>       _ -> Maybe FilePath
forall a. Maybe a
Nothing)

> positionalArgTok :: Parser Int
> positionalArgTok :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Int
positionalArgTok = (Token -> Maybe Int)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Int
forall a. (Token -> Maybe a) -> Parser a
mytoken (\tok :: Token
tok ->
>     case Token
tok of
>       L.PositionalArg p :: Int
p -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
p
>       _ -> Maybe Int
forall a. Maybe a
Nothing)


> sqlNumberTok :: Bool -> Parser String
> sqlNumberTok :: Bool -> Parser FilePath
sqlNumberTok intOnly :: Bool
intOnly = (Token -> Maybe FilePath) -> Parser FilePath
forall a. (Token -> Maybe a) -> Parser a
mytoken (\tok :: Token
tok ->
>     case Token
tok of
>       L.SqlNumber p :: FilePath
p | Bool -> Bool
not Bool
intOnly Bool -> Bool -> Bool
|| (Char -> Bool) -> FilePath -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isDigit FilePath
p -> FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
p
>       _ -> Maybe FilePath
forall a. Maybe a
Nothing)


> symbolTok :: Maybe String -> Parser String
> symbolTok :: Maybe FilePath -> Parser FilePath
symbolTok sym :: Maybe FilePath
sym = (Token -> Maybe FilePath) -> Parser FilePath
forall a. (Token -> Maybe a) -> Parser a
mytoken (\tok :: Token
tok ->
>     case (Maybe FilePath
sym,Token
tok) of
>       (Nothing, L.Symbol p :: FilePath
p) -> FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
p
>       (Just s :: FilePath
s, L.Symbol p :: FilePath
p) | FilePath
s FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== FilePath
p -> FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
p
>       _ -> Maybe FilePath
forall a. Maybe a
Nothing)

> identifierTok :: [String] -> Parser (Maybe (String,String), String)
> identifierTok :: [FilePath]
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (FilePath, FilePath), FilePath)
identifierTok blackList :: [FilePath]
blackList = (Token -> Maybe (Maybe (FilePath, FilePath), FilePath))
-> ParsecT
     [((FilePath, Int, Int), Token)]
     Dialect
     Identity
     (Maybe (FilePath, FilePath), FilePath)
forall a. (Token -> Maybe a) -> Parser a
mytoken (\tok :: Token
tok ->
>     case Token
tok of
>       L.Identifier q :: Maybe (FilePath, FilePath)
q@(Just {}) p :: FilePath
p -> (Maybe (FilePath, FilePath), FilePath)
-> Maybe (Maybe (FilePath, FilePath), FilePath)
forall a. a -> Maybe a
Just (Maybe (FilePath, FilePath)
q,FilePath
p)
>       L.Identifier q :: Maybe (FilePath, FilePath)
q p :: FilePath
p | (Char -> Char) -> FilePath -> FilePath
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower FilePath
p FilePath -> [FilePath] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [FilePath]
blackList -> (Maybe (FilePath, FilePath), FilePath)
-> Maybe (Maybe (FilePath, FilePath), FilePath)
forall a. a -> Maybe a
Just (Maybe (FilePath, FilePath)
q,FilePath
p)
>       _ -> Maybe (Maybe (FilePath, FilePath), FilePath)
forall a. Maybe a
Nothing)

> unquotedIdentifierTok :: [String] -> Maybe String -> Parser String
> unquotedIdentifierTok :: [FilePath] -> Maybe FilePath -> Parser FilePath
unquotedIdentifierTok blackList :: [FilePath]
blackList kw :: Maybe FilePath
kw = (Token -> Maybe FilePath) -> Parser FilePath
forall a. (Token -> Maybe a) -> Parser a
mytoken (\tok :: Token
tok ->
>     case (Maybe FilePath
kw,Token
tok) of
>       (Nothing, L.Identifier Nothing p :: FilePath
p) | (Char -> Char) -> FilePath -> FilePath
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower FilePath
p FilePath -> [FilePath] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [FilePath]
blackList -> FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
p
>       (Just k :: FilePath
k, L.Identifier Nothing p :: FilePath
p) | FilePath
k FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== (Char -> Char) -> FilePath -> FilePath
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower FilePath
p -> FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
p
>       _ -> Maybe FilePath
forall a. Maybe a
Nothing)

> mytoken :: (L.Token -> Maybe a) -> Parser a
> mytoken :: (Token -> Maybe a) -> Parser a
mytoken test :: Token -> Maybe a
test = (((FilePath, Int, Int), Token) -> FilePath)
-> (((FilePath, Int, Int), Token) -> SourcePos)
-> (((FilePath, Int, Int), Token) -> Maybe a)
-> Parser a
forall s t a u.
Stream s Identity t =>
(t -> FilePath)
-> (t -> SourcePos) -> (t -> Maybe a) -> Parsec s u a
token ((FilePath, Int, Int), Token) -> FilePath
forall a a. Show a => (a, a) -> FilePath
showToken ((FilePath, Int, Int), Token) -> SourcePos
forall b. ((FilePath, Int, Int), b) -> SourcePos
posToken ((FilePath, Int, Int), Token) -> Maybe a
forall a. (a, Token) -> Maybe a
testToken
>   where
>     showToken :: (a, a) -> FilePath
showToken (_,tok :: a
tok)   = a -> FilePath
forall a. Show a => a -> FilePath
show a
tok
>     posToken :: ((FilePath, Int, Int), b) -> SourcePos
posToken  ((a :: FilePath
a,b :: Int
b,c :: Int
c),_)  = FilePath -> Int -> Int -> SourcePos
newPos FilePath
a Int
b Int
c
>     testToken :: (a, Token) -> Maybe a
testToken (_,tok :: Token
tok)   = Token -> Maybe a
test Token
tok

> unsignedInteger :: Parser Integer
> unsignedInteger :: ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
unsignedInteger = FilePath -> Integer
forall a. Read a => FilePath -> a
read (FilePath -> Integer)
-> Parser FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> Parser FilePath
sqlNumberTok Bool
True ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
-> FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Integer
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> "natural number"

todo: work out the symbol parsing better

> symbol :: String -> Parser String
> symbol :: FilePath -> Parser FilePath
symbol s :: FilePath
s = Maybe FilePath -> Parser FilePath
symbolTok (FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
s) Parser FilePath -> FilePath -> Parser FilePath
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> FilePath
s

> singleCharSymbol :: Char -> Parser Char
> singleCharSymbol :: Char -> Parser Char
singleCharSymbol c :: Char
c = Char
c Char -> Parser FilePath -> Parser Char
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> Parser FilePath
symbol [Char
c]

> questionMark :: Parser Char
> questionMark :: Parser Char
questionMark = Char -> Parser Char
singleCharSymbol '?' Parser Char -> FilePath -> Parser Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> "question mark"

> openParen :: Parser Char
> openParen :: Parser Char
openParen = Char -> Parser Char
singleCharSymbol '('

> closeParen :: Parser Char
> closeParen :: Parser Char
closeParen = Char -> Parser Char
singleCharSymbol ')'

> openBracket :: Parser Char
> openBracket :: Parser Char
openBracket = Char -> Parser Char
singleCharSymbol '['

> closeBracket :: Parser Char
> closeBracket :: Parser Char
closeBracket = Char -> Parser Char
singleCharSymbol ']'


> comma :: Parser Char
> comma :: Parser Char
comma = Char -> Parser Char
singleCharSymbol ','

> semi :: Parser Char
> semi :: Parser Char
semi = Char -> Parser Char
singleCharSymbol ';'

= helper functions

> keyword :: String -> Parser String
> keyword :: FilePath -> Parser FilePath
keyword k :: FilePath
k = [FilePath] -> Maybe FilePath -> Parser FilePath
unquotedIdentifierTok [] (FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
k) Parser FilePath -> FilePath -> Parser FilePath
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> FilePath
k

helper function to improve error messages

> keywords_ :: [String] -> Parser ()
> keywords_ :: [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keywords_ ks :: [FilePath]
ks = (FilePath
 -> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ())
-> [FilePath]
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ [FilePath]
ks ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
-> FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> FilePath -> [FilePath] -> FilePath
forall a. [a] -> [[a]] -> [a]
intercalate " " [FilePath]
ks


> parens :: Parser a -> Parser a
> parens :: Parser a -> Parser a
parens = Parser Char -> Parser Char -> Parser a -> Parser a
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between Parser Char
openParen Parser Char
closeParen

> brackets :: Parser a -> Parser a
> brackets :: Parser a -> Parser a
brackets = Parser Char -> Parser Char -> Parser a -> Parser a
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between Parser Char
openBracket Parser Char
closeBracket

> commaSep :: Parser a -> Parser [a]
> commaSep :: Parser a -> Parser [a]
commaSep = (Parser a -> Parser Char -> Parser [a]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
`sepBy` Parser Char
comma)

> keyword_ :: String -> Parser ()
> keyword_ :: FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
keyword_ = Parser FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser FilePath
 -> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ())
-> (FilePath -> Parser FilePath)
-> FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Parser FilePath
keyword

> symbol_ :: String -> Parser ()
> symbol_ :: FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
symbol_ = Parser FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser FilePath
 -> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ())
-> (FilePath -> Parser FilePath)
-> FilePath
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Parser FilePath
symbol

> commaSep1 :: Parser a -> Parser [a]
> commaSep1 :: Parser a -> Parser [a]
commaSep1 = (Parser a -> Parser Char -> Parser [a]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
`sepBy1` Parser Char
comma)

> blacklist :: Dialect -> [String]
> blacklist :: Dialect -> [FilePath]
blacklist d :: Dialect
d = Dialect -> [FilePath]
diKeywords Dialect
d

These blacklisted names are mostly needed when we parse something with
an optional alias, e.g. select a a from t. If we write select a from
t, we have to make sure the from isn't parsed as an alias. I'm not
sure what other places strictly need the blacklist, and in theory it
could be tuned differently for each place the identifierString/
identifier parsers are used to only blacklist the bare
minimum. Something like this might be needed for dialect support, even
if it is pretty silly to use a keyword as an unquoted identifier when
there is a quoting syntax as well.

The standard has a weird mix of reserved keywords and unreserved
keywords (I'm not sure what exactly being an unreserved keyword
means).

The current approach tries to have everything which is a keyword only
in the keyword list - so it can only be used in some other context if
quoted. If something is a 'ansi keyword', but appears only as an
identifier or function name for instance in the syntax (or something
that looks identical to this), then it isn't treated as a keyword at
all. When there is some overlap (e.g. 'set'), then there is either
special case parsing code to handle this (in the case of set), or it
is not treated as a keyword (not perfect, but if it more or less
works, ok for now).

An exception to this is the standard type names are considered as
keywords at the moment, with a special case in the type parser to
make this work. Maybe this isn't necessary or is a bad idea.

It is possible to have a problem if you remove something which is a
keyword from this list, and still want to parse statements using it
as a keyword - for instance, removing things like 'from' or 'as',
will likely mean many things don't parse anymore.



-----------

Used to make the dialect available during parsing so different parsers
can be used for different dialects. Not sure if this is the best way
to do it, but it's convenient

> type ParseState = Dialect

> type Token = ((String,Int,Int),L.Token)

> type Parser = GenParser Token ParseState

> guardDialect :: (Dialect -> Bool) -> Parser ()
> guardDialect :: (Dialect -> Bool)
-> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
guardDialect f :: Dialect -> Bool
f = do
>     Dialect
d <- ParsecT [((FilePath, Int, Int), Token)] Dialect Identity Dialect
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
>     Bool -> ParsecT [((FilePath, Int, Int), Token)] Dialect Identity ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Dialect -> Bool
f Dialect
d)

The dialect stuff could also be used for custom options: e.g. to only
parse dml for instance.