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

Safe Haskell | None
Language | Haskell2010

Text.Regex.TDFA.Pattern

Contents

- Internal use
- Internal use, operations to support debugging under `ghci`

Description

This Text.Regex.TDFA.Pattern module provides the `Pattern` data type and its subtypes. This `Pattern` type is used to represent the parsed form of a regular expression.

Synopsis

- data Pattern
  - = PEmpty
  - | PGroup (Maybe GroupIndex) Pattern
  - | POr [Pattern]
  - | PConcat [Pattern]
  - | PQuest Pattern
  - | PPlus Pattern
  - | PStar Bool Pattern
  - | PBound Int (Maybe Int) Pattern
  - | PCarat {
    - getDoPa :: DoPa
    }
  - | PDollar {
    - getDoPa :: DoPa
    }
  - | PDot {
    - getDoPa :: DoPa
    }
  - | PAny {
    - getDoPa :: DoPa
    - getPatternSet :: PatternSet
    }
  - | PAnyNot {
    - getDoPa :: DoPa
    - getPatternSet :: PatternSet
    }
  - | PEscape {
    - getDoPa :: DoPa
    - getPatternChar :: Char
    }
  - | PChar {
    - getDoPa :: DoPa
    - getPatternChar :: Char
    }
  - | PNonCapture Pattern
  - | PNonEmpty Pattern
- data PatternSet = PatternSet (Maybe (Set Char)) (Maybe (Set PatternSetCharacterClass)) (Maybe (Set PatternSetCollatingElement)) (Maybe (Set PatternSetEquivalenceClass))
- newtype PatternSetCharacterClass = PatternSetCharacterClass {
  - unSCC :: String
  }
- newtype PatternSetCollatingElement = PatternSetCollatingElement {
  - unSCE :: String
  }
- newtype PatternSetEquivalenceClass = PatternSetEquivalenceClass {
  - unSEC :: String
  }
- type GroupIndex = Int
- newtype DoPa = DoPa {
  - dopaIndex :: Int
  }
- decodeCharacterClass :: PatternSetCharacterClass -> String
- decodePatternSet :: PatternSet -> Set Char
- showPattern :: Pattern -> String
- starTrans :: Pattern -> Pattern
- starTrans' :: Pattern -> Pattern
- simplify' :: Pattern -> Pattern
- dfsPattern :: (Pattern -> Pattern) -> Pattern -> Pattern

# Documentation

data Pattern #

`Pattern` is the type returned by the regular expression parser `parseRegex`. This is consumed by the Text.Regex.TDFA.CorePattern module and the tender leaves are nibbled by the Text.Regex.TDFA.TNFA module.

The `DoPa` field is the index of the component in the regex string `r`.

Constructors

PEmpty | `()`, matches the empty string.
PGroup (Maybe GroupIndex) Pattern | Group `(r)`. `Nothing` indicates non-matching `PGroup` (never produced by parser `parseRegex`).
POr [Pattern] | Alternative `r|s` (flattened by `starTrans`).
PConcat [Pattern] | Sequence `rs` (flattened by `starTrans`).
PQuest Pattern | Zero or one repetitions `r?` (eliminated by `starTrans`).
PPlus Pattern | One or more repetitions `r+` (eliminated by `starTrans`).
PStar Bool Pattern | Zero or more repetitions `r*`. `True` (default) means may accept the empty string on its first iteration.
PBound Int (Maybe Int) Pattern | Given number or repetitions `r{n}` or `r{n,m}` (eliminated by `starTrans`).
PCarat | `^` matches beginning of input.

Fields

- getDoPa :: DoPa

PDollar | `$` matches end of input.

Fields

- getDoPa :: DoPa

PDot | `.` matches any character.

Fields

- getDoPa :: DoPa

PAny | Bracket expression `[...]`.

Fields

- getDoPa :: DoPa
- getPatternSet :: PatternSet

PAnyNot | Inverted bracket expression `[^...]`.

Fields

- getDoPa :: DoPa
- getPatternSet :: PatternSet

PEscape | Backslashed character `c`, may have special meaning.

Fields

- getDoPa :: DoPa
- getPatternChar :: Char

PChar | Single character, matches given character.

Fields

- getDoPa :: DoPa
- getPatternChar :: Char

