@@ -13,24 +13,34 @@ parseColumn :: Parser Column
1313parseColumn = do
1414 cName <- parseWordAndComma
1515 sqlType <- lexeme parseSqlType
16- c <- many $ choice $ try <$> [
17- parsePrimaryKeyForCol
16+ c <-
17+ many $
18+ choice $
19+ try
20+ <$> [ parsePrimaryKeyForCol
21+ , parseNotNullForCol
22+ , parseUniqueForCol
23+ , parseDefaultVForCol
24+ , parseReferenceForCol
25+ , parseNullForCol
26+ , parseCheckForCol
27+ ]
28+ t <-
29+ many
30+ ( lexeme (string " constraint" )
31+ *> parseWordAndComma
32+ *> choice
33+ ( try
34+ <$> [ parsePrimaryKeyForCol
1835 , parseNotNullForCol
1936 , parseUniqueForCol
2037 , parseDefaultVForCol
2138 , parseReferenceForCol
22- , parseNullForCol
39+ , parseNullForCol
2340 , parseCheckForCol
2441 ]
25- t <- many (lexeme (string " constraint" ) *> parseWordAndComma *> choice (try <$> [
26- parsePrimaryKeyForCol
27- , parseNotNullForCol
28- , parseUniqueForCol
29- , parseDefaultVForCol
30- , parseReferenceForCol
31- , parseNullForCol
32- , parseCheckForCol
33- ]))
42+ )
43+ )
3444 void $ optional ignoreConstraints
3545 return
3646 Column
@@ -57,27 +67,26 @@ skipOptionalParts =
5767
5868skipLikeClause :: Parser ()
5969skipLikeClause = do
60- _ <- string " like"
61- _ <- parseWord
62- _ <- optional (between (char ' (' ) (char ' )' ) (skipManyTill anySingle (lookAhead (char ' )' ))))
70+ _ <- lexeme $ string " like"
71+ _ <- takeWhile1P Nothing (/= ' ;' )
6372 return ()
6473
6574skipPartitioning :: Parser ()
6675skipPartitioning = do
6776 _ <- lexeme (string " partition" ) *> lexeme (string " by" )
68- _ <- takeWhileP Nothing (/= ' ) ' )
77+ _ <- takeWhile1P Nothing (/= ' ; ' )
6978 return ()
7079
7180skipInheritsClause :: Parser ()
7281skipInheritsClause = do
73- _ <- string " inherits"
74- _ <- between (char ' ( ' ) (char ' ) ' ) (parseWord `sepBy1` lexeme (char ' , ' ) )
82+ _ <- lexeme $ string " inherits"
83+ _ <- takeWhile1P Nothing ( /= ' ; ' )
7584 return ()
7685
7786skipUsingMethod :: Parser ()
7887skipUsingMethod = do
79- _ <- string " using"
80- _ <- parseWord
88+ _ <- lexeme $ string " using"
89+ _ <- takeWhile1P Nothing ( /= ' ; ' )
8190 return ()
8291
8392skipWithOrWithoutOids :: Parser ()
@@ -96,12 +105,14 @@ skipOnCommit = do
96105
97106skipTablespace :: Parser ()
98107skipTablespace = do
99- _ <- string " tablespace"
100- _ <- parseWord
108+ _ <- lexeme $ string " tablespace"
109+ _ <- takeWhile1P Nothing ( /= ' ; ' )
101110 return ()
102111
103112parseColumnOrConstraint :: Parser (Either Column TableConstraint )
104- parseColumnOrConstraint = (Right <$> lexeme parseTableConstraint) <|> (Left <$> lexeme parseColumn)
113+ parseColumnOrConstraint =
114+ (Right <$> lexeme parseTableConstraint)
115+ <|> (Left <$> lexeme parseColumn)
105116
106117parseCreateTable :: Parser Table
107118parseCreateTable = do
@@ -113,8 +124,11 @@ parseCreateTable = do
113124 _ <- optional $ lexeme (string " if" ) *> lexeme (string " not" ) *> lexeme (string " exists" )
114125 tName <- lexeme (takeWhile1P Nothing (`notElem` (" \t\n )(" :: String )))
115126 items <-
116- between (lexeme (char ' (' )) (lexeme (char ' )' )) (parseColumnOrConstraint `sepBy` lexeme (char ' ,' ))
117- _ <- optional skipOptionalParts
127+ between
128+ (lexeme (char ' (' ))
129+ (lexeme (char ' )' ))
130+ (parseColumnOrConstraint `sepBy` lexeme (char ' ,' ))
131+ _ <- optional $ lexeme skipOptionalParts
118132 let cols = [c | Left c <- items]
119133 let constraints = [con | Right con <- items]
120134 return Table {tableName = tName, columns = cols, tableConstraints = constraints}
0 commit comments