module Text.Regex.TDFA.CorePattern(Q(..),P(..),WhichTest(..),Wanted(..)
,TestInfo,OP(..),SetTestInfo(..),NullView
,patternToQ,cleanNullView,cannotAccept,mustAccept) where
import Control.Monad (liftM2, forM, replicateM)
import Control.Monad.RWS (RWS, runRWS, ask, local, listens, tell, get, put)
import Data.Array.IArray(Array,(!),accumArray,listArray)
import Data.Either (partitionEithers, rights)
import Data.List(sort)
import Data.IntMap.EnumMap2(EnumMap)
import qualified Data.IntMap.EnumMap2 as Map(singleton,null,assocs,keysSet)
import Data.IntSet.EnumSet2(EnumSet)
import qualified Data.IntSet.EnumSet2 as Set(singleton,toList,isSubsetOf)
import Data.Semigroup as Sem
import Text.Regex.TDFA.Common
import Text.Regex.TDFA.Pattern(Pattern(..),starTrans)
data P = Empty
| Or [Q]
| Seq Q Q
| Star { P -> Maybe GroupIndex
getOrbit :: Maybe Tag
, P -> [GroupIndex]
resetOrbits :: [Tag]
, P -> Bool
firstNull :: Bool
, P -> Q
unStar :: Q}
| Test TestInfo
| OneChar Pattern
| NonEmpty Q
deriving (GroupIndex -> P -> ShowS
[P] -> ShowS
P -> String
(GroupIndex -> P -> ShowS)
-> (P -> String) -> ([P] -> ShowS) -> Show P
forall a.
(GroupIndex -> a -> ShowS)
-> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: GroupIndex -> P -> ShowS
showsPrec :: GroupIndex -> P -> ShowS
$cshow :: P -> String
show :: P -> String
$cshowList :: [P] -> ShowS
showList :: [P] -> ShowS
Show,P -> P -> Bool
(P -> P -> Bool) -> (P -> P -> Bool) -> Eq P
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: P -> P -> Bool
== :: P -> P -> Bool
$c/= :: P -> P -> Bool
/= :: P -> P -> Bool
Eq)
data Q = Q {Q -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nullQ :: NullView
,Q -> (GroupIndex, Maybe GroupIndex)
takes :: (Position,Maybe Position)
,Q -> [GroupIndex]
preReset :: [Tag]
,Q -> [GroupIndex]
postSet :: [Tag]
,Q -> Maybe GroupIndex
preTag,Q -> Maybe GroupIndex
postTag :: Maybe Tag
,Q -> Bool
tagged :: Bool
,Q -> Bool
childGroups :: Bool
,Q -> Wanted
wants :: Wanted
,Q -> P
unQ :: P} deriving (Q -> Q -> Bool
(Q -> Q -> Bool) -> (Q -> Q -> Bool) -> Eq Q
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Q -> Q -> Bool
== :: Q -> Q -> Bool
$c/= :: Q -> Q -> Bool
/= :: Q -> Q -> Bool
Eq)
type TestInfo = (WhichTest,DoPa)
newtype SetTestInfo = SetTestInfo {SetTestInfo -> EnumMap WhichTest (EnumSet DoPa)
getTests :: EnumMap WhichTest (EnumSet DoPa)} deriving (SetTestInfo -> SetTestInfo -> Bool
(SetTestInfo -> SetTestInfo -> Bool)
-> (SetTestInfo -> SetTestInfo -> Bool) -> Eq SetTestInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetTestInfo -> SetTestInfo -> Bool
== :: SetTestInfo -> SetTestInfo -> Bool
$c/= :: SetTestInfo -> SetTestInfo -> Bool
/= :: SetTestInfo -> SetTestInfo -> Bool
Eq)
instance Semigroup SetTestInfo where
SetTestInfo EnumMap WhichTest (EnumSet DoPa)
x <> :: SetTestInfo -> SetTestInfo -> SetTestInfo
<> SetTestInfo EnumMap WhichTest (EnumSet DoPa)
y = EnumMap WhichTest (EnumSet DoPa) -> SetTestInfo
SetTestInfo (EnumMap WhichTest (EnumSet DoPa)
x EnumMap WhichTest (EnumSet DoPa)
-> EnumMap WhichTest (EnumSet DoPa)
-> EnumMap WhichTest (EnumSet DoPa)
forall a. Semigroup a => a -> a -> a
Sem.<> EnumMap WhichTest (EnumSet DoPa)
y)
instance Monoid SetTestInfo where
mempty :: SetTestInfo
mempty = EnumMap WhichTest (EnumSet DoPa) -> SetTestInfo
SetTestInfo EnumMap WhichTest (EnumSet DoPa)
forall a. Monoid a => a
mempty
mappend :: SetTestInfo -> SetTestInfo -> SetTestInfo
mappend = SetTestInfo -> SetTestInfo -> SetTestInfo
forall a. Semigroup a => a -> a -> a
(Sem.<>)
instance Show SetTestInfo where
show :: SetTestInfo -> String
show (SetTestInfo EnumMap WhichTest (EnumSet DoPa)
sti) = String
"SetTestInfo "String -> ShowS
forall a. [a] -> [a] -> [a]
++[(WhichTest, [DoPa])] -> String
forall a. Show a => a -> String
show ((EnumSet DoPa -> [DoPa])
-> [(WhichTest, EnumSet DoPa)] -> [(WhichTest, [DoPa])]
forall (f :: * -> *) t1 t2 t.
Functor f =>
(t1 -> t2) -> f (t, t1) -> f (t, t2)
mapSnd (EnumSet DoPa -> [DoPa]
forall e. Enum e => EnumSet e -> [e]
Set.toList) ([(WhichTest, EnumSet DoPa)] -> [(WhichTest, [DoPa])])
-> [(WhichTest, EnumSet DoPa)] -> [(WhichTest, [DoPa])]
forall a b. (a -> b) -> a -> b
$ EnumMap WhichTest (EnumSet DoPa) -> [(WhichTest, EnumSet DoPa)]
forall key a. Enum key => EnumMap key a -> [(key, a)]
Map.assocs EnumMap WhichTest (EnumSet DoPa)
sti)
type NullView = [(SetTestInfo,TagList)]
data HandleTag = NoTag
| Advice Tag
| Apply Tag
deriving (GroupIndex -> HandleTag -> ShowS
[HandleTag] -> ShowS
HandleTag -> String
(GroupIndex -> HandleTag -> ShowS)
-> (HandleTag -> String)
-> ([HandleTag] -> ShowS)
-> Show HandleTag
forall a.
(GroupIndex -> a -> ShowS)
-> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: GroupIndex -> HandleTag -> ShowS
showsPrec :: GroupIndex -> HandleTag -> ShowS
$cshow :: HandleTag -> String
show :: HandleTag -> String
$cshowList :: [HandleTag] -> ShowS
showList :: [HandleTag] -> ShowS
Show)
data Wanted = WantsQNFA | WantsQT | WantsBoth | WantsEither deriving (Wanted -> Wanted -> Bool
(Wanted -> Wanted -> Bool)
-> (Wanted -> Wanted -> Bool) -> Eq Wanted
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Wanted -> Wanted -> Bool
== :: Wanted -> Wanted -> Bool
$c/= :: Wanted -> Wanted -> Bool
/= :: Wanted -> Wanted -> Bool
Eq,GroupIndex -> Wanted -> ShowS
[Wanted] -> ShowS
Wanted -> String
(GroupIndex -> Wanted -> ShowS)
-> (Wanted -> String) -> ([Wanted] -> ShowS) -> Show Wanted
forall a.
(GroupIndex -> a -> ShowS)
-> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: GroupIndex -> Wanted -> ShowS
showsPrec :: GroupIndex -> Wanted -> ShowS
$cshow :: Wanted -> String
show :: Wanted -> String
$cshowList :: [Wanted] -> ShowS
showList :: [Wanted] -> ShowS
Show)
instance Show Q where
show :: Q -> String
show = Q -> String
showQ
showQ :: Q -> String
showQ :: Q -> String
showQ Q
q = String
"Q { nullQ = "String -> ShowS
forall a. [a] -> [a] -> [a]
++[(SetTestInfo, [(GroupIndex, TagUpdate)])] -> String
forall a. Show a => a -> String
show (Q -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nullQ Q
q)String -> ShowS
forall a. [a] -> [a] -> [a]
++
String
"\n , takes = "String -> ShowS
forall a. [a] -> [a] -> [a]
++(GroupIndex, Maybe GroupIndex) -> String
forall a. Show a => a -> String
show (Q -> (GroupIndex, Maybe GroupIndex)
takes Q
q)String -> ShowS
forall a. [a] -> [a] -> [a]
++
String
"\n , preReset = "String -> ShowS
forall a. [a] -> [a] -> [a]
++[GroupIndex] -> String
forall a. Show a => a -> String
show (Q -> [GroupIndex]
preReset Q
q)String -> ShowS
forall a. [a] -> [a] -> [a]
++
String
"\n , postSet = "String -> ShowS
forall a. [a] -> [a] -> [a]
++[GroupIndex] -> String
forall a. Show a => a -> String
show (Q -> [GroupIndex]
postSet Q
q)String -> ShowS
forall a. [a] -> [a] -> [a]
++
String
"\n , preTag = "String -> ShowS
forall a. [a] -> [a] -> [a]
++Maybe GroupIndex -> String
forall a. Show a => a -> String
show (Q -> Maybe GroupIndex
preTag Q
q)String -> ShowS
forall a. [a] -> [a] -> [a]
++
String
"\n , postTag = "String -> ShowS
forall a. [a] -> [a] -> [a]
++Maybe GroupIndex -> String
forall a. Show a => a -> String
show (Q -> Maybe GroupIndex
postTag Q
q)String -> ShowS
forall a. [a] -> [a] -> [a]
++
String
"\n , tagged = "String -> ShowS
forall a. [a] -> [a] -> [a]
++Bool -> String
forall a. Show a => a -> String
show (Q -> Bool
tagged Q
q)String -> ShowS
forall a. [a] -> [a] -> [a]
++
String
"\n , wants = "String -> ShowS
forall a. [a] -> [a] -> [a]
++Wanted -> String
forall a. Show a => a -> String
show (Q -> Wanted
wants Q
q)String -> ShowS
forall a. [a] -> [a] -> [a]
++
String
"\n , unQ = "String -> ShowS
forall a. [a] -> [a] -> [a]
++ P -> String
indent' (Q -> P
unQ Q
q)String -> ShowS
forall a. [a] -> [a] -> [a]
++String
" }"
where indent' :: P -> String
indent' = [String] -> String
unlines ([String] -> String) -> (P -> [String]) -> P -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\[String]
s -> case [String]
s of
[] -> []
(String
h:[String]
t) -> String
h String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (ShowS -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String
spaces String -> ShowS
forall a. [a] -> [a] -> [a]
++) [String]
t)) ([String] -> [String]) -> (P -> [String]) -> P -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines (String -> [String]) -> (P -> String) -> P -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. P -> String
forall a. Show a => a -> String
show
spaces :: String
spaces = GroupIndex -> Char -> String
forall a. GroupIndex -> a -> [a]
replicate GroupIndex
10 Char
' '
notNull :: NullView
notNull :: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
notNull = []
promotePreTag :: HandleTag -> TagList
promotePreTag :: HandleTag -> [(GroupIndex, TagUpdate)]
promotePreTag = [(GroupIndex, TagUpdate)]
-> (GroupIndex -> [(GroupIndex, TagUpdate)])
-> Maybe GroupIndex
-> [(GroupIndex, TagUpdate)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\GroupIndex
x -> [(GroupIndex
x,TagTask -> TagUpdate
PreUpdate TagTask
TagTask)]) (Maybe GroupIndex -> [(GroupIndex, TagUpdate)])
-> (HandleTag -> Maybe GroupIndex)
-> HandleTag
-> [(GroupIndex, TagUpdate)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HandleTag -> Maybe GroupIndex
apply
makeEmptyNullView :: HandleTag -> HandleTag -> NullView
makeEmptyNullView :: HandleTag
-> HandleTag -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
makeEmptyNullView HandleTag
a HandleTag
b = [(SetTestInfo
forall a. Monoid a => a
mempty, HandleTag -> [(GroupIndex, TagUpdate)]
promotePreTag HandleTag
a [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
forall a. [a] -> [a] -> [a]
++ HandleTag -> [(GroupIndex, TagUpdate)]
promotePreTag HandleTag
b)]
makeTestNullView :: TestInfo -> HandleTag -> HandleTag -> NullView
makeTestNullView :: (WhichTest, DoPa)
-> HandleTag
-> HandleTag
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
makeTestNullView (WhichTest
w,DoPa
d) HandleTag
a HandleTag
b = [(EnumMap WhichTest (EnumSet DoPa) -> SetTestInfo
SetTestInfo (WhichTest -> EnumSet DoPa -> EnumMap WhichTest (EnumSet DoPa)
forall key a. Enum key => key -> a -> EnumMap key a
Map.singleton WhichTest
w (DoPa -> EnumSet DoPa
forall e. Enum e => e -> EnumSet e
Set.singleton DoPa
d)), HandleTag -> [(GroupIndex, TagUpdate)]
promotePreTag HandleTag
a [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
forall a. [a] -> [a] -> [a]
++ HandleTag -> [(GroupIndex, TagUpdate)]
promotePreTag HandleTag
b)]
tagWrapNullView :: HandleTag -> HandleTag -> NullView -> NullView
tagWrapNullView :: HandleTag
-> HandleTag
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
tagWrapNullView HandleTag
a HandleTag
b [(SetTestInfo, [(GroupIndex, TagUpdate)])]
oldNV =
case (HandleTag -> [(GroupIndex, TagUpdate)]
promotePreTag HandleTag
a, HandleTag -> [(GroupIndex, TagUpdate)]
promotePreTag HandleTag
b) of
([],[]) -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
oldNV
([(GroupIndex, TagUpdate)]
pre,[(GroupIndex, TagUpdate)]
post) -> do
(oldTests,oldTasks) <- [(SetTestInfo, [(GroupIndex, TagUpdate)])]
oldNV
return (oldTests,pre++oldTasks++post)
addGroupResetsToNullView :: [Tag] -> Tag -> NullView -> NullView
addGroupResetsToNullView :: [GroupIndex]
-> GroupIndex
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
addGroupResetsToNullView [GroupIndex]
groupResets GroupIndex
groupSet [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nv = [ (SetTestInfo
test, [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
prepend ([(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
append [(GroupIndex, TagUpdate)]
tags) ) | (SetTestInfo
test,[(GroupIndex, TagUpdate)]
tags) <- [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nv ]
where prepend :: [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
prepend = ((GroupIndex, TagUpdate)
-> ([(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)])
-> ([(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(GroupIndex, TagUpdate)
h [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
t -> ((GroupIndex, TagUpdate)
h(GroupIndex, TagUpdate)
-> [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
forall a. a -> [a] -> [a]
:)([(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> ([(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.[(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
t) [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
forall a. a -> a
id ([(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> ([GroupIndex] -> [(GroupIndex, TagUpdate)])
-> [GroupIndex]
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GroupIndex -> (GroupIndex, TagUpdate))
-> [GroupIndex] -> [(GroupIndex, TagUpdate)]
forall a b. (a -> b) -> [a] -> [b]
map (\GroupIndex
tag->(GroupIndex
tag,TagTask -> TagUpdate
PreUpdate TagTask
ResetGroupStopTask)) ([GroupIndex]
-> [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> [GroupIndex]
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
forall a b. (a -> b) -> a -> b
$ [GroupIndex]
groupResets
append :: [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
append = ([(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
forall a. [a] -> [a] -> [a]
++[(GroupIndex
groupSet,TagTask -> TagUpdate
PreUpdate TagTask
SetGroupStopTask)])
orbitWrapNullView :: Maybe Tag -> [Tag] -> NullView -> NullView
orbitWrapNullView :: Maybe GroupIndex
-> [GroupIndex]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
orbitWrapNullView Maybe GroupIndex
mOrbit [GroupIndex]
orbitResets [(SetTestInfo, [(GroupIndex, TagUpdate)])]
oldNV =
case (Maybe GroupIndex
mOrbit,[GroupIndex]
orbitResets) of
(Maybe GroupIndex
Nothing,[]) -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
oldNV
(Maybe GroupIndex
Nothing,[GroupIndex]
_) -> do (oldTests,oldTasks) <- [(SetTestInfo, [(GroupIndex, TagUpdate)])]
oldNV
return (oldTests,prepend oldTasks)
(Just GroupIndex
o,[GroupIndex]
_) -> do (oldTests,oldTasks) <- [(SetTestInfo, [(GroupIndex, TagUpdate)])]
oldNV
return (oldTests,prepend $ [(o,PreUpdate EnterOrbitTask)] ++ oldTasks ++ [(o,PreUpdate LeaveOrbitTask)])
where prepend :: [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
prepend = ((GroupIndex, TagUpdate)
-> ([(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)])
-> ([(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(GroupIndex, TagUpdate)
h [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
t -> ((GroupIndex, TagUpdate)
h(GroupIndex, TagUpdate)
-> [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
forall a. a -> [a] -> [a]
:)([(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> ([(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.[(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
t) [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)]
forall a. a -> a
id ([(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> ([GroupIndex] -> [(GroupIndex, TagUpdate)])
-> [GroupIndex]
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GroupIndex -> (GroupIndex, TagUpdate))
-> [GroupIndex] -> [(GroupIndex, TagUpdate)]
forall a b. (a -> b) -> [a] -> [b]
map (\GroupIndex
tag->(GroupIndex
tag,TagTask -> TagUpdate
PreUpdate TagTask
ResetOrbitTask)) ([GroupIndex]
-> [(GroupIndex, TagUpdate)] -> [(GroupIndex, TagUpdate)])
-> [GroupIndex]
-> [(GroupIndex, TagUpdate)]
-> [(GroupIndex, TagUpdate)]
forall a b. (a -> b) -> a -> b
$ [GroupIndex]
orbitResets
cleanNullView :: NullView -> NullView
cleanNullView :: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
cleanNullView [] = []
cleanNullView (first :: (SetTestInfo, [(GroupIndex, TagUpdate)])
first@(SetTestInfo EnumMap WhichTest (EnumSet DoPa)
sti,[(GroupIndex, TagUpdate)]
_):[(SetTestInfo, [(GroupIndex, TagUpdate)])]
rest) | EnumMap WhichTest (EnumSet DoPa) -> Bool
forall key a. Enum key => EnumMap key a -> Bool
Map.null EnumMap WhichTest (EnumSet DoPa)
sti = (SetTestInfo, [(GroupIndex, TagUpdate)])
first (SetTestInfo, [(GroupIndex, TagUpdate)])
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall a. a -> [a] -> [a]
: []
| Bool
otherwise =
(SetTestInfo, [(GroupIndex, TagUpdate)])
first (SetTestInfo, [(GroupIndex, TagUpdate)])
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall a. a -> [a] -> [a]
: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
cleanNullView (((SetTestInfo, [(GroupIndex, TagUpdate)]) -> Bool)
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> ((SetTestInfo, [(GroupIndex, TagUpdate)]) -> Bool)
-> (SetTestInfo, [(GroupIndex, TagUpdate)])
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EnumSet WhichTest
setTI EnumSet WhichTest -> EnumSet WhichTest -> Bool
forall e. Enum e => EnumSet e -> EnumSet e -> Bool
`Set.isSubsetOf`) (EnumSet WhichTest -> Bool)
-> ((SetTestInfo, [(GroupIndex, TagUpdate)]) -> EnumSet WhichTest)
-> (SetTestInfo, [(GroupIndex, TagUpdate)])
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EnumMap WhichTest (EnumSet DoPa) -> EnumSet WhichTest
forall key a. Enum key => EnumMap key a -> EnumSet key
Map.keysSet (EnumMap WhichTest (EnumSet DoPa) -> EnumSet WhichTest)
-> ((SetTestInfo, [(GroupIndex, TagUpdate)])
-> EnumMap WhichTest (EnumSet DoPa))
-> (SetTestInfo, [(GroupIndex, TagUpdate)])
-> EnumSet WhichTest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SetTestInfo -> EnumMap WhichTest (EnumSet DoPa)
getTests (SetTestInfo -> EnumMap WhichTest (EnumSet DoPa))
-> ((SetTestInfo, [(GroupIndex, TagUpdate)]) -> SetTestInfo)
-> (SetTestInfo, [(GroupIndex, TagUpdate)])
-> EnumMap WhichTest (EnumSet DoPa)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SetTestInfo, [(GroupIndex, TagUpdate)]) -> SetTestInfo
forall a b. (a, b) -> a
fst) [(SetTestInfo, [(GroupIndex, TagUpdate)])]
rest)
where setTI :: EnumSet WhichTest
setTI = EnumMap WhichTest (EnumSet DoPa) -> EnumSet WhichTest
forall key a. Enum key => EnumMap key a -> EnumSet key
Map.keysSet EnumMap WhichTest (EnumSet DoPa)
sti
mergeNullViews :: NullView -> NullView -> NullView
mergeNullViews :: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
mergeNullViews [(SetTestInfo, [(GroupIndex, TagUpdate)])]
s1 [(SetTestInfo, [(GroupIndex, TagUpdate)])]
s2 = [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
cleanNullView ([(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall a b. (a -> b) -> a -> b
$ do
(test1,tag1) <- [(SetTestInfo, [(GroupIndex, TagUpdate)])]
s1
(test2,tag2) <- s2
return (mappend test1 test2,mappend tag1 tag2)
seqTake :: (Int, Maybe Int) -> (Int, Maybe Int) -> (Int, Maybe Int)
seqTake :: (GroupIndex, Maybe GroupIndex)
-> (GroupIndex, Maybe GroupIndex) -> (GroupIndex, Maybe GroupIndex)
seqTake (GroupIndex
x1,Maybe GroupIndex
y1) (GroupIndex
x2,Maybe GroupIndex
y2) = (GroupIndex
x1GroupIndex -> GroupIndex -> GroupIndex
forall a. Num a => a -> a -> a
+GroupIndex
x2,(GroupIndex -> GroupIndex -> GroupIndex)
-> Maybe GroupIndex -> Maybe GroupIndex -> Maybe GroupIndex
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 GroupIndex -> GroupIndex -> GroupIndex
forall a. Num a => a -> a -> a
(+) Maybe GroupIndex
y1 Maybe GroupIndex
y2)
orTakes :: [(Int, Maybe Int)] -> (Int,Maybe Int)
orTakes :: [(GroupIndex, Maybe GroupIndex)] -> (GroupIndex, Maybe GroupIndex)
orTakes [] = (GroupIndex
0,GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just GroupIndex
0)
orTakes [(GroupIndex, Maybe GroupIndex)]
ts = let ([GroupIndex]
xs,[Maybe GroupIndex]
ys) = [(GroupIndex, Maybe GroupIndex)]
-> ([GroupIndex], [Maybe GroupIndex])
forall a b. [(a, b)] -> ([a], [b])
unzip [(GroupIndex, Maybe GroupIndex)]
ts
in ([GroupIndex] -> GroupIndex
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [GroupIndex]
xs, (Maybe GroupIndex -> Maybe GroupIndex -> Maybe GroupIndex)
-> [Maybe GroupIndex] -> Maybe GroupIndex
forall a. (a -> a -> a) -> [a] -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 ((GroupIndex -> GroupIndex -> GroupIndex)
-> Maybe GroupIndex -> Maybe GroupIndex -> Maybe GroupIndex
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 GroupIndex -> GroupIndex -> GroupIndex
forall a. Ord a => a -> a -> a
max) [Maybe GroupIndex]
ys)
apply :: HandleTag -> Maybe Tag
apply :: HandleTag -> Maybe GroupIndex
apply (Apply GroupIndex
tag) = GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just GroupIndex
tag
apply HandleTag
_ = Maybe GroupIndex
forall a. Maybe a
Nothing
toAdvice :: HandleTag -> HandleTag
toAdvice :: HandleTag -> HandleTag
toAdvice (Apply GroupIndex
tag) = GroupIndex -> HandleTag
Advice GroupIndex
tag
toAdvice HandleTag
s = HandleTag
s
noTag :: HandleTag -> Bool
noTag :: HandleTag -> Bool
noTag HandleTag
NoTag = Bool
True
noTag HandleTag
_ = Bool
False
fromHandleTag :: HandleTag -> Tag
fromHandleTag :: HandleTag -> GroupIndex
fromHandleTag (Apply GroupIndex
tag) = GroupIndex
tag
fromHandleTag (Advice GroupIndex
tag) = GroupIndex
tag
fromHandleTag HandleTag
_ = String -> GroupIndex
forall a. HasCallStack => String -> a
error String
"fromHandleTag"
varies :: Q -> Bool
varies :: Q -> Bool
varies Q {takes :: Q -> (GroupIndex, Maybe GroupIndex)
takes = (GroupIndex
_,Maybe GroupIndex
Nothing)} = Bool
True
varies Q {takes :: Q -> (GroupIndex, Maybe GroupIndex)
takes = (GroupIndex
x,Just GroupIndex
y)} = GroupIndex
xGroupIndex -> GroupIndex -> Bool
forall a. Eq a => a -> a -> Bool
/=GroupIndex
y
mustAccept :: Q -> Bool
mustAccept :: Q -> Bool
mustAccept Q
q = (GroupIndex
0GroupIndex -> GroupIndex -> Bool
forall a. Eq a => a -> a -> Bool
/=) (GroupIndex -> Bool) -> (Q -> GroupIndex) -> Q -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GroupIndex, Maybe GroupIndex) -> GroupIndex
forall a b. (a, b) -> a
fst ((GroupIndex, Maybe GroupIndex) -> GroupIndex)
-> (Q -> (GroupIndex, Maybe GroupIndex)) -> Q -> GroupIndex
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q -> (GroupIndex, Maybe GroupIndex)
takes (Q -> Bool) -> Q -> Bool
forall a b. (a -> b) -> a -> b
$ Q
q
canAccept :: Q -> Bool
canAccept :: Q -> Bool
canAccept Q
q = Bool -> (GroupIndex -> Bool) -> Maybe GroupIndex -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True (GroupIndex
0GroupIndex -> GroupIndex -> Bool
forall a. Eq a => a -> a -> Bool
/=) (Maybe GroupIndex -> Bool) -> Maybe GroupIndex -> Bool
forall a b. (a -> b) -> a -> b
$ (GroupIndex, Maybe GroupIndex) -> Maybe GroupIndex
forall a b. (a, b) -> b
snd ((GroupIndex, Maybe GroupIndex) -> Maybe GroupIndex)
-> (Q -> (GroupIndex, Maybe GroupIndex)) -> Q -> Maybe GroupIndex
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q -> (GroupIndex, Maybe GroupIndex)
takes (Q -> Maybe GroupIndex) -> Q -> Maybe GroupIndex
forall a b. (a -> b) -> a -> b
$ Q
q
cannotAccept :: Q -> Bool
cannotAccept :: Q -> Bool
cannotAccept Q
q = Bool -> (GroupIndex -> Bool) -> Maybe GroupIndex -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (GroupIndex
0GroupIndex -> GroupIndex -> Bool
forall a. Eq a => a -> a -> Bool
==) (Maybe GroupIndex -> Bool) -> Maybe GroupIndex -> Bool
forall a b. (a -> b) -> a -> b
$ (GroupIndex, Maybe GroupIndex) -> Maybe GroupIndex
forall a b. (a, b) -> b
snd ((GroupIndex, Maybe GroupIndex) -> Maybe GroupIndex)
-> (Q -> (GroupIndex, Maybe GroupIndex)) -> Q -> Maybe GroupIndex
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q -> (GroupIndex, Maybe GroupIndex)
takes (Q -> Maybe GroupIndex) -> Q -> Maybe GroupIndex
forall a b. (a -> b) -> a -> b
$ Q
q
type PM = RWS (Maybe GroupIndex) [Either Tag GroupInfo] ([OP]->[OP],Tag)
type HHQ = HandleTag
-> HandleTag
-> PM Q
makeGroupArray :: GroupIndex -> [GroupInfo] -> Array GroupIndex [GroupInfo]
makeGroupArray :: GroupIndex -> [GroupInfo] -> Array GroupIndex [GroupInfo]
makeGroupArray GroupIndex
maxGroupIndex [GroupInfo]
groups = ([GroupInfo] -> GroupInfo -> [GroupInfo])
-> [GroupInfo]
-> (GroupIndex, GroupIndex)
-> [(GroupIndex, GroupInfo)]
-> Array GroupIndex [GroupInfo]
forall (a :: * -> * -> *) e i e'.
(IArray a e, Ix i) =>
(e -> e' -> e) -> e -> (i, i) -> [(i, e')] -> a i e
accumArray (\[GroupInfo]
earlier GroupInfo
later -> GroupInfo
laterGroupInfo -> [GroupInfo] -> [GroupInfo]
forall a. a -> [a] -> [a]
:[GroupInfo]
earlier) [] (GroupIndex
1,GroupIndex
maxGroupIndex) [(GroupIndex, GroupInfo)]
filler
where filler :: [(GroupIndex, GroupInfo)]
filler = (GroupInfo -> (GroupIndex, GroupInfo))
-> [GroupInfo] -> [(GroupIndex, GroupInfo)]
forall a b. (a -> b) -> [a] -> [b]
map (\GroupInfo
gi -> (GroupInfo -> GroupIndex
thisIndex GroupInfo
gi,GroupInfo
gi)) [GroupInfo]
groups
patternToQ :: CompOption -> (Pattern,(GroupIndex,DoPa)) -> (Q,Array Tag OP,Array GroupIndex [GroupInfo])
patternToQ :: CompOption
-> (Pattern, (GroupIndex, DoPa))
-> (Q, Array GroupIndex OP, Array GroupIndex [GroupInfo])
patternToQ CompOption
compOpt (Pattern
pOrig,(GroupIndex
maxGroupIndex,DoPa
_)) = (Q
tnfa,Array GroupIndex OP
aTags,Array GroupIndex [GroupInfo]
aGroups) where
(Q
tnfa,([OP] -> [OP]
tag_dlist,GroupIndex
nextTag),[Either GroupIndex GroupInfo]
groups) = RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
-> Maybe GroupIndex
-> ([OP] -> [OP], GroupIndex)
-> (Q, ([OP] -> [OP], GroupIndex), [Either GroupIndex GroupInfo])
forall r w s a. RWS r w s a -> r -> s -> (a, s, w)
runRWS RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
monad Maybe GroupIndex
startReader ([OP] -> [OP], GroupIndex)
startState
aTags :: Array GroupIndex OP
aTags = (GroupIndex, GroupIndex) -> [OP] -> Array GroupIndex OP
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
(i, i) -> [e] -> a i e
listArray (GroupIndex
0,GroupIndex -> GroupIndex
forall a. Enum a => a -> a
pred GroupIndex
nextTag) ([OP] -> [OP]
tag_dlist [])
aGroups :: Array GroupIndex [GroupInfo]
aGroups = GroupIndex -> [GroupInfo] -> Array GroupIndex [GroupInfo]
makeGroupArray GroupIndex
maxGroupIndex ([Either GroupIndex GroupInfo] -> [GroupInfo]
forall a b. [Either a b] -> [b]
rights [Either GroupIndex GroupInfo]
groups)
monad :: RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
monad = Pattern -> HHQ
go (Pattern -> Pattern
starTrans Pattern
pOrig) (GroupIndex -> HandleTag
Advice GroupIndex
0) (GroupIndex -> HandleTag
Advice GroupIndex
1)
startReader :: Maybe GroupIndex
startReader :: Maybe GroupIndex
startReader = GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just GroupIndex
0
startState :: ([OP]->[OP],Tag)
startState :: ([OP] -> [OP], GroupIndex)
startState = ( (OP
MinimizeOP -> [OP] -> [OP]
forall a. a -> [a] -> [a]
:) ([OP] -> [OP]) -> ([OP] -> [OP]) -> [OP] -> [OP]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OP
MaximizeOP -> [OP] -> [OP]
forall a. a -> [a] -> [a]
:) , GroupIndex
2)
{-# INLINE uniq #-}
uniq :: String -> PM HandleTag
uniq :: String -> PM HandleTag
uniq String
_msg = (GroupIndex -> HandleTag)
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
GroupIndex
-> PM HandleTag
forall a b.
(a -> b)
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GroupIndex -> HandleTag
Apply (OP
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
GroupIndex
uniq' OP
Maximize)
ignore :: String -> PM Tag
ignore :: String
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
GroupIndex
ignore String
_msg = OP
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
GroupIndex
uniq' OP
Ignore
{-# NOINLINE uniq' #-}
uniq' :: OP -> PM Tag
uniq' :: OP
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
GroupIndex
uniq' OP
newOp = do
(op,s) <- RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
([OP] -> [OP], GroupIndex)
forall s (m :: * -> *). MonadState s m => m s
get
let op' = [OP] -> [OP]
op ([OP] -> [OP]) -> ([OP] -> [OP]) -> [OP] -> [OP]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OP
newOpOP -> [OP] -> [OP]
forall a. a -> [a] -> [a]
:)
s' = GroupIndex -> GroupIndex
forall a. Enum a => a -> a
succ GroupIndex
s
put $! (op',s')
return s
{-# INLINE makeOrbit #-}
makeOrbit :: PM (Maybe Tag)
makeOrbit :: PM (Maybe GroupIndex)
makeOrbit = do x <- OP
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
GroupIndex
uniq' OP
Orbit
tell [Left x]
return (Just x)
{-# INLINE withOrbit #-}
withOrbit :: PM a -> PM (a,[Tag])
withOrbit :: forall a. PM a -> PM (a, [GroupIndex])
withOrbit = ([Either GroupIndex GroupInfo] -> [GroupIndex])
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex])
forall w (m :: * -> *) b a.
MonadWriter w m =>
(w -> b) -> m a -> m (a, b)
listens (([Either GroupIndex GroupInfo] -> [GroupIndex])
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex]))
-> ([Either GroupIndex GroupInfo] -> [GroupIndex])
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex])
forall a b. (a -> b) -> a -> b
$ ([GroupIndex], [GroupInfo]) -> [GroupIndex]
forall a b. (a, b) -> a
fst (([GroupIndex], [GroupInfo]) -> [GroupIndex])
-> ([Either GroupIndex GroupInfo] -> ([GroupIndex], [GroupInfo]))
-> [Either GroupIndex GroupInfo]
-> [GroupIndex]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Either GroupIndex GroupInfo] -> ([GroupIndex], [GroupInfo])
forall a b. [Either a b] -> ([a], [b])
partitionEithers
{-# INLINE makeGroup #-}
makeGroup :: GroupInfo -> PM ()
makeGroup :: GroupInfo
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
()
makeGroup = [Either GroupIndex GroupInfo]
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell ([Either GroupIndex GroupInfo]
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
())
-> (GroupInfo -> [Either GroupIndex GroupInfo])
-> GroupInfo
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either GroupIndex GroupInfo
-> [Either GroupIndex GroupInfo] -> [Either GroupIndex GroupInfo]
forall a. a -> [a] -> [a]
:[]) (Either GroupIndex GroupInfo -> [Either GroupIndex GroupInfo])
-> (GroupInfo -> Either GroupIndex GroupInfo)
-> GroupInfo
-> [Either GroupIndex GroupInfo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GroupInfo -> Either GroupIndex GroupInfo
forall a b. b -> Either a b
Right
{-# INLINE getParentIndex #-}
getParentIndex :: PM (Maybe GroupIndex)
getParentIndex :: PM (Maybe GroupIndex)
getParentIndex = PM (Maybe GroupIndex)
forall r (m :: * -> *). MonadReader r m => m r
ask
{-# INLINE nonCapture #-}
nonCapture :: PM a -> PM a
nonCapture :: forall a. PM a -> PM a
nonCapture = (Maybe GroupIndex -> Maybe GroupIndex)
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall a.
(Maybe GroupIndex -> Maybe GroupIndex)
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (Maybe GroupIndex -> Maybe GroupIndex -> Maybe GroupIndex
forall a b. a -> b -> a
const Maybe GroupIndex
forall a. Maybe a
Nothing)
withParent :: GroupIndex -> PM a -> PM (a,[Tag])
withParent :: forall a. GroupIndex -> PM a -> PM (a, [GroupIndex])
withParent GroupIndex
this = (Maybe GroupIndex -> Maybe GroupIndex)
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex])
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex])
forall a.
(Maybe GroupIndex -> Maybe GroupIndex)
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (Maybe GroupIndex -> Maybe GroupIndex -> Maybe GroupIndex
forall a b. a -> b -> a
const (GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just GroupIndex
this)) (RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex])
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex]))
-> (RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex]))
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Either GroupIndex GroupInfo] -> [GroupIndex])
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, [GroupIndex])
forall w (m :: * -> *) b a.
MonadWriter w m =>
(w -> b) -> m a -> m (a, b)
listens [Either GroupIndex GroupInfo] -> [GroupIndex]
forall {a}. [Either a GroupInfo] -> [GroupIndex]
childGroupInfo
where childGroupInfo :: [Either a GroupInfo] -> [GroupIndex]
childGroupInfo [Either a GroupInfo]
x =
let gs :: [GroupInfo]
gs = ([a], [GroupInfo]) -> [GroupInfo]
forall a b. (a, b) -> b
snd (([a], [GroupInfo]) -> [GroupInfo])
-> ([a], [GroupInfo]) -> [GroupInfo]
forall a b. (a -> b) -> a -> b
$ [Either a GroupInfo] -> ([a], [GroupInfo])
forall a b. [Either a b] -> ([a], [b])
partitionEithers [Either a GroupInfo]
x
children :: [GroupIndex]
children :: [GroupIndex]
children = [GroupIndex] -> [GroupIndex]
forall a. Eq a => [a] -> [a]
norep ([GroupIndex] -> [GroupIndex])
-> ([GroupInfo] -> [GroupIndex]) -> [GroupInfo] -> [GroupIndex]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GroupIndex] -> [GroupIndex]
forall a. Ord a => [a] -> [a]
sort ([GroupIndex] -> [GroupIndex])
-> ([GroupInfo] -> [GroupIndex]) -> [GroupInfo] -> [GroupIndex]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GroupInfo -> GroupIndex) -> [GroupInfo] -> [GroupIndex]
forall a b. (a -> b) -> [a] -> [b]
map GroupInfo -> GroupIndex
thisIndex
([GroupInfo] -> [GroupIndex])
-> ([GroupInfo] -> [GroupInfo]) -> [GroupInfo] -> [GroupIndex]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GroupInfo -> Bool) -> [GroupInfo] -> [GroupInfo]
forall a. (a -> Bool) -> [a] -> [a]
filter ((GroupIndex
thisGroupIndex -> GroupIndex -> Bool
forall a. Eq a => a -> a -> Bool
==)(GroupIndex -> Bool)
-> (GroupInfo -> GroupIndex) -> GroupInfo -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.GroupInfo -> GroupIndex
parentIndex) ([GroupInfo] -> [GroupIndex]) -> [GroupInfo] -> [GroupIndex]
forall a b. (a -> b) -> a -> b
$ [GroupInfo]
gs
in (GroupIndex -> [GroupIndex]) -> [GroupIndex] -> [GroupIndex]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((GroupInfo -> GroupIndex) -> [GroupInfo] -> [GroupIndex]
forall a b. (a -> b) -> [a] -> [b]
map GroupInfo -> GroupIndex
flagTag ([GroupInfo] -> [GroupIndex])
-> (GroupIndex -> [GroupInfo]) -> GroupIndex -> [GroupIndex]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Array GroupIndex [GroupInfo]
aGroupsArray GroupIndex [GroupInfo] -> GroupIndex -> [GroupInfo]
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
!)) (GroupIndex
thisGroupIndex -> [GroupIndex] -> [GroupIndex]
forall a. a -> [a] -> [a]
:[GroupIndex]
children)
combineConcat :: [Pattern] -> HHQ
combineConcat :: [Pattern] -> HHQ
combineConcat | CompOption -> Bool
rightAssoc CompOption
compOpt = (HHQ -> HHQ -> HHQ) -> [HHQ] -> HHQ
forall a. (a -> a -> a) -> [a] -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 HHQ -> HHQ -> HHQ
combineSeq ([HHQ] -> HHQ) -> ([Pattern] -> [HHQ]) -> [Pattern] -> HHQ
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Pattern -> HHQ) -> [Pattern] -> [HHQ]
forall a b. (a -> b) -> [a] -> [b]
map Pattern -> HHQ
go
| Bool
otherwise = (HHQ -> HHQ -> HHQ) -> [HHQ] -> HHQ
forall a. (a -> a -> a) -> [a] -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 HHQ -> HHQ -> HHQ
combineSeq ([HHQ] -> HHQ) -> ([Pattern] -> [HHQ]) -> [Pattern] -> HHQ
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Pattern -> HHQ) -> [Pattern] -> [HHQ]
forall a b. (a -> b) -> [a] -> [b]
map Pattern -> HHQ
go
where {-# INLINE front'end #-}
front'end :: RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
b
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, b)
front'end | CompOption -> Bool
rightAssoc CompOption
compOpt = (a -> b -> (a, b))
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
b
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, b)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,)
| Bool
otherwise = (RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
b
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, b))
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
b
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, b)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((b -> a -> (a, b))
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
b
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
(a, b)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 ((a -> b -> (a, b)) -> b -> a -> (a, b)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,)))
combineSeq :: HHQ -> HHQ -> HHQ
combineSeq :: HHQ -> HHQ -> HHQ
combineSeq HHQ
pFront HHQ
pEnd = (\ HandleTag
m1 HandleTag
m2 -> mdo
let bothVary = Q -> Bool
varies Q
qFront Bool -> Bool -> Bool
&& Q -> Bool
varies Q
qEnd
a <- if noTag m1 && bothVary then uniq "combineSeq start" else return m1
b <- if noTag m2 && bothVary then uniq "combineSeq stop" else return m2
mid <- case (noTag a,canAccept qFront,noTag b,canAccept qEnd) of
(Bool
False,Bool
False,Bool
_,Bool
_) -> HandleTag -> PM HandleTag
forall a.
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall (m :: * -> *) a. Monad m => a -> m a
return (HandleTag -> HandleTag
toAdvice HandleTag
a)
(Bool
_,Bool
_,Bool
False,Bool
False) -> HandleTag -> PM HandleTag
forall a.
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall (m :: * -> *) a. Monad m => a -> m a
return (HandleTag -> HandleTag
toAdvice HandleTag
b)
(Bool, Bool, Bool, Bool)
_ -> if Q -> Bool
tagged Q
qFront Bool -> Bool -> Bool
|| Q -> Bool
tagged Q
qEnd then String -> PM HandleTag
uniq String
"combineSeq mid" else HandleTag -> PM HandleTag
forall a.
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall (m :: * -> *) a. Monad m => a -> m a
return HandleTag
NoTag
(qFront,qEnd) <- front'end (pFront a mid) (pEnd (toAdvice mid) b)
let wanted = if Wanted
WantsEither Wanted -> Wanted -> Bool
forall a. Eq a => a -> a -> Bool
== Q -> Wanted
wants Q
qEnd then Q -> Wanted
wants Q
qFront else Q -> Wanted
wants Q
qEnd
return $ Q { nullQ = mergeNullViews (nullQ qFront) (nullQ qEnd)
, takes = seqTake (takes qFront) (takes qEnd)
, preReset = [], postSet = [], preTag = Nothing, postTag = Nothing
, tagged = bothVary
, childGroups = childGroups qFront || childGroups qEnd
, wants = wanted
, unQ = Seq qFront qEnd }
)
go :: Pattern -> HHQ
go :: Pattern -> HHQ
go Pattern
pIn HandleTag
m1 HandleTag
m2 =
let die :: b
die = String -> b
forall a. HasCallStack => String -> a
error (String -> b) -> String -> b
forall a b. (a -> b) -> a -> b
$ String
"patternToQ cannot handle "String -> ShowS
forall a. [a] -> [a] -> [a]
++Pattern -> String
forall a. Show a => a -> String
show Pattern
pIn
nil :: RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
nil = Q
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall a.
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall (m :: * -> *) a. Monad m => a -> m a
return (Q
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q)
-> Q
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall a b. (a -> b) -> a -> b
$ Q {nullQ :: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nullQ=HandleTag
-> HandleTag -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
makeEmptyNullView HandleTag
m1 HandleTag
m2
,takes :: (GroupIndex, Maybe GroupIndex)
takes=(GroupIndex
0,GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just GroupIndex
0)
,preReset :: [GroupIndex]
preReset=[],postSet :: [GroupIndex]
postSet=[],preTag :: Maybe GroupIndex
preTag=HandleTag -> Maybe GroupIndex
apply HandleTag
m1,postTag :: Maybe GroupIndex
postTag=HandleTag -> Maybe GroupIndex
apply HandleTag
m2
,tagged :: Bool
tagged=Bool
False,childGroups :: Bool
childGroups=Bool
False,wants :: Wanted
wants=Wanted
WantsEither
,unQ :: P
unQ=P
Empty}
one :: RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
one = Q
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall a.
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall (m :: * -> *) a. Monad m => a -> m a
return (Q
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q)
-> Q
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall a b. (a -> b) -> a -> b
$ Q {nullQ :: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nullQ=[(SetTestInfo, [(GroupIndex, TagUpdate)])]
notNull
,takes :: (GroupIndex, Maybe GroupIndex)
takes=(GroupIndex
1,GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just GroupIndex
1)
,preReset :: [GroupIndex]
preReset=[],postSet :: [GroupIndex]
postSet=[],preTag :: Maybe GroupIndex
preTag=HandleTag -> Maybe GroupIndex
apply HandleTag
m1,postTag :: Maybe GroupIndex
postTag=HandleTag -> Maybe GroupIndex
apply HandleTag
m2
,tagged :: Bool
tagged=Bool
False,childGroups :: Bool
childGroups=Bool
False,wants :: Wanted
wants=Wanted
WantsQNFA
,unQ :: P
unQ = Pattern -> P
OneChar Pattern
pIn}
test :: (WhichTest, DoPa) -> m Q
test (WhichTest, DoPa)
myTest = Q -> m Q
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Q -> m Q) -> Q -> m Q
forall a b. (a -> b) -> a -> b
$ Q {nullQ :: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nullQ=(WhichTest, DoPa)
-> HandleTag
-> HandleTag
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
makeTestNullView (WhichTest, DoPa)
myTest HandleTag
m1 HandleTag
m2
,takes :: (GroupIndex, Maybe GroupIndex)
takes=(GroupIndex
0,GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just GroupIndex
0)
,preReset :: [GroupIndex]
preReset=[],postSet :: [GroupIndex]
postSet=[],preTag :: Maybe GroupIndex
preTag=HandleTag -> Maybe GroupIndex
apply HandleTag
m1,postTag :: Maybe GroupIndex
postTag=HandleTag -> Maybe GroupIndex
apply HandleTag
m2
,tagged :: Bool
tagged=Bool
False,childGroups :: Bool
childGroups=Bool
False,wants :: Wanted
wants=Wanted
WantsQT
,unQ :: P
unQ=(WhichTest, DoPa) -> P
Test (WhichTest, DoPa)
myTest }
xtra :: Bool
xtra = CompOption -> Bool
newSyntax CompOption
compOpt
in case Pattern
pIn of
Pattern
PEmpty -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
nil
POr [] -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
nil
POr [Pattern
branch] -> Pattern -> HHQ
go Pattern
branch HandleTag
m1 HandleTag
m2
POr [Pattern]
branches -> mdo
let needUniqTags = Q -> Bool
childGroups Q
ans
let needTags = Q -> Bool
varies Q
ans Bool -> Bool -> Bool
|| Q -> Bool
childGroups Q
ans
a <- if noTag m1 && needTags then uniq "POr start" else return m1
b <- if noTag m2 && needTags then uniq "POr stop" else return m2
let aAdvice = HandleTag -> HandleTag
toAdvice HandleTag
a
bAdvice = HandleTag -> HandleTag
toAdvice HandleTag
b
newUniq = if Bool
needUniqTags then String -> PM HandleTag
uniq String
"POr branch" else HandleTag -> PM HandleTag
forall a.
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall (m :: * -> *) a. Monad m => a -> m a
return HandleTag
bAdvice
bs <- fmap (++[bAdvice]) $ replicateM (pred $ length branches) newUniq
qs <- forM (zip branches bs) (\(Pattern
branch,HandleTag
bTag) -> (Pattern -> HHQ
go Pattern
branch HandleTag
aAdvice HandleTag
bTag))
let wqs = (Q -> Wanted) -> [Q] -> [Wanted]
forall a b. (a -> b) -> [a] -> [b]
map Q -> Wanted
wants [Q]
qs
wanted = if (Wanted -> Bool) -> [Wanted] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Wanted
WantsBothWanted -> Wanted -> Bool
forall a. Eq a => a -> a -> Bool
==) [Wanted]
wqs then Wanted
WantsBoth
else case ((Wanted -> Bool) -> [Wanted] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Wanted
WantsQNFAWanted -> Wanted -> Bool
forall a. Eq a => a -> a -> Bool
==) [Wanted]
wqs,(Wanted -> Bool) -> [Wanted] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Wanted
WantsQTWanted -> Wanted -> Bool
forall a. Eq a => a -> a -> Bool
==) [Wanted]
wqs) of
(Bool
True,Bool
True) -> Wanted
WantsBoth
(Bool
True,Bool
False) -> Wanted
WantsQNFA
(Bool
False,Bool
True) -> Wanted
WantsQT
(Bool
False,Bool
False) -> Wanted
WantsEither
nullView = [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
cleanNullView ([(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> ([Q] -> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> [Q]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HandleTag
-> HandleTag
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
tagWrapNullView HandleTag
a HandleTag
b ([(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> ([Q] -> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> [Q]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Q -> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> [Q] -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Q -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nullQ ([Q] -> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> [Q] -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall a b. (a -> b) -> a -> b
$ [Q]
qs
let ans = Q { nullQ :: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nullQ = [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nullView
, takes :: (GroupIndex, Maybe GroupIndex)
takes = [(GroupIndex, Maybe GroupIndex)] -> (GroupIndex, Maybe GroupIndex)
orTakes ([(GroupIndex, Maybe GroupIndex)]
-> (GroupIndex, Maybe GroupIndex))
-> ([Q] -> [(GroupIndex, Maybe GroupIndex)])
-> [Q]
-> (GroupIndex, Maybe GroupIndex)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Q -> (GroupIndex, Maybe GroupIndex))
-> [Q] -> [(GroupIndex, Maybe GroupIndex)]
forall a b. (a -> b) -> [a] -> [b]
map Q -> (GroupIndex, Maybe GroupIndex)
takes ([Q] -> (GroupIndex, Maybe GroupIndex))
-> [Q] -> (GroupIndex, Maybe GroupIndex)
forall a b. (a -> b) -> a -> b
$ [Q]
qs
, preReset :: [GroupIndex]
preReset = [], postSet :: [GroupIndex]
postSet = []
, preTag :: Maybe GroupIndex
preTag = HandleTag -> Maybe GroupIndex
apply HandleTag
a, postTag :: Maybe GroupIndex
postTag = HandleTag -> Maybe GroupIndex
apply HandleTag
b
, tagged :: Bool
tagged = Bool
needTags
, childGroups :: Bool
childGroups = (Q -> Bool) -> [Q] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Q -> Bool
childGroups [Q]
qs
, wants :: Wanted
wants = Wanted
wanted
, unQ :: P
unQ = [Q] -> P
Or [Q]
qs }
return ans
PConcat [] -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
nil
PConcat [Pattern]
ps -> [Pattern] -> HHQ
combineConcat [Pattern]
ps HandleTag
m1 HandleTag
m2
PStar Bool
mayFirstBeNull Pattern
p -> mdo
let accepts = Q -> Bool
canAccept Q
q
needsOrbit = Q -> Bool
varies Q
q Bool -> Bool -> Bool
&& Q -> Bool
childGroups Q
q
needsTags = Bool
needsOrbit Bool -> Bool -> Bool
|| Bool
accepts
a <- if noTag m1 && needsTags then uniq "PStar start" else return m1
b <- if noTag m2 && needsTags then uniq "PStar stop" else return m2
mOrbit <- if needsOrbit then makeOrbit else return Nothing
(q,resetOrbitTags) <- withOrbit (go p NoTag (toAdvice b))
let nullView | Bool
mayFirstBeNull = [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
cleanNullView ([(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall a b. (a -> b) -> a -> b
$ [(SetTestInfo, [(GroupIndex, TagUpdate)])]
childViews [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall a. [a] -> [a] -> [a]
++ [(SetTestInfo, [(GroupIndex, TagUpdate)])]
skipView
| Bool
otherwise = [(SetTestInfo, [(GroupIndex, TagUpdate)])]
skipView
where childViews :: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
childViews = HandleTag
-> HandleTag
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
tagWrapNullView HandleTag
a HandleTag
b ([(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> ([(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe GroupIndex
-> [GroupIndex]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
orbitWrapNullView Maybe GroupIndex
mOrbit [GroupIndex]
resetOrbitTags ([(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])])
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
-> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
forall a b. (a -> b) -> a -> b
$ Q -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
nullQ Q
q
skipView :: [(SetTestInfo, [(GroupIndex, TagUpdate)])]
skipView = HandleTag
-> HandleTag -> [(SetTestInfo, [(GroupIndex, TagUpdate)])]
makeEmptyNullView HandleTag
a HandleTag
b
return $ Q { nullQ = nullView
, takes = (0,if accepts then Nothing else (Just 0))
, preReset = [], postSet = []
, preTag = apply a, postTag = apply b
, tagged = needsTags
, childGroups = childGroups q
, wants = WantsQT
, unQ =Star { getOrbit = mOrbit
, resetOrbits = resetOrbitTags
, firstNull = mayFirstBeNull
, unStar = q } }
PCarat DoPa
dopa -> (WhichTest, DoPa)
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {m :: * -> *}. Monad m => (WhichTest, DoPa) -> m Q
test (WhichTest
Test_BOL,DoPa
dopa)
PDollar DoPa
dopa -> (WhichTest, DoPa)
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {m :: * -> *}. Monad m => (WhichTest, DoPa) -> m Q
test (WhichTest
Test_EOL,DoPa
dopa)
PChar {} -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
one
PDot {} -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
one
PAny {} -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
one
PAnyNot {} -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
one
PEscape DoPa
dopa Char
'`' | Bool
xtra -> (WhichTest, DoPa)
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {m :: * -> *}. Monad m => (WhichTest, DoPa) -> m Q
test (WhichTest
Test_BOB,DoPa
dopa)
PEscape DoPa
dopa Char
'\'' | Bool
xtra -> (WhichTest, DoPa)
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {m :: * -> *}. Monad m => (WhichTest, DoPa) -> m Q
test (WhichTest
Test_EOB,DoPa
dopa)
PEscape DoPa
dopa Char
'<' | Bool
xtra -> (WhichTest, DoPa)
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {m :: * -> *}. Monad m => (WhichTest, DoPa) -> m Q
test (WhichTest
Test_BOW,DoPa
dopa)
PEscape DoPa
dopa Char
'>' | Bool
xtra -> (WhichTest, DoPa)
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {m :: * -> *}. Monad m => (WhichTest, DoPa) -> m Q
test (WhichTest
Test_EOW,DoPa
dopa)
PEscape DoPa
dopa Char
'b' | Bool
xtra -> (WhichTest, DoPa)
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {m :: * -> *}. Monad m => (WhichTest, DoPa) -> m Q
test (WhichTest
Test_EdgeWord,DoPa
dopa)
PEscape DoPa
dopa Char
'B' | Bool
xtra -> (WhichTest, DoPa)
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {m :: * -> *}. Monad m => (WhichTest, DoPa) -> m Q
test (WhichTest
Test_NotEdgeWord,DoPa
dopa)
PEscape {} -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
one
PGroup Maybe GroupIndex
Nothing Pattern
p -> Pattern -> HHQ
go Pattern
p HandleTag
m1 HandleTag
m2
PGroup (Just GroupIndex
this) Pattern
p -> do
mParent <- PM (Maybe GroupIndex)
getParentIndex
case mParent of
Maybe GroupIndex
Nothing -> Pattern -> HHQ
go Pattern
p HandleTag
m1 HandleTag
m2
Just GroupIndex
parent -> do
a <- if HandleTag -> Bool
noTag HandleTag
m1 then String -> PM HandleTag
uniq String
"PGroup start" else HandleTag -> PM HandleTag
forall a.
a
-> RWST
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Identity
a
forall (m :: * -> *) a. Monad m => a -> m a
return HandleTag
m1
b <- if noTag m2 then uniq "PGroup stop" else return m2
flag <- ignore "PGroup ignore"
(q,resetGroupTags) <- withParent this (go p a b)
makeGroup (GroupInfo this parent (fromHandleTag a) (fromHandleTag b) flag)
return $ q { nullQ = addGroupResetsToNullView resetGroupTags flag (nullQ q)
, tagged = True
, childGroups = True
, preReset = resetGroupTags `mappend` (preReset q)
, postSet = (postSet q) `mappend` [flag]
}
PNonCapture Pattern
p -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
-> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall a. PM a -> PM a
nonCapture (Pattern -> HHQ
go Pattern
p HandleTag
m1 HandleTag
m2)
PPlus {} -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {b}. b
die
PQuest {} -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {b}. b
die
PBound {} -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {b}. b
die
PNonEmpty {} -> RWS
(Maybe GroupIndex)
[Either GroupIndex GroupInfo]
([OP] -> [OP], GroupIndex)
Q
forall {b}. b
die