-
Notifications
You must be signed in to change notification settings - Fork 35
/
SimpleSQLQueryParser0.lhs
727 lines (596 loc) · 20.1 KB
/
SimpleSQLQueryParser0.lhs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
[[simple-sql-query-parser]]
= Simple SQL query parser
Here is the complete syntax, parser and tests for the value and query
expressions so far as a self contained module
> module SimpleSQLQueryParser0 where
>
> import Text.Parsec.String (Parser)
> import Text.Parsec.String.Parsec (try)
> import Text.Parsec.String.Char
> import Text.Parsec.String.Combinator
> import Text.Parsec (parse,ParseError)
> import Control.Applicative ((<$>),(<*), (*>),(<*>), (<$), (<|>), many)
> import qualified Text.Parsec.String.Expr as E
> import Control.Monad
> --import Data.List (intercalate)
> import Data.Maybe ()
> import qualified Test.HUnit as H
> import FunctionsAndTypesForParsing
> import Debug.Trace
== Supported SQL
=== comments
```sql
-- single line comment
/*
multiline
comment
*/
```
The `/* */` comments do not nest.
=== value expressions
==== literals
postive integral literals and string literals with single quote,
without escaping of single quote within string (so there is no way to
create a string literal with a single quote in it).
```sql
1
500
'string literal'
```
==== identifiers
Unquoted identifiers only, an identifier may start with a letter or
underscore, and contain letters, underscores and digits.
```sql
a
something
_test_
a123
```
==== dotted identifiers
Supports two part dotted identifiers only. Both parts must parse
according to the rules for regular identifiers.
```sql
t.a
something.something_else
```
==== star
Star, plus dotted star using the identifier rules for the first part.
```sql
*
t.*
```
==== function application
The function name must parse as a valid identifier.
```sql
f()
g(1)
h(2,'something')
```
==== operators
Here is the range of operators supported.
```sql
a = b
a > b
a < b
a >= b
a <= b
a != b
a <> b
a and b
a or b
1 + 2
1 - 2
1 * 2
1 / 2
'some' || 'thing'
a like b
not a
```
==== case expression
```sql
case a
when 3 then 'got three'
when 5 then 'got five'
else 'neither'
end
```
```sql
case
when a = 3 then 'a is three'
when b = 4 then 'b is four'
else 'neither'
end
```
The else branch is optional in both cases.
==== parentheses
```sql
(1 + 2) * 3
```
Parentheses are explicit in the abstract syntax.
=== query expressions
TODO: examples
select queries only, no union, intersect or except. No common table
expressions.
select list aliases, with the 'as' optional in the alias
'select * from t'
'select t.* from t'
but not the alias version 'select * as (a,b,c) from t'.
from clause
implicit and explicit joins, including keywords
natural, inner, outer, left, right, full, cross, on and using, plus
parens and simple aliases (e.g. select a from t u, but not select a
from t(a,b)).
where
group by lists
but not the new group by options in SQL2003 (group by (), grouping
sets, cube, rollup).
having
order by, with multiple columns, but not explicit asc or
desc , and no 'nulls first' or 'nulls last' syntax.
No support for offset and fetch first, or variations.
== Abstract syntax
> data ValueExpr = StringLit String
> | NumLit Integer
> | Iden String
> | DIden String String -- a.b
> | Star
> | DStar String -- t.*
> | App String [ValueExpr]
> | PrefOp String ValueExpr
> | BinOp ValueExpr String ValueExpr
> | Case (Maybe ValueExpr) -- test value
> [(ValueExpr,ValueExpr)] -- when branches
> (Maybe ValueExpr) -- else value
> | Parens ValueExpr
> deriving (Eq,Show)
> data QueryExpr
> = Select
> {qeSelectList :: [(ValueExpr,Maybe String)]
> ,qeFrom :: [TableRef]
> ,qeWhere :: Maybe ValueExpr
> ,qeGroupBy :: [ValueExpr]
> ,qeHaving :: Maybe ValueExpr
> ,qeOrderBy :: [ValueExpr]
> } deriving (Eq,Show)
> makeSelect :: QueryExpr
> makeSelect = Select {qeSelectList = []
> ,qeFrom = []
> ,qeWhere = Nothing
> ,qeGroupBy = []
> ,qeHaving = Nothing
> ,qeOrderBy = []}
> data TableRef = TRSimple String
> | TRJoin TableRef JoinType TableRef (Maybe JoinCondition)
> | TRParens TableRef
> | TRAlias TableRef String
> | TRQueryExpr QueryExpr
> deriving (Eq,Show)
> data JoinType = JoinInner | JoinLeft | JoinRight | JoinFull | JoinCross
> deriving (Eq,Show)
> data JoinCondition = JoinOn ValueExpr
> | JoinUsing [String]
> | JoinNatural
> deriving (Eq,Show)
== Value expression parsing
=== term components
> num :: Parser ValueExpr
> num = NumLit <$> integer
> iden :: [String] -> Parser ValueExpr
> iden blacklist = Iden <$> identifierBlacklist blacklist
> parensValue :: Parser ValueExpr
> parensValue = Parens <$> parens (valueExpr [])
> stringLit :: Parser ValueExpr
> stringLit = StringLit <$> stringToken
> dIden :: Parser ValueExpr
> dIden = DIden <$> identifier <*> (dot *> identifier)
> star :: Parser ValueExpr
> star = Star <$ symbol "*"
> dstar :: Parser ValueExpr
> dstar = DStar <$> (identifier <* dot <* symbol "*")
> app :: Parser ValueExpr
> app = App <$> identifier <*> parens (commaSep $ valueExpr [])
=== case
> caseValue :: Parser ValueExpr
> caseValue =
> Case
> <$> (keyword "case" *> optionMaybe caseVal)
> <*> many1 whenClause
> <*> optionMaybe elseClause
> <* keyword "end"
> where
> whenClause = (,) <$> (keyword "when" *> caseVal)
> <*> (keyword "then" *> caseVal)
> elseClause = keyword "else" *> caseVal
> caseVal = valueExpr blackList
> blackList = ["case", "when", "then", "else", "end"]
=== term
> term :: [String] -> Parser ValueExpr
> term blackList = choice [caseValue
> ,try app
> ,try dstar
> ,try dIden
> ,iden blackList
> ,num
> ,parensValue
> ,stringLit
> ,star]
=== operators
> table :: [[E.Operator ValueExpr]]
> table = [[prefix "-", prefix "+"]
> ,[binary "^" E.AssocLeft]
> ,[binary "*" E.AssocLeft
> ,binary "/" E.AssocLeft
> ,binary "%" E.AssocLeft]
> ,[binary "+" E.AssocLeft
> ,binary "-" E.AssocLeft]
> ,[binary "<=" E.AssocRight
> ,binary ">=" E.AssocRight
> ,binaryK "like" E.AssocNone
> ,binary "!=" E.AssocRight
> ,binary "<>" E.AssocRight
> ,binary "||" E.AssocRight]
> ,[binary "<" E.AssocNone
> ,binary ">" E.AssocNone]
> ,[binary "=" E.AssocRight]
> ,[prefixK "not"]
> ,[binaryK "and" E.AssocLeft]
> ,[binaryK "or" E.AssocLeft]]
> where
> binary name assoc =
> E.Infix (mkBinOp name <$ symbol name) assoc
> mkBinOp nm a b = BinOp a nm b
> prefix name = E.Prefix (PrefOp name <$ symbol name)
> binaryK name assoc =
> E.Infix (mkBinOp name <$ keyword name) assoc
> prefixK name = E.Prefix (PrefOp name <$ keyword name)
=== valueExpr
> valueExpr :: [String] -> Parser ValueExpr
> valueExpr blackList = E.buildExpressionParser table (term blackList)
== Query expression parsing
> selectList :: Parser [(ValueExpr, Maybe String)]
> selectList = keyword_ "select" *> commaSep1 selectItem
> selectItem :: Parser (ValueExpr, Maybe String)
> selectItem = (,) <$> valueExpr [] <*> optionMaybe (try alias)
> where alias = optional (keyword_ "as") *> identifierBlacklist ["from"]
> whereClause :: Parser ValueExpr
> whereClause = keyword_ "where" *> valueExpr []
> groupByClause :: Parser [ValueExpr]
> groupByClause = keyword_ "group" *> keyword_ "by"
> *> commaSep1 (valueExpr [])
> having :: Parser ValueExpr
> having = keyword_ "having" *> (valueExpr [])
> orderBy :: Parser [ValueExpr]
> orderBy = keyword_ "order" *> keyword_ "by"
> *> commaSep1 (valueExpr [])
=== from clause
> from :: Parser [TableRef]
> from = keyword_ "from" >> commaSep1 tref
> where
> tref = nonJoinTref >>= suffixWrapper joinTrefSuffix
> joinTrefSuffix t0 = (do
> nat <- option False (True <$ keyword_ "natural")
> TRJoin t0 <$> joinType
> <*> nonJoinTref
> <*> optionMaybe (joinCondition nat))
> >>= suffixWrapper joinTrefSuffix
> nonJoinTref = choice [TRSimple <$> identifier
> ,try (TRQueryExpr <$> parens queryExpr)
> ,TRParens <$> parens tref]
> >>= suffixWrapper (try . alias)
> alias tr = try (TRAlias tr <$> (optional (keyword_ "as") *> aliasIdentifier))
> aliasIdentifier = identifierBlacklist
> [-- join keywords
> "natural"
> ,"inner"
> ,"outer"
> ,"cross"
> ,"left"
> ,"right"
> ,"full"
> ,"join"
> ,"on"
> ,"using"
> -- subsequent clause keywords
> ,"where"
> ,"group"
> ,"having"
> ,"order"
> ]
> joinType :: Parser JoinType
> joinType = choice
> [JoinCross <$ keyword_ "cross" <* keyword_ "join"
> ,JoinInner <$ keyword_ "inner" <* keyword_ "join"
> ,JoinLeft <$ keyword_ "left"
> <* optional (keyword_ "outer")
> <* keyword_ "join"
> ,JoinRight <$ keyword_ "right"
> <* optional (keyword_ "outer")
> <* keyword_ "join"
> ,JoinFull <$ keyword_ "full"
> <* optional (keyword_ "outer")
> <* keyword_ "join"
> ,JoinInner <$ keyword_ "join"]
> joinCondition :: Bool -> Parser JoinCondition
> joinCondition nat =
> choice [guard nat >> return JoinNatural
> ,keyword_ "on" >> JoinOn <$> valueExpr []
> ,keyword_ "using" >> JoinUsing <$> parens (commaSep1 identifier)
> ]
=== queryExpr
> queryExpr :: Parser QueryExpr
> queryExpr = Select
> <$> selectList
> <*> option [] from
> <*> optionMaybe whereClause
> <*> option [] groupByClause
> <*> optionMaybe having
> <*> option [] orderBy
== tokens
> whitespace :: Parser ()
> whitespace =
> choice [simpleWhitespace *> whitespace
> ,lineComment *> whitespace
> ,blockComment *> whitespace
> ,return ()]
> where
> lineComment = try (string "--")
> *> manyTill anyChar (void (char '\n') <|> eof)
> blockComment = try (string "/*")
> *> manyTill anyChar (try $ string "*/")
> simpleWhitespace = void $ many1 (oneOf " \t\n")
> lexeme :: Parser a -> Parser a
> lexeme p = p <* whitespace
> integer :: Parser Integer
> integer = read <$> lexeme (many1 digit)
> identifier :: Parser String
> identifier = lexeme ((:) <$> firstChar <*> many nonFirstChar)
> where
> firstChar = letter <|> char '_'
> nonFirstChar = digit <|> firstChar
> symbol :: String -> Parser String
> symbol s = try $ lexeme $ do
> u <- many1 (oneOf "<>=+-^%/*!|")
> guard (s == u)
> return s
> openParen :: Parser Char
> openParen = lexeme $ char '('
> closeParen :: Parser Char
> closeParen = lexeme $ char ')'
> stringToken :: Parser String
> stringToken = lexeme (char '\'' *> manyTill anyChar (char '\''))
> dot :: Parser Char
> dot = lexeme $ char '.'
> comma :: Parser Char
> comma = lexeme $ char ','
== helper functions
> keyword :: String -> Parser String
> keyword k = try $ do
> i <- identifier
> guard (i == k)
> return k
> parens :: Parser a -> Parser a
> parens = between openParen closeParen
> commaSep :: Parser a -> Parser [a]
> commaSep = (`sepBy` comma)
> keyword_ :: String -> Parser ()
> keyword_ = void . keyword
> symbol_ :: String -> Parser ()
> symbol_ = void . symbol
> commaSep1 :: Parser a -> Parser [a]
> commaSep1 = (`sepBy1` comma)
> identifierBlacklist :: [String] -> Parser String
> identifierBlacklist bl = do
> i <- identifier
> guard (i `notElem` bl)
> return i
> suffixWrapper :: (a -> Parser a) -> a -> Parser a
> suffixWrapper p a = p a <|> return a
== the parser api
> parseQueryExpr :: String -> Either ParseError QueryExpr
> parseQueryExpr = parse (whitespace *> queryExpr <* eof) ""
> parseValueExpr :: String -> Either ParseError ValueExpr
> parseValueExpr = parse (whitespace *> valueExpr [] <* eof) ""
== tests
> data TestItem = Group String [TestItem]
> | ValueExpressionTest String ValueExpr
> | QueryExpressionTest String QueryExpr
> numLitTests :: [(String,ValueExpr)]
> numLitTests =
> [("1", NumLit 1)
> ,("54321", NumLit 54321)]
>
> idenTests :: [(String,ValueExpr)]
> idenTests =
> [("test", Iden "test")
> ,("_something3", Iden "_something3")]
>
> operatorTests :: [(String,ValueExpr)]
> operatorTests =
> map (\o -> (o ++ " a", PrefOp o (Iden "a"))) ["not", "+", "-"]
> ++ map (\o -> ("a " ++ o ++ " b", BinOp (Iden "a") o (Iden "b")))
> ["=",">","<", ">=", "<=", "!=", "<>"
> ,"and", "or", "+", "-", "*", "/", "||", "like"]
>
> parensTests :: [(String,ValueExpr)]
> parensTests = [("(1)", Parens (NumLit 1))]
> basicTests :: [(String,ValueExpr)]
> basicTests = numLitTests ++ idenTests ++ operatorTests ++ parensTests
> stringLiteralTests :: [(String,ValueExpr)]
> stringLiteralTests =
> [("''", StringLit "")
> ,("'test'", StringLit "test")]
> dIdenTests :: [(String,ValueExpr)]
> dIdenTests =
> [("t.a", DIden "t" "a")]
> starTests :: [(String,ValueExpr)]
> starTests = [("*", Star)]
> dStarTests :: [(String,ValueExpr)]
> dStarTests = [("t.*", DStar "t")]
> appTests :: [(String,ValueExpr)]
> appTests = [("f()", App "f" [])
> ,("f(1)", App "f" [NumLit 1])
> ,("f(1,a)", App "f" [NumLit 1, Iden "a"])]
> caseTests :: [(String,ValueExpr)]
> caseTests =
> [("case a when 1 then 2 end"
> ,Case (Just $ Iden "a") [(NumLit 1,NumLit 2)] Nothing)
>
> ,("case a when 1 then 2 when 3 then 4 end"
> ,Case (Just $ Iden "a")
> [(NumLit 1, NumLit 2)
> ,(NumLit 3, NumLit 4)]
> Nothing)
>
> ,("case a when 1 then 2 when 3 then 4 else 5 end"
> ,Case (Just $ Iden "a")
> [(NumLit 1, NumLit 2)
> ,(NumLit 3, NumLit 4)]
> (Just $ NumLit 5))
>
> ,("case when a=1 then 2 when a=3 then 4 else 5 end"
> ,Case Nothing
> [(BinOp (Iden "a") "=" (NumLit 1), NumLit 2)
> ,(BinOp (Iden "a") "=" (NumLit 3), NumLit 4)]
> (Just $ NumLit 5))
> ]
> allValueExprTests :: [(String,ValueExpr)]
> allValueExprTests = concat [basicTests
> ,stringLiteralTests
> ,dIdenTests
> ,starTests
> ,dStarTests
> ,appTests
> ,caseTests]
> singleSelectItemTests :: [(String,QueryExpr)]
> singleSelectItemTests =
> [("select 1", makeSelect {qeSelectList = [(NumLit 1,Nothing)]})]
> multipleSelectItemsTests :: [(String,QueryExpr)]
> multipleSelectItemsTests =
> [("select a"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)]})
> ,("select a,b"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
> ,(Iden "b",Nothing)]})
> ,("select 1+2,3+4"
> ,makeSelect {qeSelectList =
> [(BinOp (NumLit 1) "+" (NumLit 2),Nothing)
> ,(BinOp (NumLit 3) "+" (NumLit 4),Nothing)]})
> ]
> selectListTests :: [(String,QueryExpr)]
> selectListTests =
> [("select a as a, b as b"
> ,makeSelect {qeSelectList = [(Iden "a", Just "a")
> ,(Iden "b", Just "b")]})
> ,("select a a, b b"
> ,makeSelect {qeSelectList = [(Iden "a", Just "a")
> ,(Iden "b", Just "b")]})
> ] ++ multipleSelectItemsTests
> ++ singleSelectItemTests
> fromTests :: [(String,QueryExpr)]
> fromTests =
> [("select a from t"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]})]
> whereTests :: [(String,QueryExpr)]
> whereTests =
> [("select a from t where a = 5"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeWhere = Just $ BinOp (Iden "a") "=" (NumLit 5)})
> ]
> groupByTests :: [(String,QueryExpr)]
> groupByTests =
> [("select a,sum(b) from t group by a"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
> ,(App "sum" [Iden "b"],Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeGroupBy = [Iden "a"]
> })
> ,("select a,b,sum(c) from t group by a,b"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
> ,(Iden "b",Nothing)
> ,(App "sum" [Iden "c"],Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeGroupBy = [Iden "a",Iden "b"]
> })
> ]
> havingTests :: [(String,QueryExpr)]
> havingTests =
> [("select a,sum(b) from t group by a having sum(b) > 5"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
> ,(App "sum" [Iden "b"],Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeGroupBy = [Iden "a"]
> ,qeHaving = Just $ BinOp (App "sum" [Iden "b"]) ">" (NumLit 5)
> })
> ]
> orderByTests :: [(String,QueryExpr)]
> orderByTests =
> [("select a from t order by a"
> ,ms [Iden "a"])
> ,("select a from t order by a, b"
> ,ms [Iden "a", Iden "b"])
> ]
> where
> ms o = makeSelect {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeOrderBy = o}
> queryExprJoinTests :: [(String,QueryExpr)]
> queryExprJoinTests =
> [("select a from t"
> ,ms [TRSimple "t"])
> ,("select a from t,u"
> ,ms [TRSimple "t", TRSimple "u"])
>
> ,("select a from t inner join u on expr"
> ,ms [TRJoin (TRSimple "t") JoinInner (TRSimple "u")
> (Just $ JoinOn $ Iden "expr")])
>
> ,("select a from t left join u on expr"
> ,ms [TRJoin (TRSimple "t") JoinLeft (TRSimple "u")
> (Just $ JoinOn $ Iden "expr")])
>
> ,("select a from t right join u on expr"
> ,ms [TRJoin (TRSimple "t") JoinRight (TRSimple "u")
> (Just $ JoinOn $ Iden "expr")])
>
> ,("select a from t full join u on expr"
> ,ms [TRJoin (TRSimple "t") JoinFull (TRSimple "u")
> (Just $ JoinOn $ Iden "expr")])
>
> ,("select a from t cross join u"
> ,ms [TRJoin (TRSimple "t") JoinCross (TRSimple "u") Nothing])
>
> ,("select a from t natural inner join u"
> ,ms [TRJoin (TRSimple "t") JoinInner (TRSimple "u")
> (Just JoinNatural)])
>
> ,("select a from t inner join u using(a,b)"
> ,ms [TRJoin (TRSimple "t") JoinInner (TRSimple "u")
> (Just $ JoinUsing ["a", "b"])])
>
> ,("select a from (select a from t)"
> ,ms [TRQueryExpr $ ms [TRSimple "t"]])
>
> ,("select a from t as u"
> ,ms [TRAlias (TRSimple "t") "u"])
>
> ,("select a from t u"
> ,ms [TRAlias (TRSimple "t") "u"])
>
> ,("select a from (t cross join u) as u"
> ,ms [TRAlias (TRParens $ TRJoin (TRSimple "t") JoinCross
> (TRSimple "u") Nothing) "u"])
> ]
> where
> ms f = makeSelect {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = f}
> allQueryExprTests :: [(String,QueryExpr)]
> allQueryExprTests = concat [selectListTests ++ fromTests ++ whereTests ++ groupByTests ++ havingTests ++ orderByTests ++ queryExprJoinTests]
todo: use external api parsing code
> makeTest :: (Eq a, Show a) => Parser a -> (String,a) -> H.Test
> makeTest parser (src,expected) = H.TestLabel src $ H.TestCase $ do
> let gote = parse (whitespace *> parser <* eof) "" src
> case gote of
> Left e -> H.assertFailure $ show e
> Right got -> H.assertEqual src expected got