1
Fork 0

use explicit data type for sign in interval literals

This commit is contained in:
Jake Wheat 2016-02-22 23:25:00 +02:00
parent d52b5efc8b
commit c56a1c8fc8
4 changed files with 12 additions and 6 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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))