Commit 24d29590 by Camil Staps 🙂

cleanup

parent c49f1a9c
 ... ... @@ -54,10 +54,12 @@ match` EndOfString st = if (isEmpty st.unseen) [st] [] skip :: Int MatchStatus -> MatchStatus skip n st = {st & skipped=st.skipped ++ take n st.unseen, unseen=drop n st.unseen} skip n st = {st & skipped=st.skipped ++ take n st.unseen, unseen=drop n st.unseen} eat :: Int MatchStatus -> MatchStatus eat n st = {st & matched=st.matched ++ take n st.unseen, unseen=drop n st.unseen} eat n st = {st & matched=st.matched ++ take n st.unseen, unseen=drop n st.unseen} matchAndContinue :: Regex MatchStatus [MatchStatus] -> [MatchStatus] matchAndContinue r st sts = sts ++ ... ...
 ... ... @@ -9,16 +9,17 @@ import StdTuple from Data.Func import \$ import Data.List import Data.Maybe from Text import class Text(concat), instance Text String, instance + String import Regex import Regex.Util print :: Bool Regex -> String print ps (Literal cs) = parens (ps && length cs > 1) \$ foldl (+++) "" \$ map escape cs print ps (CharacterClass True cc) = foldl (+++) "[^" (printCharClasses cc) +++ "]" print ps (Literal cs) = parens (ps && length cs > 1) \$ concat \$ map escape cs print ps (CharacterClass True cc) = "[^" + concat (printCharClasses cc) + "]" print ps (CharacterClass False cc) | length ccs == 1 = hd ccs | otherwise = foldl (+++) "[" ccs +++ "]" | otherwise = "[" + concat ccs + "]" where ccs = printCharClasses cc print ps (CharacterClass False [('\0','\255')]) = "." print ps (CharacterClass n cs) = "[" <+ if n "^" "" <+ foldl (<++) "" cs <+ "]" ... ... @@ -27,9 +28,9 @@ where (<++) s (c1,c2) | c1 == c2 = s <+ c1 | otherwise = s <+ c1 <+ "-" <+ c2 print ps (Concat rgxs) = parens ps \$ foldl (\x s -> x +++ s) r rs print ps (Concat rgxs) = parens ps \$ foldl (+) r rs where [r:rs] = map (print True) rgxs print ps (Any rgxs) = parens ps \$ foldl (\x s -> x +++ "|" +++ s) r rs print ps (Any rgxs) = parens ps \$ foldl (\x s -> x + "|" + s) r rs where [r:rs] = map (print True) rgxs print ps (Repeated g 0 (Just 1) r) = print True r <+ "?" <+ lz g print ps (Repeated g 1 (Just 1) r) = print True r ... ... @@ -56,7 +57,7 @@ parens True s = "(?:" <+ s <+ ")" parens False s = toString s (<+) infixr 5 :: a b -> String | toString a & toString b (<+) x y = toString x +++ toString y (<+) x y = toString x + toString y printCharClasses :: [(Char,Char)] -> [String] printCharClasses [] = [] ... ... @@ -64,7 +65,8 @@ printCharClasses cs = case findShorthand shorthand_classes cs of (Just (n,cs`)) = [n:printCharClasses cs`] Nothing = map printRange cs where findShorthand :: [(Char, [(Char,Char)])] [(Char,Char)] -> Maybe (String, [(Char,Char)]) findShorthand :: [(Char, [(Char,Char)])] [(Char,Char)] -> Maybe (String, [(Char,Char)]) findShorthand [] _ = Nothing findShorthand [(n,ndl):shts] hay | all (flip isMember hay) ndl = Just ({'\\',n}, foldr removeMember hay ndl) ... ... @@ -74,7 +76,7 @@ where printRange ('\0','\255') = "." printRange (c1,c2) | c1 == c2 = c1` | otherwise = c1` +++ "-" +++ c2` | otherwise = c1` + "-" + c2` where (c1`,c2`) = (escape c1, escape c2) escape :: Char -> String ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!