Skip to content

Commit

Permalink
add support for multiple extend expressions in tutd
Browse files Browse the repository at this point in the history
relates to #270
  • Loading branch information
agentm committed Nov 7, 2020
1 parent f7fc888 commit a45300a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/bin/TutorialD/Interpreter/RelationalExpr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ ungroupP = do
extendP :: RelationalMarkerExpr a => Parser (RelationalExprBase a -> RelationalExprBase a)
extendP = do
reservedOp ":"
Extend <$> braces extendTupleExpressionP
extends <- braces (sepBy extendTupleExpressionP comma)
case extends of
[] -> pure (Restrict TruePredicate)
extends' ->
pure $ \expr -> foldl (\acc ext -> Extend ext acc) expr extends'

semijoinP :: RelationalMarkerExpr a => Parser (RelationalExprBase a -> RelationalExprBase a -> RelationalExprBase a)
semijoinP = do
Expand Down
3 changes: 2 additions & 1 deletion test/TutorialD/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ simpleRelTests = TestCase $ do
("x:=relation{tuple{a 5}} : {b:=6}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 6])]),
("x:=relation{tuple{a 5}} : {b:=add(@a,5)}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 10])]),
("x:=relation{tuple{a 5}} : {b:=add(@a,\"spam\")}", Left (AtomFunctionTypeError "add" 2 IntegerAtomType TextAtomType)),
("x:=relation{tuple{a 5}} : {b:=add(add(@a,2),5)}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 12])])
("x:=relation{tuple{a 5}} : {b:=add(add(@a,2),5)}", mkRelationFromTuples simpleDAttributes [RelationTuple simpleDAttributes (V.fromList [IntegerAtom 5, IntegerAtom 12])]),
("x:=false:{a:=1,b:=2}", mkRelationFromTuples simpleDAttributes [])
]
simpleAAttributes = A.attributesFromList [Attribute "a" IntegerAtomType]
simpleBAttributes = A.attributesFromList [Attribute "d" IntegerAtomType]
Expand Down

0 comments on commit a45300a

Please sign in to comment.