data CharSet = CharSet Bool (List (Int, Int)) (List Int) (List Int) deriving (Eq, Show)
import Data.RegexData.Regex — moteur à dérivées de Brzozowski
Synopsis
data CharSet = CharSet Bool (List (Int, Int)) (List Int) (List Int) deriving (Eq, Show)matches : Regex -> String -> Booldata RegexError = RegexError String Nat deriving (Eq, Show)data PP = PP (List Char) Natcompile : String -> Result RegexError Regexdata RxFlags = RxFlags Bool Bool Booldata Bit = Zero | One deriving (Eq)data Adata V = VEmpty | VChr | VLeft V | VRight V | VSeq V V | VStars (List V) | VGroup Int Vdata Match = Match Nat Nat (List (Maybe (Nat, Nat))) (List (String, Int))matchStart : Match -> NatmatchEnd : Match -> Natgroup : Match -> Nat -> Maybe (Nat, Nat)groupName : Match -> String -> Maybe (Nat, Nat)fullmatch : Regex -> String -> Maybe Matchsearch : Regex -> String -> Maybe MatchfindAll : Regex -> String -> List Matchsplit : Regex -> String -> List Stringreplace : Regex -> String -> String -> String
matches : Regex -> String -> Bool
matches r s : la regex matche-t-elle TOUTE l'entrée ? O(n), PILE CONSTANTE.
data RegexError = RegexError String Nat deriving (Eq, Show)
data PP = PP (List Char) Nat
compile : String -> Result RegexError Regex
Compile un motif en Regex. Drapeaux : préfixe GLOBAL (?flags) et SCOPÉ (?flags:…). v1 : i (casse ASCII, foldée à la compilation), s (dotall : . matche \n), u (classes Unicode, cf. plus bas). m (multi-ligne) = à venir (nécessite les ancres ^/$).
data RxFlags = RxFlags Bool Bool Bool
data Bit = Zero | One deriving (Eq)
data A
= AZero
| AOne (List Bit)
| AChar (List Bit) CharSet
| AAlt (List Bit) (List A)
| ASeq (List Bit) A A
| AStar (List Bit) A
| AGroup (List Bit) Int A
| ARep (List Bit) Int (Maybe Int) A
AZeroAOneACharAAltASeqAStarAGroupARep
data V = VEmpty | VChr | VLeft V | VRight V | VSeq V V | VStars (List V) | VGroup Int V
deriving (Eq)
data Match = Match Nat Nat (List (Maybe (Nat, Nat))) (List (String, Int))
deriving (Eq, Show)
Un match : début, fin (positions 0-basées), une étendue par groupe capturant (1-basé ; Nothing = groupe non apparié), et la table nom→index des groupes nommés ((?<name>…)). group … 0 = match entier. Le Match reste POSITIONNEL (le nom est une métadonnée ; les positions POSIX sont inchangées).
matchStart : Match -> Nat
matchEnd : Match -> Nat
group : Match -> Nat -> Maybe (Nat, Nat)
Étendue d'un groupe (1-basé) ; group m 0 = le match entier.
groupName : Match -> String -> Maybe (Nat, Nat)
Étendue d'un groupe NOMMÉ ((?<name>…)) ; Nothing si le nom est inconnu.
fullmatch : Regex -> String -> Maybe Match
Match ANCRÉ : la regex doit couvrir TOUTE l'entrée.
search : Regex -> String -> Maybe Match
RECHERCHE POSIX leftmost-longest : 1er début qui matche, plus long à ce début.
findAll : Regex -> String -> List Match
Tous les matches NON CHEVAUCHANTS, de gauche à droite (avance d'≥1 sur un match vide pour garantir la terminaison).
split : Regex -> String -> List String
Découpe l'entrée aux occurrences de r (les séparateurs), en Strings.
replace : Regex -> String -> String -> String
Remplace chaque match par le gabarit repl ($1.. = groupes, $0 = match entier, $$ = '$' littéral, $k non-apparié → "").