regex-tdfa-1.3.2.5: 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 Source #

`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 Source # |
Instance details Defined in Text.Regex.TDFA.Pattern Methods showsPrec :: Int -> Pattern -> ShowS Source # show :: Pattern -> String Source # showList :: [Pattern] -> ShowS Source #
Eq Pattern Source # |
Instance details Defined in Text.Regex.TDFA.Pattern Methods (==) :: Pattern -> Pattern -> Bool Source # (/=) :: Pattern -> Pattern -> Bool Source #

data PatternSet Source #

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

newtype PatternSetCharacterClass Source #

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

Constructors

PatternSetCharacterClass |

Fields

- unSCC :: String

#### Instances

Instances details

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

Instance details

Defined in Text.Regex.TDFA.Pattern

Methods

compare :: PatternSetCharacterClass -> PatternSetCharacterClass -> Ordering Source #

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

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

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

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

max :: PatternSetCharacterClass -> PatternSetCharacterClass -> PatternSetCharacterClass Source #

min :: PatternSetCharacterClass -> PatternSetCharacterClass -> PatternSetCharacterClass Source #

newtype PatternSetCollatingElement Source #

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

Constructors

PatternSetCollatingElement |

Fields

- unSCE :: String

#### Instances

Instances details

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

Instance details

Defined in Text.Regex.TDFA.Pattern

Methods

compare :: PatternSetCollatingElement -> PatternSetCollatingElement -> Ordering Source #

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

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

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

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

max :: PatternSetCollatingElement -> PatternSetCollatingElement -> PatternSetCollatingElement Source #

min :: PatternSetCollatingElement -> PatternSetCollatingElement -> PatternSetCollatingElement Source #

newtype PatternSetEquivalenceClass Source #

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

Constructors

PatternSetEquivalenceClass |

Fields

- unSEC :: String

#### Instances

Instances details

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

Instance details

Defined in Text.Regex.TDFA.Pattern

Methods

compare :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Ordering Source #

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

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

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

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

max :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> PatternSetEquivalenceClass Source #

min :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> PatternSetEquivalenceClass Source #

type GroupIndex = Int Source #

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

newtype DoPa Source #

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

Constructors

DoPa |

Fields

- dopaIndex :: Int

#### Instances

Instances details

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

decodeCharacterClass :: PatternSetCharacterClass -> String Source #

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 Source #

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

Since: 1.3.2

showPattern :: Pattern -> String Source #

## Internal use

starTrans :: Pattern -> Pattern Source #

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 Source #

simplify' :: Pattern -> Pattern Source #

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

dfsPattern Source #

Arguments

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

Apply a `Pattern` transformation function depth first.