on master help sign in
add support for multiple extend expressions in tutd
a45300aAgentM
src/bin/TutorialD/Interpreter/RelationalExpr.hs+5−1
@@ -102,7 +102,11 @@ ungroupP = do
102extendP :: RelationalMarkerExpr a => Parser (RelationalExprBase a -> RelationalExprBase a)
102extendP :: RelationalMarkerExpr a => Parser (RelationalExprBase a -> RelationalExprBase a)
103extendP = do
103extendP = do
104 reservedOp ":"
104 reservedOp ":"
105− Extend <$> braces extendTupleExpressionP
105+ extends <- braces (sepBy extendTupleExpressionP comma)
106+ case extends of
107+ [] -> pure (Restrict TruePredicate)
108+ extends' ->
109+ pure $ \expr -> foldl (\acc ext -> Extend ext acc) expr extends'
106
110
107semijoinP :: RelationalMarkerExpr a => Parser (RelationalExprBase a -> RelationalExprBase a -> RelationalExprBase a)
111semijoinP :: RelationalMarkerExpr a => Parser (RelationalExprBase a -> RelationalExprBase a -> RelationalExprBase a)
108semijoinP = do
112semijoinP = do
test/TutorialD/Interpreter.hs+2−1
@@ -121,7 +121,8 @@ simpleRelTests = TestCase $ do
121 ("x:=relation{tuple{a 5}} : {b:=6}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 6])]),
121 ("x:=relation{tuple{a 5}} : {b:=6}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 6])]),
122 ("x:=relation{tuple{a 5}} : {b:=add(@a,5)}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 10])]),
122 ("x:=relation{tuple{a 5}} : {b:=add(@a,5)}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 10])]),
123 ("x:=relation{tuple{a 5}} : {b:=add(@a,\"spam\")}", Left (AtomFunctionTypeError "add" 2 IntegerAtomType TextAtomType)),
123 ("x:=relation{tuple{a 5}} : {b:=add(@a,\"spam\")}", Left (AtomFunctionTypeError "add" 2 IntegerAtomType TextAtomType)),
124− ("x:=relation{tuple{a 5}} : {b:=add(add(@a,2),5)}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 12])])
124+ ("x:=relation{tuple{a 5}} : {b:=add(add(@a,2),5)}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 12])]),
125+ ("x:=false:{a:=1,b:=2}", mkRelationFromTuples simpleDAttributes [])
125 ]
126 ]
126 simpleAAttributes = A.attributesFromList [Attribute "a" IntegerAtomType]
127 simpleAAttributes = A.attributesFromList [Attribute "a" IntegerAtomType]
127 simpleBAttributes = A.attributesFromList [Attribute "d" IntegerAtomType]
128 simpleBAttributes = A.attributesFromList [Attribute "d" IntegerAtomType]