PNonCapture Pattern | Tag for internal use, introduced by `starTrans`.
PNonEmpty Pattern | Tag for internal use, introduced by `starTrans`.

#### Instances

Instances details

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

data PatternSet #

Content of a bracket expression `[...]` organized into characters, POSIX character classes (e.g. `[[:alnum:]]`), collating elements (e.g. `[.ch.]`, unused), and equivalence classes (e.g. `[=a=]`, treated as characters).

Constructors

PatternSet (Maybe (Set Char)) (Maybe (Set PatternSetCharacterClass)) (Maybe (Set PatternSetCollatingElement)) (Maybe (Set PatternSetEquivalenceClass)) |

#### Instances

Instances details

Show PatternSet # | Hand-rolled implementation, giving textual rather than Haskell representation.
Instance details Defined in Text.Regex.TDFA.Pattern Methods showsPrec :: Int -> PatternSet -> ShowS # show :: PatternSet -> String # showList :: [PatternSet] -> ShowS #
Eq PatternSet # |
Instance details Defined in Text.Regex.TDFA.Pattern Methods (==) :: PatternSet -> PatternSet -> Bool # (/=) :: PatternSet -> PatternSet -> Bool #

newtype PatternSetCharacterClass #

Content of `[: :]`, e.g. `"alnum"` for `[:alnum:]`.

Constructors

PatternSetCharacterClass |

Fields

- unSCC :: String

#### Instances

Instances details

Show PatternSetCharacterClass # | Hand-rolled implementation, giving textual rather than Haskell representation.
Instance details Defined in Text.Regex.TDFA.Pattern Methods showsPrec :: Int -> PatternSetCharacterClass -> ShowS # show :: PatternSetCharacterClass -> String # showList :: [PatternSetCharacterClass] -> ShowS #
Eq PatternSetCharacterClass # |
Instance details Defined in Text.Regex.TDFA.Pattern Methods (==) :: PatternSetCharacterClass -> PatternSetCharacterClass -> Bool # (/=) :: PatternSetCharacterClass -> PatternSetCharacterClass -> Bool #
Ord PatternSetCharacterClass # |

Instance details

Defined in Text.Regex.TDFA.Pattern

Methods

compare :: PatternSetCharacterClass -> PatternSetCharacterClass -> Ordering #

(<) :: PatternSetCharacterClass -> PatternSetCharacterClass -> Bool #

(<=) :: PatternSetCharacterClass -> PatternSetCharacterClass -> Bool #

(>) :: PatternSetCharacterClass -> PatternSetCharacterClass -> Bool #

(>=) :: PatternSetCharacterClass -> PatternSetCharacterClass -> Bool #

max :: PatternSetCharacterClass -> PatternSetCharacterClass -> PatternSetCharacterClass #

min :: PatternSetCharacterClass -> PatternSetCharacterClass -> PatternSetCharacterClass #

newtype PatternSetCollatingElement #

Content of `[. .]`, e.g. `"ch"` for `[.ch.]`.

Constructors

PatternSetCollatingElement |

Fields

- unSCE :: String

#### Instances

Instances details

Show PatternSetCollatingElement # | Hand-rolled implementation, giving textual rather than Haskell representation.
Instance details Defined in Text.Regex.TDFA.Pattern Methods showsPrec :: Int -> PatternSetCollatingElement -> ShowS # show :: PatternSetCollatingElement -> String # showList :: [PatternSetCollatingElement] -> ShowS #
Eq PatternSetCollatingElement # |
Instance details Defined in Text.Regex.TDFA.Pattern Methods (==) :: PatternSetCollatingElement -> PatternSetCollatingElement -> Bool # (/=) :: PatternSetCollatingElement -> PatternSetCollatingElement -> Bool #
Ord PatternSetCollatingElement # |

Instance details

Defined in Text.Regex.TDFA.Pattern

Methods

compare :: PatternSetCollatingElement -> PatternSetCollatingElement -> Ordering #

(<) :: PatternSetCollatingElement -> PatternSetCollatingElement -> Bool #

(<=) :: PatternSetCollatingElement -> PatternSetCollatingElement -> Bool #

(>) :: PatternSetCollatingElement -> PatternSetCollatingElement -> Bool #

(>=) :: PatternSetCollatingElement -> PatternSetCollatingElement -> Bool #

max :: PatternSetCollatingElement -> PatternSetCollatingElement -> PatternSetCollatingElement #

