1
Fork 0

refactor the join parsing to left factor and remove try

refactor the string token parser to reduce use of try
This commit is contained in:
Jake Wheat 2014-04-17 20:46:16 +03:00
parent 6720d3e3a3
commit 556f65ee22

View file

@ -625,15 +625,20 @@ tref
> from = keyword_ "from" *> commaSep1 tref > from = keyword_ "from" *> commaSep1 tref
> where > where
> tref = nonJoinTref >>= optionSuffix joinTrefSuffix > tref = nonJoinTref >>= optionSuffix joinTrefSuffix
> nonJoinTref = choice [try (TRQueryExpr <$> parens queryExpr) > nonJoinTref = choice
> ,TRParens <$> parens tref > [parens $ choice
> ,TRLateral <$> (try (keyword_ "lateral") > [TRQueryExpr <$> queryExpr
> *> nonJoinTref) > ,TRParens <$> tref]
> ,try (TRFunction <$> name > ,TRLateral <$> (keyword_ "lateral"
> <*> parens (commaSep valueExpr)) > *> nonJoinTref)
> ,try (TRQualified <$> name <*> (char '.' >> name)) > ,do
> ,TRSimple <$> name] > n <- name
> >>= optionSuffix aliasSuffix > choice [TRFunction n
> <$> parens (commaSep valueExpr)
> ,do
> choice [TRQualified n <$> (symbol "." >> name)
> ,return $ TRSimple n]]]
> >>= optionSuffix aliasSuffix
> aliasSuffix j = option j (TRAlias j <$> alias) > aliasSuffix j = option j (TRAlias j <$> alias)
> joinTrefSuffix t = (do > joinTrefSuffix t = (do
> nat <- option False (True <$ keyword_ "natural") > nat <- option False (True <$ keyword_ "natural")
@ -943,7 +948,7 @@ todo: work out the symbol parsing better
> >>= optionSuffix moreString) > >>= optionSuffix moreString)
> <?> "string" > <?> "string"
> where > where
> moreString s0 = try $ choice > moreString s0 = choice
> [-- handle two adjacent quotes > [-- handle two adjacent quotes
> do > do
> void $ char '\'' > void $ char '\''
@ -952,8 +957,7 @@ todo: work out the symbol parsing better
> ,-- handle string in separate parts > ,-- handle string in separate parts
> -- e.g. 'part 1' 'part 2' > -- e.g. 'part 1' 'part 2'
> do > do
> whitespace > try (whitespace <* char '\'')
> void $ char '\''
> s <- manyTill anyChar (char '\'') > s <- manyTill anyChar (char '\'')
> optionSuffix moreString (s0 ++ s) > optionSuffix moreString (s0 ++ s)
> ] > ]