Permalink
Browse files

Moved some functions higher in the file.

  • Loading branch information...
1 parent 6eaf34b commit b4ff1176637417f82a6e8cc5102e6f5987cc86bf @cgroza committed Apr 9, 2012
Showing with 8 additions and 5 deletions.
  1. +8 −5 HsRegex.hs
View
@@ -32,11 +32,17 @@ fst' (x, _, _) = x
snd' (_, y, _) = y
thrd' (_, _, z) = z
+subRange :: (Int, Int) -> [a] -> [a]
+subRange (x, y) = take (y - x) . drop x
+
+extractMatches :: String -> [(Int, Int)] -> [String]
+extractMatches str = map (flip subRange str)
+
+
+
-- for notational convienience
type Regex = [String] -> String -> Int -> (Bool, Int, [String])
-subRange :: (Int, Int) -> [a] -> [a]
-subRange (x, y) = take (y - x) . drop x
greedyMatch :: Regex -> [String] -> String -> Int -> (Int, Int)
greedyMatch m groups ss i = match ss i m 0 groups
@@ -204,9 +210,6 @@ matchRegex re ss ms i = if i < length ss then
else matchRegex re ss ms (i + 1)
else ms
-extractMatches :: String -> [(Int, Int)] -> [String]
-extractMatches str = map (flip subRange str)
-
-- apply the regex on tails str and record the matched ranges
(=~) :: String -> (String -> Int -> (Bool, Int, [String])) -> [String]
(=~) str regex = extractMatches str $ matchRegex regex (str ++ ['\n']) [] 0

0 comments on commit b4ff117

Please sign in to comment.