@@ -25,8 +25,9 @@ data VerifiedTextConstraint
25 | VTEnum [Text]
25 | VTEnum [Text]
26 deriving (Show)
26 deriving (Show)
28−verifyTextLengthConstraints ::
28+verifyTextLengthConstraints
29+ :: [DemotedTextConstraint]
29− [DemotedTextConstraint] -> Maybe (Maybe VerifiedTextConstraint)
30+ -> Maybe (Maybe VerifiedTextConstraint)
30verifyTextLengthConstraints cs' = do
31verifyTextLengthConstraints cs' = do
31 let cs = toStrictTextLength cs'
32 let cs = toStrictTextLength cs'
32 mlt = simplifyDNLs [x | DTLt x <- cs]
33 mlt = simplifyDNLs [x | DTLt x <- cs]
@@ -35,7 +36,7 @@ verifyTextLengthConstraints cs' = do
35 verifyEquations mgt meq mlt
36 verifyEquations mgt meq mlt
36 case all isNothing ([mgt, meq, mlt] :: [Maybe Integer]) of
37 case all isNothing ([mgt, meq, mlt] :: [Maybe Integer]) of
37 True -> Just Nothing
38 True -> Just Nothing
41 case meq of
42 case meq of
@@ -46,73 +47,76 @@ regexLength :: Text -> Maybe (Int, Maybe Int)
46regexLength regexp =
47regexLength regexp =
47 case parseRegex . unpack $ regexp of
48 case parseRegex . unpack $ regexp of
48 Right (p, _) -> Just (minRegexLength p, maxRegexLength p)
49 Right (p, _) -> Just (minRegexLength p, maxRegexLength p)
49− Left _ -> Nothing
50+ Left _ -> Nothing
51minRegexLength :: Pattern -> Int
52minRegexLength :: Pattern -> Int
52minRegexLength p =
53minRegexLength p =
54− PEmpty -> 0
55+ PEmpty -> 0
55− PChar {..} -> 1
56+ PChar {..} -> 1
56− PAny {..} -> 1
57+ PAny {..} -> 1
57− PAnyNot {..} -> 1
58+ PAnyNot {..} -> 1
58− PQuest _ -> 0
59+ PQuest _ -> 0
59− PPlus sch -> minRegexLength $ PBound 1 Nothing sch
60+ PPlus sch -> minRegexLength $ PBound 1 Nothing sch
60− PStar _ sch -> minRegexLength $ PBound 0 Nothing sch
61+ PStar _ sch -> minRegexLength $ PBound 0 Nothing sch
61 PBound low _ sch -> low * minRegexLength sch
62 PBound low _ sch -> low * minRegexLength sch
62− PConcat ps -> sum $ fmap minRegexLength ps
63+ PConcat ps -> sum $ fmap minRegexLength ps
63− POr xs -> minimum $ fmap minRegexLength xs
64+ POr xs -> minimum $ fmap minRegexLength xs
64− PDot _ -> 1
65+ PDot _ -> 1
65− PEscape {..} -> 1
66+ PEscape {..} -> 1
66− PCarat _ -> 0
67+ PCarat _ -> 0
67− PDollar _ -> 0
68+ PDollar _ -> 0
70maxRegexLength :: Pattern -> Maybe Int
71maxRegexLength :: Pattern -> Maybe Int
71maxRegexLength p =
72maxRegexLength p =
73− PEmpty -> Just 0
74+ PEmpty -> Just 0
74− PChar _ _ -> Just 1
75+ PChar _ _ -> Just 1
75− PAny _ _ -> Just 1
76+ PAny _ _ -> Just 1
76− PAnyNot _ _ -> Just 1
77+ PAnyNot _ _ -> Just 1
77− PQuest _ -> Just 0
78+ PQuest _ -> Just 0
78− PPlus _ -> Nothing
79+ PPlus _ -> Nothing
79− PStar _ _ -> Nothing
80+ PStar _ _ -> Nothing
80 PBound _ mhigh sch -> (*) <$> mhigh <*> maxRegexLength sch
81 PBound _ mhigh sch -> (*) <$> mhigh <*> maxRegexLength sch
81− PConcat ps -> sum <$> mapM maxRegexLength ps
82+ PConcat ps -> sum <$> mapM maxRegexLength ps
82− POr xs -> maximum <$> mapM maxRegexLength xs
83+ POr xs -> maximum <$> mapM maxRegexLength xs
83− PDot _ -> Just 1
84+ PDot _ -> Just 1
84− PEscape _ _ -> Just 1
85+ PEscape _ _ -> Just 1
85− PCarat _ -> Just 0
86+ PCarat _ -> Just 0
86− PDollar _ -> Just 0
87+ PDollar _ -> Just 0
87− _ -> Just 0
88+ _ -> Just 0
89−verifyTextRegexConstraint ::
90+verifyTextRegexConstraint
91+ :: [DemotedTextConstraint]
90− [DemotedTextConstraint] -> Maybe (Maybe VerifiedTextConstraint)
92+ -> Maybe (Maybe VerifiedTextConstraint)
91verifyTextRegexConstraint cs = do
93verifyTextRegexConstraint cs = do
92 let regexps = [x | DTRegex x <- cs]
94 let regexps = [x | DTRegex x <- cs]
93 case regexps of
95 case regexps of
94− [] -> Just Nothing
96+ [] -> Just Nothing
96 (l, mh) <- regexLength x
98 (l, mh) <- regexLength x
97 Just $ Just $ VTRegex x (fromIntegral l) (fromIntegral <$> mh)
99 Just $ Just $ VTRegex x (fromIntegral l) (fromIntegral <$> mh)
98− _ -> Nothing
100+ _ -> Nothing
100−verifyTextEnumConstraint ::
102+verifyTextEnumConstraint
103+ :: [DemotedTextConstraint]
101− [DemotedTextConstraint] -> Maybe (Maybe VerifiedTextConstraint)
104+ -> Maybe (Maybe VerifiedTextConstraint)
102verifyTextEnumConstraint cs = do
105verifyTextEnumConstraint cs = do
103 let enums = concat [x | DTEnum x <- cs]
106 let enums = concat [x | DTEnum x <- cs]
104 case enums of
107 case enums of
105 [] -> Just Nothing
108 [] -> Just Nothing
106− x -> Just $ Just $ VTEnum x
109+ x -> Just $ Just $ VTEnum x
108−verifyTextConstraints ::
111+verifyTextConstraints
112+ :: [DemotedTextConstraint]
109− [DemotedTextConstraint] -> Maybe [VerifiedTextConstraint]
113+ -> Maybe [VerifiedTextConstraint]
110verifyTextConstraints cs = do
114verifyTextConstraints cs = do
111 regexp <- verifyTextRegexConstraint cs
115 regexp <- verifyTextRegexConstraint cs
112 void $ case regexp of
116 void $ case regexp of
113 Just (VTRegex _ l mh) ->
117 Just (VTRegex _ l mh) ->
114 verifyTextLengthConstraints (DTGe l : cs ++ maybeToList (DTLe <$> mh))
118 verifyTextLengthConstraints (DTGe l : cs ++ maybeToList (DTLe <$> mh))
115− _ -> pure Nothing
119+ _ -> pure Nothing
116 lengths <- verifyTextLengthConstraints cs
120 lengths <- verifyTextLengthConstraints cs
117 enums <- verifyTextEnumConstraint cs
121 enums <- verifyTextEnumConstraint cs
118 return $ catMaybes [lengths, enums, regexp]
122 return $ catMaybes [lengths, enums, regexp]