From 35acfd9a41c082cba56a638c2be8027a3e5d1b62 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 15 Sep 2015 20:30:04 +0200 Subject: Cleanup parenpairs --- rip.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rip.hs b/rip.hs index e10ddb5..25ff98f 100644 --- a/rip.hs +++ b/rip.hs @@ -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) -- cgit v1.2.3-70-g09d2