1
Fork 0

refactor postgresql operator parsing

This commit is contained in:
Jake Wheat 2016-02-13 20:34:50 +02:00
parent c24008444c
commit fc2119be02

View file

@ -366,49 +366,43 @@ which allows the last character of a multi character symbol to be + or
> -- these are the symbols when if part of a multi character > -- these are the symbols when if part of a multi character
> -- operator permit the operator to end with a + or - symbol > -- operator permit the operator to end with a + or - symbol
> exceptionOpSymbols = "~!@#%^&|`?" > exceptionOpSymbols = "~!@#%^&|`?"
>
> -- special case for parsing a single + or - symbol > -- special case for parsing a single + or - symbol
> singlePlusMinus = try $ do > singlePlusMinus = try $ do
> c <- choice $ map char "+-" > c <- oneOf "+-"
> -- todo: deal with e.g. --- +-- +/* ? > -- todo: make sure it deals with e.g. --- +-- +/* -/*?
> notFollowedBy $ choice $ map char allOpSymbols > notFollowedBy $ oneOf allOpSymbols
> return [c] > return [c]
> -- this is used when we are parsing a potentially multi symbol > -- this is used when we are parsing a potentially multi symbol
> -- operator and we have alread seen one of the 'exception chars' > -- operator and we have alread seen one of the 'exception chars'
> -- and so we can end with a + or - > -- and so we can end with a + or -
> moreOpCharsException = do > moreOpCharsException = do
> c <- choice (map char allOpSymbolsNoCommentStarters > c <- oneOf allOpSymbolsNoCommentStarters
> -- make sure we don't parse a comment starting token > -- make sure we don't parse a comment starting token
> -- as part of an operator > -- as part of an operator
> ++ [try (char '/' <* notFollowedBy (char '*')) > <|> try (char '/' <* notFollowedBy (char '*'))
> ,try (char '-' <* notFollowedBy (char '-'))]) > <|> try (char '-' <* notFollowedBy (char '-'))
> (c:) <$> option [] moreOpCharsException > (c:) <$> option [] moreOpCharsException
> opMoreChars = choice > opMoreChars = choice
> [do > [-- parse an exception char, now we can finish with a + -
> -- parse an exception char, now we can finish with a + - > (:)
> c <- choice $ map char exceptionOpSymbols > <$> oneOf exceptionOpSymbols
> (c:) <$> option [] moreOpCharsException > <*> option [] moreOpCharsException
> ,do > ,(:)
> -- parse + or -, make sure it isn't the last symbol > <$> (-- parse +, make sure it isn't the last symbol
> c <- try (char '+' > try (char '+' <* lookAhead (oneOf allOpSymbols))
> -- make sure there is another symbol > <|> -- parse -, make sure it isn't the last symbol
> <* lookAhead (choice $ map char allOpSymbols)) > -- or the start of a -- comment
> (c:) <$> option [] opMoreChars > try (char '-'
> ,do
> c <- try (char '-'
> -- check for comment
> <* notFollowedBy (char '-') > <* notFollowedBy (char '-')
> -- make sure there is another symbol > <* lookAhead (oneOf allOpSymbols))
> <* lookAhead (choice $ map char allOpSymbols)) > <|> -- parse / check it isn't the start of a /* comment
> (c:) <$> option [] opMoreChars > try (char '/' <* notFollowedBy (char '*'))
> ,do > <|> -- any other ansi operator symbol
> -- parse one of the other ansi operator symbols > oneOf "*<>=")
> c <- choice (-- check / isn't start of comment /* > <*> option [] opMoreChars
> try (char '/' <* notFollowedBy (char '*'))
> : map char "*<>=")
> (c:) <$> option [] opMoreChars
> ] > ]