From d20245880801f853d0b10957989ec3cb3591c46a Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Thu, 17 Apr 2014 20:53:16 +0300 Subject: [PATCH] refactor the interval literal parser to not use try --- Language/SQL/SimpleSQL/Parser.lhs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs index 50348a0..7a5fb35 100644 --- a/Language/SQL/SimpleSQL/Parser.lhs +++ b/Language/SQL/SimpleSQL/Parser.lhs @@ -114,11 +114,14 @@ interval '3 days' which parses as a typed literal > interval :: Parser ValueExpr -> interval = try (keyword_ "interval" >> -> IntervalLit -> <$> stringToken -> <*> identifierBlacklist blacklist -> <*> optionMaybe (parens integer)) +> interval = keyword_ "interval" >> +> mkIt <$> stringToken +> <*> optionMaybe +> ((,) <$> identifierBlacklist blacklist +> <*> optionMaybe (parens integer)) +> where +> mkIt val Nothing = TypedLit (TypeName "interval") val +> mkIt val (Just (a,b)) = IntervalLit val a b > literal :: Parser ValueExpr > literal = number <|> stringValue <|> interval