Show
Ignore:
Timestamp:
11/05/05 23:47:32 (3 years ago)
Author:
autrijus
Message:

* Work around PGE's bug in not grokking zero-width rules

(reporte to p6[ic]), by special casing that // matches
always at position 0 with length 0. It's useful anyway
because split(//, $string) can be fast without launching
Parrot.

* Also, fix m:g// and m:P5:g// support so they won't loop

on zero-width matches. (Previously s:g// and s:P5:g//
was fixed in the same fashion.)

Files:
1 modified

Legend:

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

    r7854 r7861  
    1515 
    1616doMatch :: String -> VRule -> Eval VMatch 
     17-- Work around PGE bug on Parrot 0.3.1 -- empty rule matches automatically 
     18doMatch _ MkRulePGE{ rxRule = "" } = return $ mkMatchOk 0 0 "" [] Map.empty 
    1719doMatch cs MkRulePGE{ rxRule = re } = do 
    1820    let pwd1 = getConfig "installarchlib" ++ "/CORE/pugs/pge" 
     
    153155    where 
    154156    hasSubpatterns = case rx of 
    155         MkRulePGE{}             -> True -- bogus 
     157        MkRulePGE{}             -> True -- XXX bogus - use <p6rule> to parse itself 
    156158        MkRulePCRE{rxNumSubs=n} -> not (n == 0) 
    157159    matchOnce :: String -> Eval [Val] 
     
    159161        match <- str `doMatch` rx 
    160162        if not (matchOk match) then return [] else do 
    161         rest <- matchOnce (genericDrop (matchTo match) str) 
    162         return $ if hasSubpatterns 
    163                  then (matchSubPos match) ++ rest 
    164                  else (VMatch match):rest 
     163        let ret x = return $ if hasSubpatterns 
     164                        then (matchSubPos match) ++ x 
     165                        else (VMatch match):x 
     166        case (matchTo match, matchFrom match) of 
     167            (0, 0) -> if null str then ret [] else do 
     168                rest <- matchOnce (tail str) 
     169                ret rest 
     170            (to, _) -> do 
     171                rest <- matchOnce (genericDrop to str) 
     172                ret rest 
    165173 
    166174op2Match x (VRule rx) = do 
     
    210218        then do 
    211219            let (c:cs) = str 
    212             rest <- rxSplit rx (cs) 
     220            rest <- rxSplit rx cs 
    213221            return (VStr [c]:rest) 
    214222        else do