on master help sign in
detect and reject duplicate attribute names in tutd input
commit13209bc4c72f02c6bf4dac71e5cde8c37284705f authorAgentM <agentm@themactionfaction.com> dateSun 3 Apr 2016, 12:15 (11 years ago) parent28492b3
1 file changed+9−2
TutorialD/Interpreter/RelationalExpr.hs+9−2
TutorialD/Interpreter/RelationalExpr.hs+9−2
@@ -8,8 +8,10 @@ import TutorialD.Interpreter.Types
88import qualified Data.Text as T
99import qualified Data.Set as S
1010import qualified Data.Map as M
11+import Data.List (sort)
1112import Data.Functor.Identity (Identity)
1213import Control.Applicative (liftA)
14+import ProjectM36.MiscUtils
1315
1416--used in projection
1517attributeListP :: Parser AttributeNames
@@ -23,7 +25,7 @@ makeRelationP :: Parser RelationalExpr
2325makeRelationP = do
2426 reserved "relation"
2527 attrExprs <- try (liftA Just makeAttributeExprsP) <|> pure Nothing
26− tupleExprs <- try (braces (sepBy tupleExprP comma)) <|> pure []
28+ tupleExprs <- braces (sepBy tupleExprP comma) <|> pure []
2729 pure $ MakeRelationFromExprs attrExprs tupleExprs
2830
2931--used in relation creation
@@ -49,7 +51,12 @@ tupleExprP :: Parser TupleExpr
4951tupleExprP = do
5052 reservedOp "tuple"
5153 attrAssocs <- braces (sepBy tupleAtomExprP comma)
52− pure (TupleExpr (M.fromList attrAssocs))
54+ --detect duplicate attribute names
55+ let dupAttrNames = dupes (sort (map fst attrAssocs))
56+ if length dupAttrNames /= 0 then
57+ fail ("Attribute names duplicated: " ++ show dupAttrNames)
58+ else
59+ pure (TupleExpr (M.fromList attrAssocs))
5360
5461tupleAtomExprP :: Parser (AttributeName, AtomExpr)
5562tupleAtomExprP = do