@@ -25,8 +25,9 @@ data VerifiedTextConstraint
2525 | VTEnum [Text]
2626 deriving (Show)
2727
28−verifyTextLengthConstraints ::
29− [DemotedTextConstraint] -> Maybe (Maybe VerifiedTextConstraint)
28+verifyTextLengthConstraints
29+ :: [DemotedTextConstraint]
30+ -> Maybe (Maybe VerifiedTextConstraint)
3031verifyTextLengthConstraints cs' = do
3132 let cs = toStrictTextLength cs'
3233 mlt = simplifyDNLs [x | DTLt x <- cs]
@@ -35,7 +36,7 @@ verifyTextLengthConstraints cs' = do
3536 verifyEquations mgt meq mlt
3637 case all isNothing ([mgt, meq, mlt] :: [Maybe Integer]) of
3738 True -> Just Nothing
38− _ ->
39+ _ ->
3940 Just $
4041 Just $
4142 case meq of
@@ -46,73 +47,76 @@ regexLength :: Text -> Maybe (Int, Maybe Int)
4647regexLength regexp =
4748 case parseRegex . unpack $ regexp of
4849 Right (p, _) -> Just (minRegexLength p, maxRegexLength p)
49− Left _ -> Nothing
50+ Left _ -> Nothing
5051
5152minRegexLength :: Pattern -> Int
5253minRegexLength p =
5354 case p of
54− PEmpty -> 0
55− PChar {..} -> 1
56− PAny {..} -> 1
57− PAnyNot {..} -> 1
58− PQuest _ -> 0
59− PPlus sch -> minRegexLength $ PBound 1 Nothing sch
60− PStar _ sch -> minRegexLength $ PBound 0 Nothing sch
55+ PEmpty -> 0
56+ PChar {..} -> 1
57+ PAny {..} -> 1
58+ PAnyNot {..} -> 1
59+ PQuest _ -> 0
60+ PPlus sch -> minRegexLength $ PBound 1 Nothing sch
61+ PStar _ sch -> minRegexLength $ PBound 0 Nothing sch
6162 PBound low _ sch -> low * minRegexLength sch
62− PConcat ps -> sum $ fmap minRegexLength ps
63− POr xs -> minimum $ fmap minRegexLength xs
64− PDot _ -> 1
65− PEscape {..} -> 1
66− PCarat _ -> 0
67− PDollar _ -> 0
68− _ -> 0
63+ PConcat ps -> sum $ fmap minRegexLength ps
64+ POr xs -> minimum $ fmap minRegexLength xs
65+ PDot _ -> 1
66+ PEscape {..} -> 1
67+ PCarat _ -> 0
68+ PDollar _ -> 0
69+ _ -> 0
6970
7071maxRegexLength :: Pattern -> Maybe Int
7172maxRegexLength p =
7273 case p of
73− PEmpty -> Just 0
74− PChar _ _ -> Just 1
75− PAny _ _ -> Just 1
76− PAnyNot _ _ -> Just 1
77− PQuest _ -> Just 0
78− PPlus _ -> Nothing
79− PStar _ _ -> Nothing
74+ PEmpty -> Just 0
75+ PChar _ _ -> Just 1
76+ PAny _ _ -> Just 1
77+ PAnyNot _ _ -> Just 1
78+ PQuest _ -> Just 0
79+ PPlus _ -> Nothing
80+ PStar _ _ -> Nothing
8081 PBound _ mhigh sch -> (*) <$> mhigh <*> maxRegexLength sch
81− PConcat ps -> sum <$> mapM maxRegexLength ps
82− POr xs -> maximum <$> mapM maxRegexLength xs
83− PDot _ -> Just 1
84− PEscape _ _ -> Just 1
85− PCarat _ -> Just 0
86− PDollar _ -> Just 0
87− _ -> Just 0
82+ PConcat ps -> sum <$> mapM maxRegexLength ps
83+ POr xs -> maximum <$> mapM maxRegexLength xs
84+ PDot _ -> Just 1
85+ PEscape _ _ -> Just 1
86+ PCarat _ -> Just 0
87+ PDollar _ -> Just 0
88+ _ -> Just 0
8889
89−verifyTextRegexConstraint ::
90− [DemotedTextConstraint] -> Maybe (Maybe VerifiedTextConstraint)
90+verifyTextRegexConstraint
91+ :: [DemotedTextConstraint]
92+ -> Maybe (Maybe VerifiedTextConstraint)
9193verifyTextRegexConstraint cs = do
9294 let regexps = [x | DTRegex x <- cs]
9395 case regexps of
94− [] -> Just Nothing
96+ [] -> Just Nothing
9597 [x] -> do
9698 (l, mh) <- regexLength x
9799 Just $ Just $ VTRegex x (fromIntegral l) (fromIntegral <$> mh)
98− _ -> Nothing
100+ _ -> Nothing
99101
100−verifyTextEnumConstraint ::
101− [DemotedTextConstraint] -> Maybe (Maybe VerifiedTextConstraint)
102+verifyTextEnumConstraint
103+ :: [DemotedTextConstraint]
104+ -> Maybe (Maybe VerifiedTextConstraint)
102105verifyTextEnumConstraint cs = do
103106 let enums = concat [x | DTEnum x <- cs]
104107 case enums of
105108 [] -> Just Nothing
106− x -> Just $ Just $ VTEnum x
109+ x -> Just $ Just $ VTEnum x
107110
108−verifyTextConstraints ::
109− [DemotedTextConstraint] -> Maybe [VerifiedTextConstraint]
111+verifyTextConstraints
112+ :: [DemotedTextConstraint]
113+ -> Maybe [VerifiedTextConstraint]
110114verifyTextConstraints cs = do
111115 regexp <- verifyTextRegexConstraint cs
112116 void $ case regexp of
113117 Just (VTRegex _ l mh) ->
114118 verifyTextLengthConstraints (DTGe l : cs ++ maybeToList (DTLe <$> mh))
115− _ -> pure Nothing
119+ _ -> pure Nothing
116120 lengths <- verifyTextLengthConstraints cs
117121 enums <- verifyTextEnumConstraint cs
118122 return $ catMaybes [lengths, enums, regexp]