Changeset 10736 for src/Pugs/Prim/Match.hs
- Timestamp:
- 06/18/06 15:02:55 (2 years ago)
- Files:
-
- 1 modified
-
src/Pugs/Prim/Match.hs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim/Match.hs
r10113 r10736 14 14 import qualified Data.Array as Array 15 15 16 -- XXX - kluge: before we figure out the parrot calling convention, 17 -- we'll simply inline the adverbs into the regex. 18 ruleWithAdverbs :: VRule -> Eval VStr 19 ruleWithAdverbs MkRulePGE{ rxRule = re, rxAdverbs = advs } = do 20 when (null re) $ 21 fail "Null patterns are invalid; use <?null> or an empty string instead" 22 hv <- join $ doHash advs hash_fetch 23 advs <- forM (Map.assocs hv) $ \(k, v) -> do 24 str <- case v of 25 VBool True -> return "1" 26 VBool False -> return "0" 27 _ -> fromVal v 28 return $ \x -> ":" ++ k ++ "(" ++ str ++ ")[" ++ x ++ "]" 29 return $ combine advs re 30 ruleWithAdverbs _ = fail "PCRE regexes can't be compiled to PGE regexes" 31 16 32 doMatch :: String -> VRule -> Eval VMatch 17 -- Work around PGE bug on Parrot 0.3.1 -- empty rules are errors 18 doMatch _ MkRulePGE{ rxRule = "" } = fail "Null patterns are invalid; use <?null> or an empty string instead" 19 doMatch cs MkRulePGE{ rxRule = re } = do 33 doMatch cs rule@MkRulePGE{ rxRule = ruleStr } = do 20 34 let pwd1 = getConfig "installarchlib" ++ "/CORE/pugs/pge" 21 35 pwd2 = getConfig "sourcedir" ++ "/src/pge" … … 25 39 let syms = [ (name, tvar) | (('<':'*':name), [(_, tvar)]) <- padToList glob ] 26 40 subrules <- forM syms $ \(name, tvar) -> do 27 ref <- liftSTM $ readTVar tvar 28 (VRule rule) <- fromVal =<< readRef ref 29 return (name, rxRule rule) 30 pge <- liftIO $ evalPGE pwd (encodeUTF8 cs) (encodeUTF8 re) subrules 41 ref <- liftSTM $ readTVar tvar 42 VRule rule <- fromVal =<< readRef ref 43 text <- ruleWithAdverbs rule 44 return (name, text) 45 text <- ruleWithAdverbs rule 46 pge <- liftIO $ evalPGE pwd (encodeUTF8 cs) (encodeUTF8 text) subrules 31 47 `catch` (\e -> return $ ioeGetErrorString e) 32 48 rv <- tryIO Nothing $ fmap Just (readIO $ decodeUTF8 pge) … … 43 59 Just m -> fromVal (matchToVal m) 44 60 Nothing -> do 45 liftIO $ putStrLn ("*** Cannot parse PGE: " ++ r e++ "\n*** Error: " ++ pge)61 liftIO $ putStrLn ("*** Cannot parse PGE: " ++ ruleStr ++ "\n*** Error: " ++ pge) 46 62 return mkMatchFail 47 63
