distributors-0.6.0.0: Unifying Parsers, Printers & Grammars
Copyright(C) 2026 - Eitan Chatav
LicenseBSD-style (see the file LICENSE)
MaintainerEitan Chatav <eitan.chatav@gmail.com>
Stabilityprovisional
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Control.Lens.Grammar.Machine

Description

 
Synopsis

Matching

class Matching word pattern | pattern -> word where Source #

Does a word match a pattern?

Methods

(=~) :: word -> pattern -> Bool infix 2 Source #

Instances

Instances details
Matching String RegBnf Source # 
Instance details

Defined in Control.Lens.Grammar

Methods

(=~) :: String -> RegBnf -> Bool Source #

Matching String RegString Source # 
Instance details

Defined in Control.Lens.Grammar

Methods

(=~) :: String -> RegString -> Bool Source #

Matching s k => Matching s (Grammor k a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

(=~) :: s -> Grammor k a b -> Bool Source #

AsEmpty s => Matching s (Parsor s [] a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

(=~) :: s -> Parsor s [] a b -> Bool Source #

Matching s (APrism s t a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Machine

Methods

(=~) :: s -> APrism s t a b -> Bool Source #

Categorized token => Matching [token] (Bnf (RegEx token)) Source # 
Instance details

Defined in Control.Lens.Grammar.Machine

Methods

(=~) :: [token] -> Bnf (RegEx token) -> Bool Source #

Categorized token => Matching [token] (RegEx token) Source # 
Instance details

Defined in Control.Lens.Grammar.Machine

Methods

(=~) :: [token] -> RegEx token -> Bool Source #

Categorized token => Matching [token] (Transducer token) Source # 
Instance details

Defined in Control.Lens.Grammar.Machine

Methods

(=~) :: [token] -> Transducer token -> Bool Source #

Transducer

transducer :: Bnf (RegEx token) -> Transducer token Source #

Compile a RegExtended Bnf into a Transducer, using a combination of Thompson's algorithm for regular expressions and Earley's algorithm for context-free grammars. See Jim & Mandelbaum, Efficient Earley Parsing with Regular Right-hand Sides, and McIlroy, Enumerating the strings of regular languages.

A transducer is a form of finite state machine that can be run in various ways like =~, expectNext, languageSample, parseForest & unreachableRules.

parseForest Source #

Arguments

:: Categorized token 
=> Transducer token 
-> [token]

string

-> ([Tree (String, Int, Int, [token])], [token])

parse forest & remaining unparsed tokens

The parse forest of a string of tokens.

languageSample Source #

Arguments

:: (TokenAlgebra token (f token), Applicative f) 
=> Transducer token

transducer

-> f [[token]] 

languageSample lazily produces all words in a language from shortest to longest. However since TokenClasses can resolve to infinite sets of tokens, and the relevant case of Char tokens while not infinite is huge, it samples tokens in an Applicative TokenAlgebra.

expectNext Source #

Arguments

:: Categorized token 
=> Transducer token 
-> [token]

prefix

-> TokenClass token 

What token is expected next? The scanner frontier, expectNext returns the TokenClass that can be scanned next after the given input prefix. A falseB result means the current chart has no scanner transitions, i.e. the prefix is a dead end for recognition.

unreachableRules :: Transducer token -> Set String Source #

Rule names that can never be entered from the start expression — dead productions. A non-empty result is a grammar-hygiene warning: those rules can be deleted without changing the recognized language.

data Transducer token Source #

A Transducer is a tuple

T = (Σ, Δ, Q, I ⊆ Q, F ∈ Q, transition ⊆ Q × (Σ ∪ ∆) × Q, output ⊆ Q × ∆)

Constructors

Transducer 

Fields

Instances

Instances details
Categorized token => Matching [token] (Transducer token) Source # 
Instance details

Defined in Control.Lens.Grammar.Machine

Methods

(=~) :: [token] -> Transducer token -> Bool Source #