aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-09-15 20:30:04 +0200
committertomsmeding <hallo@tomsmeding.nl>2015-09-15 20:30:04 +0200
commit35acfd9a41c082cba56a638c2be8027a3e5d1b62 (patch)
treefbb295a5134a1302e93ad449bdd855900ced6dec
parent19031d6c87120db91c2849ce367930f4b089e5e0 (diff)
Cleanup parenpairs
-rw-r--r--rip.hs13
1 files 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)