on master help sign in
add support to tutd for Maybe Int and Maybe Text types
6dae00eAgentM
TutorialD/Interpreter/RelationalExpr.hs+22−1
@@ -226,7 +226,15 @@ nakedAtomExprP :: Parser AtomExpr
226nakedAtomExprP = NakedAtomExpr <$> atomP
226nakedAtomExprP = NakedAtomExpr <$> atomP
227
227
228atomP :: Parser Atom
228atomP :: Parser Atom
229−atomP = dateTimeAtomP <|> dateAtomP <|> stringAtomP <|> doubleAtomP <|> intAtomP <|> boolAtomP <|> relationAtomP
229+atomP = dateTimeAtomP <|>
230+ dateAtomP <|>
231+ maybeTextAtomP <|>
232+ maybeIntAtomP <|>
233+ stringAtomP <|>
234+ doubleAtomP <|>
235+ intAtomP <|>
236+ boolAtomP <|>
237+ relationAtomP
230
238
231functionAtomExprP :: Parser AtomExpr
239functionAtomExprP :: Parser AtomExpr
232functionAtomExprP = do
240functionAtomExprP = do
@@ -240,6 +248,19 @@ relationalAtomExprP = RelationAtomExpr <$> relExprP
240stringAtomP :: Parser Atom
248stringAtomP :: Parser Atom
241stringAtomP = liftA (Atom . T.pack) quotedString
249stringAtomP = liftA (Atom . T.pack) quotedString
242
250
251+--until polymorphic type constructors and algebraic data types are properly supported, such constructs must be unfortunately hard-coded
252+maybeTextAtomP :: Parser Atom
253+maybeTextAtomP = do
254+ maybeText <- try $ ((Just . T.pack <$> (reserved "Just" *> quotedString)) <|>
255+ (reserved "nothing" *> return Nothing)) <* reserved "::maybe char"
256+ return $ Atom maybeText
257+
258+maybeIntAtomP :: Parser Atom
259+maybeIntAtomP = do
260+ maybeInt <- try $ ((Just . fromIntegral <$> (reserved "Just" *> integer)) <|>
261+ (reserved "nothing" *> return Nothing)) <* reserved "::maybe int"
262+ return $ Atom (maybeInt :: Maybe Int)
263+
243dateTimeAtomP :: Parser Atom
264dateTimeAtomP :: Parser Atom
244dateTimeAtomP = do
265dateTimeAtomP = do
245 dateTimeString' <- try $ do
266 dateTimeString' <- try $ do
test/TutorialD/Interpreter.hs+9−1
@@ -18,6 +18,8 @@ import System.Exit
18import Data.Maybe (isJust)
18import Data.Maybe (isJust)
19import System.IO
19import System.IO
20import qualified Data.Vector as V
20import qualified Data.Vector as V
21+import Data.Typeable (Proxy(..))
22+import Data.Text (Text)
21
23
22--urgent: add group and ungroup tests- I missed the group relation type bug
24--urgent: add group and ungroup tests- I missed the group relation type bug
23main :: IO ()
25main :: IO ()
@@ -59,6 +61,8 @@ main = do
59 simpleBAttributes = A.attributesFromList [Attribute "d" intAtomType]
61 simpleBAttributes = A.attributesFromList [Attribute "d" intAtomType]
60 simpleCAttributes = A.attributesFromList [Attribute "a" stringAtomType, Attribute "b" intAtomType]
62 simpleCAttributes = A.attributesFromList [Attribute "a" stringAtomType, Attribute "b" intAtomType]
61 simpleDAttributes = A.attributesFromList [Attribute "a" intAtomType, Attribute "b" intAtomType]
63 simpleDAttributes = A.attributesFromList [Attribute "a" intAtomType, Attribute "b" intAtomType]
64+ simpleMaybeTextAttributes = A.attributesFromList [Attribute "a" $ atomTypeForProxy (Proxy :: Proxy (Maybe Text))]
65+ simpleMaybeIntAttributes = A.attributesFromList [Attribute "a" $ atomTypeForProxy (Proxy :: Proxy (Maybe Int))]
62 simpleProjectionAttributes = A.attributesFromList [Attribute "c" intAtomType]
66 simpleProjectionAttributes = A.attributesFromList [Attribute "c" intAtomType]
63 nestedRelationAttributes = A.attributesFromList [Attribute "a" intAtomType, Attribute "b" (RelationAtomType $ A.attributesFromList [Attribute "a" intAtomType])]
67 nestedRelationAttributes = A.attributesFromList [Attribute "a" intAtomType, Attribute "b" (RelationAtomType $ A.attributesFromList [Attribute "a" intAtomType])]
64 extendTestAttributes = A.attributesFromList [Attribute "a" intAtomType, Attribute "b" $ RelationAtomType (attributes suppliersRel)]
68 extendTestAttributes = A.attributesFromList [Attribute "a" intAtomType, Attribute "b" $ RelationAtomType (attributes suppliersRel)]
@@ -89,7 +93,11 @@ main = do
89 ("x:=S{all but S#} = S{CITY,SNAME,STATUS}", Right $ relationTrue),
93 ("x:=S{all but S#} = S{CITY,SNAME,STATUS}", Right $ relationTrue),
90 --test key syntax
94 --test key syntax
91 ("x:=S; key testconstraint {S#,CITY} x; insert x relation{tuple{CITY \"London\", S# \"S1\", SNAME \"gonk\", STATUS 50}}", Left (InclusionDependencyCheckError "testconstraint")),
95 ("x:=S; key testconstraint {S#,CITY} x; insert x relation{tuple{CITY \"London\", S# \"S1\", SNAME \"gonk\", STATUS 50}}", Left (InclusionDependencyCheckError "testconstraint")),
92− ("y:=S; key testconstraint {S#} y; insert y relation{tuple{CITY \"London\", S# \"S6\", SNAME \"gonk\", STATUS 50}}; x:=y{S#} = S{S#} union relation{tuple{S# \"S6\"}}", Right $ relationTrue)
96+ ("y:=S; key testconstraint {S#} y; insert y relation{tuple{CITY \"London\", S# \"S6\", SNAME \"gonk\", STATUS 50}}; x:=y{S#} = S{S#} union relation{tuple{S# \"S6\"}}", Right $ relationTrue),
97+ --test Maybe Text
98+ ("x:=relation{tuple{a Just \"spam\"::maybe char}}", mkRelationFromList simpleMaybeTextAttributes [[Atom (Just "spam" :: Maybe Text)]]),
99+ --test Maybe Int
100+ ("x:=relation{tuple{a Just 3::maybe int}}", mkRelationFromList simpleMaybeIntAttributes [[Atom (Just 3 :: Maybe Int)]])
93 ]
101 ]
94
102
95
103