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