diff options
Diffstat (limited to 'rip.hs')
-rw-r--r-- | rip.hs | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -12,12 +12,13 @@ booltoint True = 1 parenpairs :: String -> [(Int,Int)] parenpairs = go 0 [] - where go _ [] [] = [] - go i st ('[':cs) = go (i+1) (i:st) cs - go i (s:st) (']':cs) = (s,i) : go (i+1) st cs - go i [] (']':cs) = error "rip -- unmatched closing bracket" - go i st (_:cs) = go (i+1) st cs - go _ (_:_) [] = error "rip -- unmatched open bracket" + -- index stack string + where go _ [] [] = [] + go i st ('[':cs) = go (i+1) (i:st) cs + go i (s:st) (']':cs) = (s,i) : go (i+1) st cs + go i [] (']':cs) = error "rip -- unmatched closing bracket" + go i st (_:cs) = go (i+1) st cs + go _ (_:_) [] = error "rip -- unmatched open bracket" -- returns string in and after codeblock getcodeblock :: String -> Either () (String,String) |