From c56a1c8fc83d249d7753cb4b683f17f6aaa3b8fc Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Mon, 22 Feb 2016 23:25:00 +0200 Subject: [PATCH] use explicit data type for sign in interval literals --- Language/SQL/SimpleSQL/Parse.lhs | 4 ++-- Language/SQL/SimpleSQL/Pretty.lhs | 4 +++- Language/SQL/SimpleSQL/Syntax.lhs | 6 +++++- tools/Language/SQL/SimpleSQL/SQL2011Queries.lhs | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Language/SQL/SimpleSQL/Parse.lhs b/Language/SQL/SimpleSQL/Parse.lhs index 87461c3..21f620f 100644 --- a/Language/SQL/SimpleSQL/Parse.lhs +++ b/Language/SQL/SimpleSQL/Parse.lhs @@ -686,8 +686,8 @@ this. also fix the monad -> applicative > intervalLit :: Parser ScalarExpr > intervalLit = try (keyword_ "interval" >> do -> s <- optionMaybe $ choice [True <$ symbol_ "+" -> ,False <$ symbol_ "-"] +> s <- optionMaybe $ choice [Plus <$ symbol_ "+" +> ,Minus <$ symbol_ "-"] > lit <- singleQuotesOnlyStringTok > q <- optionMaybe intervalQualifier > mkIt s lit q) diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index c72466f..0673f29 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -45,7 +45,9 @@ which have been changed to try to improve the layout of the output. > scalarExpr _ (NumLit s) = text s > scalarExpr _ (IntervalLit s v f t) = > text "interval" -> <+> me (\x -> if x then text "+" else text "-") s +> <+> me (\x -> text $ case x of +> Plus -> "+" +> Minus -> "-") s > <+> quotes (text v) > <+> intervalTypeField f > <+> me (\x -> text "to" <+> intervalTypeField x) t diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index ce4bc37..b92cf38 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -7,6 +7,7 @@ > ,Name(..) > ,TypeName(..) > ,IntervalTypeField(..) +> ,Sign(..) > ,PrecMultiplier(..) > ,PrecUnits(..) > ,SetQuantifier(..) @@ -95,7 +96,7 @@ > -- | text of interval literal, units of interval precision, > -- e.g. interval 3 days (3) > | IntervalLit -> {ilSign :: Maybe Bool -- ^ true if + used, false if - used +> {ilSign :: Maybe Sign -- ^ if + or - used > ,ilLiteral :: String -- ^ literal text > ,ilFrom :: IntervalTypeField > ,ilTo :: Maybe IntervalTypeField @@ -250,6 +251,9 @@ in other places > data IntervalTypeField = Itf String (Maybe (Integer, Maybe Integer)) > deriving (Eq,Show,Read,Data,Typeable) +> data Sign = Plus | Minus +> deriving (Eq,Show,Read,Data,Typeable) + > data PrecMultiplier = PrecK | PrecM | PrecG | PrecT | PrecP > deriving (Eq,Show,Read,Data,Typeable) > data PrecUnits = PrecCharacters diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Queries.lhs b/tools/Language/SQL/SimpleSQL/SQL2011Queries.lhs index e13c356..ca57523 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011Queries.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011Queries.lhs @@ -711,9 +711,9 @@ TODO: unicode escape > ,("interval '1' day(3)" > ,IntervalLit Nothing "1" (Itf "day" $ Just (3,Nothing)) Nothing) > ,("interval + '1' day(3)" -> ,IntervalLit (Just True) "1" (Itf "day" $ Just (3,Nothing)) Nothing) +> ,IntervalLit (Just Plus) "1" (Itf "day" $ Just (3,Nothing)) Nothing) > ,("interval - '1' second(2,2)" -> ,IntervalLit (Just False) "1" (Itf "second" $ Just (2,Just 2)) Nothing) +> ,IntervalLit (Just Minus) "1" (Itf "second" $ Just (2,Just 2)) Nothing) > ,("interval '1' year to month" > ,IntervalLit Nothing "1" (Itf "year" Nothing) > (Just $ Itf "month" Nothing))