module Text.Regex.TDFA.NewDFA.Engine_NC_FA(execMatch) where
import Control.Monad(unless)
import Prelude hiding ((!!))
import Data.Array.MArray(MArray(..))
import Data.Array.Unsafe(unsafeFreeze)
import Data.Array.ST(STArray)
import qualified Data.IntMap.CharMap2 as CMap(findWithDefault)
import qualified Data.IntMap as IMap(null)
import qualified Data.IntSet as ISet(null)
import qualified Data.Array.MArray()
import Data.STRef(newSTRef,readSTRef,writeSTRef)
import qualified Control.Monad.ST.Strict as S(ST,runST)
import Data.Sequence(Seq)
import qualified Data.ByteString.Char8 as SBS(ByteString)
import qualified Data.ByteString.Lazy.Char8 as LBS(ByteString)
import Text.Regex.Base(MatchArray,MatchOffset,MatchLength)
import Text.Regex.TDFA.Common hiding (indent)
import Text.Regex.TDFA.NewDFA.Uncons(Uncons(uncons))
import Text.Regex.TDFA.NewDFA.MakeTest(test_singleline)
{-# SPECIALIZE execMatch :: Regex -> Position -> Char -> ([] Char) -> [MatchArray] #-}
{-# SPECIALIZE execMatch :: Regex -> Position -> Char -> (Seq Char) -> [MatchArray] #-}
{-# SPECIALIZE execMatch :: Regex -> Position -> Char -> SBS.ByteString -> [MatchArray] #-}
{-# SPECIALIZE execMatch :: Regex -> Position -> Char -> LBS.ByteString -> [MatchArray] #-}
execMatch :: Uncons text => Regex -> Position -> Char -> text -> [MatchArray]
execMatch :: Regex -> Position -> Char -> text -> [MatchArray]
execMatch (Regex { regex_dfa :: Regex -> DFA
regex_dfa = DFA {d_dt :: DFA -> DT
d_dt=DT
dtIn} })
offsetIn :: Position
offsetIn _prevIn :: Char
_prevIn inputIn :: text
inputIn = (forall s. ST s [MatchArray]) -> [MatchArray]
forall a. (forall s. ST s a) -> a
S.runST forall s. ST s [MatchArray]
goNext where
test :: WhichTest -> Position -> text -> Bool
test wt :: WhichTest
wt off :: Position
off input :: text
input = WhichTest -> Position -> Char -> text -> Bool
forall text.
Uncons text =>
WhichTest -> Position -> Char -> text -> Bool
test_singleline WhichTest
wt Position
off '\n' text
input
goNext :: ST s [MatchArray]
goNext = {-# SCC "goNext" #-} do
STRef s (Maybe Position)
winQ <- Maybe Position -> ST s (STRef s (Maybe Position))
forall a s. a -> ST s (STRef s a)
newSTRef Maybe Position
forall a. Maybe a
Nothing
let next :: DT -> Position -> a -> ST s [MatchArray]
next dt :: DT
dt offset :: Position
offset input :: a
input = {-# SCC "goNext.next" #-}
case DT
dt of
Testing' {dt_test :: DT -> WhichTest
dt_test=WhichTest
wt,dt_a :: DT -> DT
dt_a=DT
a,dt_b :: DT -> DT
dt_b=DT
b} ->
if WhichTest -> Position -> a -> Bool
forall text. Uncons text => WhichTest -> Position -> text -> Bool
test WhichTest
wt Position
offset a
input
then DT -> Position -> a -> ST s [MatchArray]
next DT
a Position
offset a
input
else DT -> Position -> a -> ST s [MatchArray]
next DT
b Position
offset a
input
Simple' {dt_win :: DT -> IntMap Instructions
dt_win=IntMap Instructions
w,dt_trans :: DT -> CharMap Transition
dt_trans=CharMap Transition
t, dt_other :: DT -> Transition
dt_other=Transition
o} -> do
Bool -> ST s () -> ST s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (IntMap Instructions -> Bool
forall a. IntMap a -> Bool
IMap.null IntMap Instructions
w) (ST s () -> ST s ()) -> ST s () -> ST s ()
forall a b. (a -> b) -> a -> b
$
STRef s (Maybe Position) -> Maybe Position -> ST s ()
forall s a. STRef s a -> a -> ST s ()
writeSTRef STRef s (Maybe Position)
winQ (Position -> Maybe Position
forall a. a -> Maybe a
Just Position
offset)