regex-tdfa-1.3.2.5: Pure Haskell Tagged DFA Backend for "Text.Regex" (regex-base)

Safe Haskell | None
Language | Haskell2010

Text.Regex.TDFA.CorePattern

Description

The CorePattern module deconstructs the Pattern tree created by ReadRegex.parseRegex and returns a simpler Q/P tree with annotations at each Q node. This will be converted by the TNFA module into a QNFA finite automata.

Of particular note, this Pattern to Q/P conversion creates and assigns all the internal Tags that will be used during the matching process, and associates the captures groups with the tags that represent their starting and ending locations and with their immediate parent group.

Each Maximize and Minimize tag is held as either a preTag or a postTag by one and only one location in the Q/P tree. The Orbit tags are each held by one and only one Star node. Tags that stop a Group are also held in perhaps numerous preReset lists.

The additional nullQ::nullView field of Q records the potentially complex information about what tests and tags must be used if the pattern unQ::P matches 0 zero characters. There can be redundancy in nullView, which is eliminated by cleanNullView.

Uses recursive do notation.

2009 XXX TODO: we can avoid needing tags in the part of the pattern after the last capturing group (when right-associative). This is flipped for left-associative where the front of the pattern before the first capturing group needs no tags. The edge of these regions is subtle: both case needs a Maximize tag. One ought to be able to check the Pattern: if the root is PConcat then a scan from the end (start) looking for the first with an embedded PGroup can be found and the PGroup free elements can be wrapped in some new PNOTAG semantic indicator.

Synopsis

- data Q = Q {
  - nullQ :: NullView
  - takes :: (Position, Maybe Position)
  - preReset :: [Tag]
  - postSet :: [Tag]
  - preTag :: Maybe Tag
  - postTag :: Maybe Tag
  - tagged :: Bool
  - childGroups :: Bool
  - wants :: Wanted
  - unQ :: P
  }
- data P
  - = Empty
  - | Or [Q]
  - | Seq Q Q
  - | Star {
    - getOrbit :: Maybe Tag
    - resetOrbits :: [Tag]
    - firstNull :: Bool
    - unStar :: Q
    }
  - | Test TestInfo
  - | OneChar Pattern
  - | NonEmpty Q
- data WhichTest
  - = Test_BOL
  - | Test_EOL
  - | Test_BOB
  - | Test_EOB
  - | Test_BOW
  - | Test_EOW
  - | Test_EdgeWord
  - | Test_NotEdgeWord
- data Wanted
  - = WantsQNFA
  - | WantsQT
  - | WantsBoth
  - | WantsEither
- type TestInfo = (WhichTest, DoPa)
- data OP
  - = Maximize
  - | Minimize
  - | Orbit
  - | Ignore
- newtype SetTestInfo = SetTestInfo {
  - getTests :: EnumMap WhichTest (EnumSet DoPa)
  }
- type NullView = [(SetTestInfo, TagList)]
- patternToQ :: CompOption -> (Pattern, (GroupIndex, DoPa)) -> (Q, Array Tag OP, Array GroupIndex [GroupInfo])
- cleanNullView :: NullView -> NullView
- cannotAccept :: Q -> Bool
- mustAccept :: Q -> Bool

# Documentation

data Q Source #

Constructors

Q |

Fields

- nullQ :: NullView
- takes :: (Position, Maybe Position)
- preReset :: [Tag]
- postSet :: [Tag]
- preTag :: Maybe Tag
- postTag :: Maybe Tag
- tagged :: Bool
- childGroups :: Bool
- wants :: Wanted
- unQ :: P

#### Instances

Instances details

Show Q Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods showsPrec :: Int -> Q -> ShowS Source # show :: Q -> String Source # showList :: [Q] -> ShowS Source #
Eq Q Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods (==) :: Q -> Q -> Bool Source # (/=) :: Q -> Q -> Bool Source #

data P Source #

Constructors

Empty |
Or [Q] |
Seq Q Q |
Star |

Fields

- getOrbit :: Maybe Tag
- resetOrbits :: [Tag]
- firstNull :: Bool
- unStar :: Q

Test TestInfo |
OneChar Pattern |
NonEmpty Q |

#### Instances

Instances details

Show P Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods showsPrec :: Int -> P -> ShowS Source # show :: P -> String Source # showList :: [P] -> ShowS Source #
Eq P Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods (==) :: P -> P -> Bool Source # (/=) :: P -> P -> Bool Source #

data WhichTest Source #

