on master help sign in
add support for multiple extend expressions in tutd

relates to #270

commita45300a7145884ef330e28aad2352a889bbda1dd authorAgentM <agentm@themactionfaction.com> dateFri 6 Nov 2020, 23:12 (6 years ago) parentf7fc888
2 files changed+7−2
src/bin/TutorialD/Interpreter/RelationalExpr.hs+5−1 test/TutorialD/Interpreter.hs+2−1
src/bin/TutorialD/Interpreter/RelationalExpr.hs+5−1
@@ -102,7 +102,11 @@ ungroupP = do
102102extendP :: RelationalMarkerExpr a => Parser (RelationalExprBase a -> RelationalExprBase a)
103103extendP = do
104104 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'
106110
107111semijoinP :: RelationalMarkerExpr a => Parser (RelationalExprBase a -> RelationalExprBase a -> RelationalExprBase a)
108112semijoinP = do
test/TutorialD/Interpreter.hs+2−1
@@ -121,7 +121,8 @@ simpleRelTests = TestCase $ do
121121 ("x:=relation{tuple{a 5}} : {b:=6}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 6])]),
122122 ("x:=relation{tuple{a 5}} : {b:=add(@a,5)}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 10])]),
123123 ("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 [])
125126 ]
126127 simpleAAttributes = A.attributesFromList [Attribute "a" IntegerAtomType]
127128 simpleBAttributes = A.attributesFromList [Attribute "d" IntegerAtomType]