on master help sign in
fix parsing of relation{} and relation{}{} and relation{tuple{}} and true/false
commitf2598330cf1b647255e4aa7d2d60a17839dc443c authorAgentM <agentm@themactionfaction.com> dateThu 3 Dec 2015, 17:35 (11 years ago) parentb3f3f02
2 files changed+6−3
TutorialD/Interpreter/RelationalExpr.hs+4−3 test/TutorialD/Interpreter.hs+2
TutorialD/Interpreter/RelationalExpr.hs+4−3
@@ -313,9 +313,10 @@ relationP = do
313313 case mkRelation attrs emptyTupleSet of
314314 Left err -> fail (show err)
315315 Right rel -> return rel
316− else do
317− tuples <- braces (sepBy tupleP comma)
318− case mkRelationFromTuples (tupleAttributes (head tuples)) tuples of
316+ else do -- empty attributes
317+ tuples <- try (braces (sepBy tupleP comma)) <|> pure []
318+ let tupleAttrs = if null tuples then A.emptyAttributes else tupleAttributes (head tuples)
319+ case mkRelationFromTuples tupleAttrs tuples of
319320 Left err -> fail (show err)
320321 Right rel -> return rel
321322
test/TutorialD/Interpreter.hs+2
@@ -44,6 +44,8 @@ main = do
4444 ("x:=relation{tuple{a \"spam\", b 5}}", mkRelation simpleCAttributes $ RelationTupleSet [(RelationTuple simpleCAttributes) (V.fromList [stringAtom "spam", intAtom 5])]),
4545 ("constraint failc true in false; x:=true", Left $ InclusionDependencyCheckError "failc"),
4646 ("x:=y; x:=true", Left $ RelVarNotDefinedError "y"),
47+ ("x:=relation{}", Right relationFalse),
48+ ("x:=relation{tuple{}}", Right relationTrue),
4749 ("x:=true where true", Right relationTrue),
4850 ("x:=true where false", Right relationFalse),
4951 ("x:=true where true or false", Right relationTrue),