| 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.BackusNaur
Contents
Description
See Naur & Backus, et al. Report on the Algorithmic Language ALGOL 60
Synopsis
- class BackusNaurForm bnf where
- data Bnf rule = Bnf {}
- liftBnf0 :: Ord a => a -> Bnf a
- liftBnf1 :: (Coercible a b, Ord b) => (a -> b) -> Bnf a -> Bnf b
- liftBnf2 :: (Coercible a c, Coercible b c, Ord c) => (a -> b -> c) -> Bnf a -> Bnf b -> Bnf c
- class Matching word pattern | pattern -> word where
- diffB :: (Categorized token, HasTrie token) => [token] -> Bnf (RegEx token) -> Bnf (RegEx token)
BackusNaurForm
class BackusNaurForm bnf where Source #
BackusNaurForm grammar combinators formalize
rule abstraction and general recursion. Context-free
Grammars support the BackusNaurForm interface.
Minimal complete definition
Nothing
Methods
rule :: String -> bnf -> bnf Source #
For a BackusNaurForm parser instance,
rule can be used to detail parse errors.
rule name bnf = ruleRec name (\_ -> bnf)
ruleRec :: String -> (bnf -> bnf) -> bnf Source #
General recursion, using ruleRec, rules can refer to themselves.
Instances
| BackusNaurForm RegBnf Source # | |
| (Ord rule, NonTerminalSymbol rule) => BackusNaurForm (Bnf rule) Source # | |
| BackusNaurForm k => BackusNaurForm (Grammor k a b) Source # | |
| BackusNaurForm (Parsor s m a b) Source # | |
| BackusNaurForm (Printor s m a b) Source # | |
A Bnf consists of a distinguished starting rule
and a set of named rules, supporting the BackusNaurForm interface.
Instances
liftBnf1 :: (Coercible a b, Ord b) => (a -> b) -> Bnf a -> Bnf b Source #
Lift a function of rules to Bnfs.
liftBnf2 :: (Coercible a c, Coercible b c, Ord c) => (a -> b -> c) -> Bnf a -> Bnf b -> Bnf c Source #
Lift a binary function of rules to Bnfs.
Matching
class Matching word pattern | pattern -> word where Source #
Does a word match a pattern?
Instances
| Matching String RegBnf Source # | |
| Matching String RegString Source # | |
| Matching s k => Matching s (Grammor k a b) Source # | |
| AsEmpty s => Matching s (Parsor s List a b) Source # | |
| Matching s (APrism s t a b) Source # | |
| (Categorized token, HasTrie token) => Matching [token] (Bnf (RegEx token)) Source # | |
| (Categorized token, HasTrie token) => Matching [token] (RegEx token) Source # | |