Show
Ignore:
Timestamp:
06/20/05 06:39:30 (3 years ago)
Author:
mugwump
svk:copy_cache_prev:
6641
Message:

Implement 3-arg split (rx-only for now), update test

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim/Match.hs

    r4114 r4865  
    33 
    44module Pugs.Prim.Match ( 
    5     op2Match, rxSplit, matchFromMR 
     5    op2Match, rxSplit, rxSplit_n, matchFromMR 
    66) where 
    77import Pugs.Internals 
     
    175175            rest <- rxSplit rx after 
    176176            return $ (VStr before:matchSubPos match) ++ rest 
     177 
     178-- duplicated for now, pending über-Haskell-fu 
     179 
     180rxSplit_n :: VRule -> String -> Int -> Eval [Val] 
     181rxSplit_n _ [] n = return [] 
     182rxSplit_n rx str n = do 
     183    match <- str `doMatch` rx 
     184    if or [ ( n == 1 ), ( not (matchOk match) ) ] then return [VStr str] else do 
     185    if matchFrom match == matchTo match 
     186        then do 
     187            let (c:cs) = str 
     188            rest <- rxSplit_n rx (cs) (n-1) 
     189            return (VStr [c]:rest) 
     190        else do 
     191            let before = genericTake (matchFrom match) str 
     192                after  = genericDrop (matchTo match) str 
     193            rest <- rxSplit_n rx after (n-1) 
     194            return $ (VStr before:matchSubPos match) ++ rest