regex-tdfa-1.2.1: Replaces/Enhances Text.Regex

Safe Haskell | None
Language | Haskell98

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
  }
- 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. This is consumed by the CorePattern module and the tender leaves are nibbled by the TNFA module.

Constructors

PEmpty |
PGroup (Maybe GroupIndex) Pattern |
POr [Pattern] |
PConcat [Pattern] |
PQuest Pattern |
PPlus Pattern |
PStar Bool Pattern |
PBound Int (Maybe Int) Pattern |
PCarat |
Fields getDoPa :: DoPa
PDollar |
Fields getDoPa :: DoPa
PDot |
Fields getDoPa :: DoPa
PAny |
Fields getDoPa :: DoPa getPatternSet :: PatternSet
PAnyNot |
Fields getDoPa :: DoPa getPatternSet :: PatternSet
PEscape |
Fields getDoPa :: DoPa getPatternChar :: Char
PChar |
Fields getDoPa :: DoPa getPatternChar :: Char
PNonCapture Pattern |
PNonEmpty Pattern |

Instances

Eq Pattern # |
Methods (==) :: Pattern -> Pattern -> Bool # (/=) :: Pattern -> Pattern -> Bool #
Show Pattern # |
Methods showsPrec :: Int -> Pattern -> ShowS # show :: Pattern -> String # showList :: [Pattern] -> ShowS #

data PatternSet #

Constructors

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

Instances

Eq PatternSet # |
Methods (==) :: PatternSet -> PatternSet -> Bool # (/=) :: PatternSet -> PatternSet -> Bool #
Show PatternSet # |
Methods showsPrec :: Int -> PatternSet -> ShowS # show :: PatternSet -> String # showList :: [PatternSet] -> ShowS #

newtype PatternSetCharacterClass #

Constructors

PatternSetCharacterClass |
Fields unSCC :: String

Instances

Eq PatternSetCharacterClass # |
Methods (==) :: PatternSetCharacterClass -> PatternSetCharacterClass -> Bool # (/=) :: PatternSetCharacterClass -> PatternSetCharacterClass -> Bool #
Ord PatternSetCharacterClass # |
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 #
Show PatternSetCharacterClass # |
Methods showsPrec :: Int -> PatternSetCharacterClass -> ShowS # show :: PatternSetCharacterClass -> String # showList :: [PatternSetCharacterClass] -> ShowS #

newtype PatternSetCollatingElement #

Constructors

PatternSetCollatingElement |
Fields unSCE :: String

Instances

Eq PatternSetCollatingElement # |
Methods (==) :: PatternSetCollatingElement -> PatternSetCollatingElement -> Bool # (/=) :: PatternSetCollatingElement -> PatternSetCollatingElement -> Bool #
Ord PatternSetCollatingElement # |
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 #
Show PatternSetCollatingElement # |
Methods showsPrec :: Int -> PatternSetCollatingElement -> ShowS # show :: PatternSetCollatingElement -> String # showList :: [PatternSetCollatingElement] -> ShowS #

newtype PatternSetEquivalenceClass #

Constructors

PatternSetEquivalenceClass |
Fields unSEC :: String

Instances

Eq PatternSetEquivalenceClass # |
Methods (==) :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Bool # (/=) :: PatternSetEquivalenceClass -> PatternSetEquivalenceClass -> Bool #
Ord PatternSetEquivalenceClass # |
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 #
Show PatternSetEquivalenceClass # |
Methods showsPrec :: Int -> PatternSetEquivalenceClass -> ShowS # show :: PatternSetEquivalenceClass -> String # showList :: [PatternSetEquivalenceClass] -> ShowS #

type GroupIndex = Int #

GroupIndex is for indexing submatches from capturing parenthesized groups (PGroup/Group)

newtype DoPa #

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

Constructors

DoPa |
Fields dopaIndex :: Int

Instances

Enum DoPa # |
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] #
Eq DoPa # |
Methods (==) :: DoPa -> DoPa -> Bool # (/=) :: DoPa -> DoPa -> Bool #
Ord DoPa # |
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 #
Show DoPa # |
Methods showsPrec :: Int -> DoPa -> ShowS # show :: DoPa -> String # showList :: [DoPa] -> ShowS #

showPattern :: Pattern -> String #

I have not been checking, but this should have the property that parsing the resulting string should result in an identical Pattern. This is not true if starTrans has created PNonCapture and PNonEmpty values or a (PStar False). The contents of a "[ ]" grouping are always shown in a sorted canonical order.

## 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 True/False. 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 transfomation function depth first