diff options
author | tomsmeding <hallo@tomsmeding.nl> | 2015-09-15 20:30:04 +0200 |
---|---|---|
committer | tomsmeding <hallo@tomsmeding.nl> | 2015-09-15 20:30:04 +0200 |
commit | 35acfd9a41c082cba56a638c2be8027a3e5d1b62 (patch) | |
tree | fbb295a5134a1302e93ad449bdd855900ced6dec | |
parent | 19031d6c87120db91c2849ce367930f4b089e5e0 (diff) |
Cleanup parenpairs
-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) |