Changeset 4986 for src/Pugs/Prim/Match.hs
- Timestamp:
- 06/26/05 10:01:46 (3 years ago)
- svk:copy_cache_prev:
- 6771
- Files:
-
- 1 modified
-
src/Pugs/Prim/Match.hs (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim/Match.hs
r4922 r4986 3 3 4 4 module Pugs.Prim.Match ( 5 op2Match, rxSplit, rxSplit_n, matchFromMR 5 op2Match, rxSplit, rxSplit_n, matchFromMR, pkgParents 6 6 ) where 7 7 import Pugs.Internals … … 9 9 import Pugs.AST 10 10 import Pugs.Types 11 import Pugs.Context12 11 import Pugs.Config 13 12 import qualified RRegex.PCRE as PCRE … … 74 73 -- XXX - need to generalise this 75 74 op2Match :: Val -> Val -> Eval Val 75 76 op2Match x (VRef (MkRef (IScalar sv))) | scalar_iType sv == mkType "Scalar::Const" = do 77 y' <- scalar_fetch' sv 78 op2Match x y' 79 76 80 op2Match x (VRef y) = do 77 81 y' <- readRef y 78 82 op2Match x y' 83 84 op2Match x y@(VObject MkObject{ objType = MkType "Class" } ) = do 85 fetch <- doHash y hash_fetchVal 86 name <- fromVal =<< fetch "name" 87 op2Match x (VType (MkType name)) 79 88 80 89 op2Match x (VSubst (rx, subst)) | rxGlobal rx = do … … 147 156 148 157 op2Match (VType typ) (VType t) = do 149 cls <- asks envClasses150 return $ VBool (isaType cls (showType t) typ)158 typs <- pkgParents (showType typ) 159 return . VBool $ showType t `elem` typs 151 160 152 161 op2Match x y@(VType _) = do … … 154 163 op2Match (VType typ) y 155 164 156 op2Match x y = op2Cmp (fromVal :: Val -> Eval VStr) (==) x y 165 op2Match x y = do 166 op2Cmp (fromVal :: Val -> Eval VStr) (==) x y 157 167 158 168 op2Cmp :: (a -> Eval b) -> (b -> b -> VBool) -> a -> a -> Eval Val … … 195 205 rest <- rxSplit_n rx after (n-1) 196 206 return $ (VStr before:matchSubPos match) ++ rest 207 208 pkgParents :: VStr -> Eval [VStr] 209 pkgParents pkg = do 210 ref <- readVar (':':'*':pkg) 211 if ref == undef then return [] else do 212 meta <- readRef =<< fromVal ref 213 fetch <- doHash meta hash_fetchVal 214 attrs <- fromVal =<< fetch "traits" 215 pkgs <- mapM pkgParents attrs 216 return $ nub (pkg:concat pkgs) 217