min :: PatternSetCollatingElement -> PatternSetCollatingElement -> PatternSetCollatingElement #

newtype PatternSetEquivalenceClass #

Content of `[= =]`, e.g. `"a"` for `[=a=]`.

Constructors

PatternSetEquivalenceClass |

Fields

- unSEC :: String

#### Instances

Instances details

Show PatternSetEquivalenceClass # | Hand-rolled implementation, giving textual rather than Haskell representation.
Instance details Defined in Text.Regex.TDFA.Pattern Methods showsPrec :: Int -> PatternSetEquivalenceClass -> ShowS # show :: PatternSetEquivalenceClass -> String # showList :: [PatternSetEquivalenceClass] -> ShowS #
Eq PatternSetEquivalenceClass # |
Instance details Defined in Text.Regex.TDFA.Pattern Methods (==) :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Bool # (/=) :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Bool #
Ord PatternSetEquivalenceClass # |

Instance details

Defined in Text.Regex.TDFA.Pattern

Methods

compare :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Ordering #

(<) :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Bool #

(<=) :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Bool #

(>) :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Bool #

(>=) :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Bool #

max :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> PatternSetEquivalenceClass #

min :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> PatternSetEquivalenceClass #

type GroupIndex = Int #

`GroupIndex` is for indexing submatches from capturing parenthesized groups (`PGroup` or `Group`).

newtype DoPa #

Used to track elements of the pattern that accept characters or are anchors.

Constructors

DoPa |

Fields

- dopaIndex :: Int

#### Instances

Instances details

Enum DoPa # |
Instance details Defined in Text.Regex.TDFA.Common Methods succ :: DoPa -> DoPa # pred :: DoPa -> DoPa # toEnum :: Int -> DoPa # fromEnum :: DoPa -> Int # enumFrom :: DoPa -> [DoPa] # enumFromThen :: DoPa -> DoPa -> [DoPa] # enumFromTo :: DoPa -> DoPa -> [DoPa] # enumFromThenTo :: DoPa -> DoPa -> DoPa -> [DoPa] #
Show DoPa # |
Instance details Defined in Text.Regex.TDFA.Common Methods showsPrec :: Int -> DoPa -> ShowS # show :: DoPa -> String # showList :: [DoPa] -> ShowS #
Eq DoPa # |
Instance details Defined in Text.Regex.TDFA.Common Methods (==) :: DoPa -> DoPa -> Bool # (/=) :: DoPa -> DoPa -> Bool #
Ord DoPa # |
Instance details Defined in Text.Regex.TDFA.Common Methods compare :: DoPa -> DoPa -> Ordering # (<) :: DoPa -> DoPa -> Bool # (<=) :: DoPa -> DoPa -> Bool # (>) :: DoPa -> DoPa -> Bool # (>=) :: DoPa -> DoPa -> Bool # max :: DoPa -> DoPa -> DoPa # min :: DoPa -> DoPa -> DoPa #

decodeCharacterClass :: PatternSetCharacterClass -> String #

This returns the strictly ascending list of characters represented by `[: :]` POSIX character classes. Unrecognized class names return an empty string.

Since: 1.3.2

decodePatternSet :: PatternSet -> Set Char #

`decodePatternSet` cannot handle collating element and treats equivalence classes as just their definition and nothing more.

Since: 1.3.2

showPattern :: Pattern -> String #

## Internal use

starTrans :: Pattern -> Pattern #

Do the transformation and simplification in a single traversal. This removes the `PPlus`, `PQuest`, and `PBound` values, changing to `POr` and `PEmpty` and `PStar`. For some `PBound` values it adds `PNonEmpty` and `PNonCapture` semantic marker. It also simplifies to flatten out nested `POr` and `PConcat` instances and eliminate some unneeded `PEmpty` values.

## Internal use, operations to support debugging under `ghci`

starTrans' :: Pattern -> Pattern #

simplify' :: Pattern -> Pattern #

Function to transform a pattern into an equivalent, but less redundant form. Nested `POr` and `PConcat` are flattened. `PEmpty` is propagated.

dfsPattern #

Arguments

:: (Pattern -> Pattern) | The transformation function.
-> Pattern | The `Pattern` to transform.
-> Pattern | The transformed `Pattern`.

Apply a `Pattern` transformation function depth first.