Show
Ignore:
Timestamp:
02/02/07 04:10:20 (22 months ago)
Author:
audreyt
Message:

* Filetest operators are now removed; use smartmatch against Pairs instead:

-e 'README'

!-e 'README'

becomes:

'README':e
'README'
:!e

Files:
1 modified

Legend:

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

    r14351 r15165  
    1212import qualified Data.Map as Map 
    1313import qualified Data.Array as Array 
     14import qualified Pugs.Prim.FileTest as FileTest 
    1415 
    1516-- XXX - kluge: before we figure out the parrot calling convention, 
     
    122123    op2Match x y' 
    123124 
     125op2Match x (VRef (MkRef (IPair pv))) = do  
     126    -- Pair match: ~~ :e executes the -e filetest. 
     127    (k, v)  <- pair_fetch pv 
     128    isTrue  <- fromVal v :: Eval Bool 
     129    testOp  <- fromVal k 
     130    file    <- fromVal x 
     131    rv      <- ($ file) $ case testOp of 
     132        "r" -> FileTest.isReadable 
     133        "w" -> FileTest.isWritable 
     134        "x" -> FileTest.isExecutable 
     135        "e" -> FileTest.exists 
     136        "z" -> FileTest.sizeIsZero 
     137        "s" -> FileTest.fileSize 
     138        "M" -> FileTest.fileMTime 
     139        "A" -> FileTest.fileATime 
     140        "C" -> FileTest.fileCTime 
     141        "f" -> FileTest.isFile 
     142        "d" -> FileTest.isDirectory 
     143        _   -> const $ die "Unknown file test operator" testOp 
     144    if isTrue 
     145        then return rv 
     146        else fmap (castV . not) (fromVal rv) 
     147 
    124148op2Match x (VRef y) = do 
    125149    y' <- readRef y