| 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 | None |
| Language | Haskell2010 |
Control.Lens.Grammar.Class
Contents
Description
The classes of types' grammars, over their tokens, regular, context-free
& context-sensitive, & numerals, by their digits. Haskell types' grammars,
equivalent to their Read & Show instances, are in
Control.Lens.Grammar.Prec.
Synopsis
- class Grammar token a => RegGrammar token a where
- regGrammar :: RegGrammatical token p => p a a
- class CtxGrammar token a => Grammar token a where
- grammar :: Grammatical token p => p a a
- class CtxGrammar token a where
- ctxGrammar :: CtxGrammatical token p => p a a
- digit :: (Integral n, Choice p, Tokenized Char (p Char Char)) => n -> p n n
- numeral :: (Integral n, Alternator p, Tokenized Char (p Char Char)) => n -> p n n
Documentation
class Grammar token a => RegGrammar token a where Source #
A type's regular grammar, over its tokens, which is also its context-free & context-sensitive grammar.
Methods
regGrammar :: RegGrammatical token p => p a a Source #
class CtxGrammar token a => Grammar token a where Source #
A type's context-free grammar, over its tokens, which is also its context-sensitive grammar; its regular grammar, by default.
Minimal complete definition
Nothing
Methods
grammar :: Grammatical token p => p a a Source #
default grammar :: (RegGrammar token a, Grammatical token p) => p a a Source #
Instances
| Grammar Char (Bnf (RegEx Char)) Source # | The context-free
Such a
Like
They can be generated from context-free Like
|
| Grammar Char (RegEx Char) Source # | The context-free
Since they are strings, they have a string-like interface.
They can be generated from
A regular expression string is stored as an algebraic datatype, a
They're similar to regular expression strings in many other
programming languages. We can use them to see if a word and pattern
are
Like
Since they're a
Like other regular expression languages, they support character classes.
The character classes are used for failure, matching no character or string, as well as the wildcard, matching any single character.
Additional forms of character classes test for a character's
Ill-formed regular expression strings normalize to failure.
|
Defined in Control.Lens.Grammar.RegEx | |
class CtxGrammar token a where Source #
A type's context-sensitive grammar, over its tokens; its context-free grammar, by default.
Minimal complete definition
Nothing
Methods
ctxGrammar :: CtxGrammatical token p => p a a Source #
default ctxGrammar :: (Grammar token a, CtxGrammatical token p) => p a a Source #
Instances
| CtxGrammar Char (Bnf (RegEx Char)) Source # | |
Defined in Control.Lens.Grammar.RegEx | |
| CtxGrammar Char (RegEx Char) Source # | |
Defined in Control.Lens.Grammar.RegEx Methods ctxGrammar :: CtxGrammatical Char p => p (RegEx Char) (RegEx Char) Source # | |
Numerals
digit :: (Integral n, Choice p, Tokenized Char (p Char Char)) => n -> p n n Source #
A digit in a base, from 2 to 36, by its value: 0-9, then letters,
printing in lowercase, & parsing either case.
>>>[d | (d, "") <- parseP (digit (16 :: Int) :: Parsor String [] Int Int) "F"][15]
numeral :: (Integral n, Alternator p, Tokenized Char (p Char Char)) => n -> p n n Source #
A natural number in a base, from 2 to 36, by its digits, most significant first, printing without leading zeros, & parsing them too, an improper iso.
>>>($ "") <$> printP (numeral (16 :: Integer) :: Printor String Maybe Integer Integer) 255Just "ff"