| Copyright | (C) 2026 - Eitan Chatav |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Eitan Chatav <eitan.chatav@gmail.com> |
| Stability | provisional |
| Portability | non-portable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Control.Lens.Grammar.Kleene
Contents
Description
Regular expressions form a Kleene star algebra. See Kleene, Representation of Events in Nerve Nets and Finite Automata
Synopsis
- class Monoid k => KleeneStarAlgebra k where
- orK :: (Foldable f, KleeneStarAlgebra k) => f k -> k
- anyK :: (Foldable f, KleeneStarAlgebra k) => (a -> k) -> f a -> k
- data RegEx token
- = Terminal [token]
- | NonTerminal String
- | Sequence (RegEx token) (RegEx token)
- | KleeneStar (RegEx token)
- | KleeneOpt (RegEx token)
- | KleenePlus (RegEx token)
- | RegExam (RegExam token (RegEx token))
- data RegExam token alg
- data CategoryTest token
- = AsIn (Categorize token)
- | NotAsIn (Set (Categorize token))
KleeneStarAlgebra
class Monoid k => KleeneStarAlgebra k where Source #
A KleeneStarAlgebra is a ring
with a generally non-commutaive multiplication,
the Monoid concatenation operator <> with identity mempty;
and an idempotent addition, the alternation operator >|<
with identity zeroK.
It has three unary operators optK, plusK and the eponymous starK.
starK x = optK (plusK x)
plusK x = x <> starK x
optK x = mempty >|< x
Minimal complete definition
Nothing
Methods
(>|<) :: k -> k -> k infixl 3 Source #
default (>|<) :: (k ~ f a, Alternative f) => k -> k -> k Source #
default zeroK :: (k ~ f a, Alternative f) => k Source #
Instances
| KleeneStarAlgebra RegBnf Source # | |
| KleeneStarAlgebra RegString Source # | |
| (Ord rule, KleeneStarAlgebra rule) => KleeneStarAlgebra (Bnf rule) Source # | |
| Categorized token => KleeneStarAlgebra (RegEx token) Source # | |
| (Alternative f, Monoid k) => KleeneStarAlgebra (Ap f k) Source # | |
orK :: (Foldable f, KleeneStarAlgebra k) => f k -> k Source #
cumulative alternation
anyK :: (Foldable f, KleeneStarAlgebra k) => (a -> k) -> f a -> k Source #
universal
RegEx
The RegExpression type is the prototypical KleeneStarAlgebra.
Constructors
| Terminal [token] | |
| NonTerminal String | |
| Sequence (RegEx token) (RegEx token) | |
| KleeneStar (RegEx token) | |
| KleeneOpt (RegEx token) | |
| KleenePlus (RegEx token) | |
| RegExam (RegExam token (RegEx token)) |
Instances
data RegExam token alg Source #
A component of both RegExpressions
and TokenTests, so that the latter can
be embedded in the former with tokenClass.
Instances
data CategoryTest token Source #
CategoryTests for Categorized tokens.
Constructors
| AsIn (Categorize token) | |
| NotAsIn (Set (Categorize token)) |