Known predicates, just Beginning of Line (^) and End of Line ($). Also support for GNU extensions is being added: \` beginning of buffer, \' end of buffer, \< and \> for begin and end of words, \b and \B for word boundary and not word boundary.

Constructors

Test_BOL | `^` (affected by multiline option)
Test_EOL | `$` (affected by multiline option)
Test_BOB | `\`` beginning of buffer
Test_EOB | `\'` end ofbuffer
Test_BOW | `\<` beginning of word
Test_EOW | `\>` end of word
Test_EdgeWord | `\b` word boundary
Test_NotEdgeWord | `\B` not word boundary

#### Instances

Instances details

Enum WhichTest Source # |

Instance details

Defined in Text.Regex.TDFA.Common

Methods

succ :: WhichTest -> WhichTest Source #

pred :: WhichTest -> WhichTest Source #

toEnum :: Int -> WhichTest Source #

fromEnum :: WhichTest -> Int Source #

enumFrom :: WhichTest -> [WhichTest] Source #

enumFromThen :: WhichTest -> WhichTest -> [WhichTest] Source #

enumFromTo :: WhichTest -> WhichTest -> [WhichTest] Source #

enumFromThenTo :: WhichTest -> WhichTest -> WhichTest -> [WhichTest] Source #

Show WhichTest Source # |
Instance details Defined in Text.Regex.TDFA.Common Methods showsPrec :: Int -> WhichTest -> ShowS Source # show :: WhichTest -> String Source # showList :: [WhichTest] -> ShowS Source #
Eq WhichTest Source # |
Instance details Defined in Text.Regex.TDFA.Common Methods (==) :: WhichTest -> WhichTest -> Bool Source # (/=) :: WhichTest -> WhichTest -> Bool Source #
Ord WhichTest Source # |

Instance details

Defined in Text.Regex.TDFA.Common

Methods

compare :: WhichTest -> WhichTest -> Ordering Source #

(<) :: WhichTest -> WhichTest -> Bool Source #

(<=) :: WhichTest -> WhichTest -> Bool Source #

(>) :: WhichTest -> WhichTest -> Bool Source #

(>=) :: WhichTest -> WhichTest -> Bool Source #

max :: WhichTest -> WhichTest -> WhichTest Source #

min :: WhichTest -> WhichTest -> WhichTest Source #

data Wanted Source #

Constructors

WantsQNFA |
WantsQT |
WantsBoth |
WantsEither |

#### Instances

Instances details

Show Wanted Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods showsPrec :: Int -> Wanted -> ShowS Source # show :: Wanted -> String Source # showList :: [Wanted] -> ShowS Source #
Eq Wanted Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods (==) :: Wanted -> Wanted -> Bool Source # (/=) :: Wanted -> Wanted -> Bool Source #

type TestInfo = (WhichTest, DoPa) Source #

data OP Source #

Internal use to indicate type of tag and preference for larger or smaller `Position`s.

Constructors

Maximize |
Minimize |
Orbit |
Ignore |

#### Instances

Instances details

Show OP Source # |
Instance details Defined in Text.Regex.TDFA.Common Methods showsPrec :: Int -> OP -> ShowS Source # show :: OP -> String Source # showList :: [OP] -> ShowS Source #
Eq OP Source # |
Instance details Defined in Text.Regex.TDFA.Common Methods (==) :: OP -> OP -> Bool Source # (/=) :: OP -> OP -> Bool Source #

newtype SetTestInfo Source #

Constructors

SetTestInfo |

Fields

- getTests :: EnumMap WhichTest (EnumSet DoPa)

#### Instances

Instances details

Monoid SetTestInfo Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods mempty :: SetTestInfo Source # mappend :: SetTestInfo -> SetTestInfo -> SetTestInfo Source # mconcat :: [SetTestInfo] -> SetTestInfo Source #
Semigroup SetTestInfo Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods (<>) :: SetTestInfo -> SetTestInfo -> SetTestInfo Source # sconcat :: NonEmpty SetTestInfo -> SetTestInfo Source # stimes :: Integral b => b -> SetTestInfo -> SetTestInfo Source #
Show SetTestInfo Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods showsPrec :: Int -> SetTestInfo -> ShowS Source # show :: SetTestInfo -> String Source # showList :: [SetTestInfo] -> ShowS Source #
Eq SetTestInfo Source # |
Instance details Defined in Text.Regex.TDFA.CorePattern Methods (==) :: SetTestInfo -> SetTestInfo -> Bool Source # (/=) :: SetTestInfo -> SetTestInfo -> Bool Source #

type NullView = [(SetTestInfo, TagList)] Source #

patternToQ :: CompOption -> (Pattern, (GroupIndex, DoPa)) -> (Q, Array Tag OP, Array GroupIndex [GroupInfo]) Source #

cleanNullView :: NullView -> NullView Source #

cannotAccept :: Q -> Bool Source #

mustAccept :: Q -> Bool Source #