grammatical-parsers-0.5: parsers that combine into grammars
Safe HaskellNone
LanguageHaskell2010

Text.Grampa.ContextFree.Memoizing

Synopsis

Documentation

data FailureInfo s Source #

Constructors

FailureInfo Int [Expected s] 

Instances

Instances details
Eq s => Eq (FailureInfo s) Source # 
Instance details

Defined in Text.Grampa.Internal

Show s => Show (FailureInfo s) Source # 
Instance details

Defined in Text.Grampa.Internal

Semigroup (FailureInfo s) Source # 
Instance details

Defined in Text.Grampa.Internal

Monoid (FailureInfo s) Source # 
Instance details

Defined in Text.Grampa.Internal

data ResultList g s r Source #

Constructors

ResultList !(BinTree (ResultInfo g s r)) !(FailureInfo s) 

Instances

Instances details
Functor (ResultList g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

fmap :: (a -> b) -> ResultList g s a -> ResultList g s b #

(<$) :: a -> ResultList g s b -> ResultList g s a #

Show s => Show1 (ResultList g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> ResultList g s a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [ResultList g s a] -> ShowS #

(Show s, Show r) => Show (ResultList g s r) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

showsPrec :: Int -> ResultList g s r -> ShowS #

show :: ResultList g s r -> String #

showList :: [ResultList g s r] -> ShowS #

Semigroup (ResultList g s r) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

(<>) :: ResultList g s r -> ResultList g s r -> ResultList g s r #

sconcat :: NonEmpty (ResultList g s r) -> ResultList g s r #

stimes :: Integral b => b -> ResultList g s r -> ResultList g s r #

Monoid (ResultList g s r) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

mempty :: ResultList g s r #

mappend :: ResultList g s r -> ResultList g s r -> ResultList g s r #

mconcat :: [ResultList g s r] -> ResultList g s r #

newtype Parser g s r Source #

Parser for a context-free grammar with packrat-like sharing of parse results. It does not support left-recursive grammars.

Constructors

Parser 

Fields

Instances

Instances details
Monad (Parser g i) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

(>>=) :: Parser g i a -> (a -> Parser g i b) -> Parser g i b #

(>>) :: Parser g i a -> Parser g i b -> Parser g i b #

return :: a -> Parser g i a #

Functor (Parser g i) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

fmap :: (a -> b) -> Parser g i a -> Parser g i b #

(<$) :: a -> Parser g i b -> Parser g i a #

Applicative (Parser g i) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

pure :: a -> Parser g i a #

(<*>) :: Parser g i (a -> b) -> Parser g i a -> Parser g i b #

liftA2 :: (a -> b -> c) -> Parser g i a -> Parser g i b -> Parser g i c #

(*>) :: Parser g i a -> Parser g i b -> Parser g i b #

(<*) :: Parser g i a -> Parser g i b -> Parser g i a #

Alternative (Parser g i) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

empty :: Parser g i a #

(<|>) :: Parser g i a -> Parser g i a -> Parser g i a #

some :: Parser g i a -> Parser g i [a] #

many :: Parser g i a -> Parser g i [a] #

MonadPlus (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

mzero :: Parser g s a #

mplus :: Parser g s a -> Parser g s a -> Parser g s a #

MonoidNull s => DeterministicParsing (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

(<<|>) :: Parser g s a -> Parser g s a -> Parser g s a #

takeOptional :: Parser g s a -> Parser g s (Maybe a) #

takeMany :: Parser g s a -> Parser g s [a] #

takeSome :: Parser g s a -> Parser g s [a] #

concatAll :: Monoid a => Parser g s a -> Parser g s a #

skipAll :: Parser g s a -> Parser g s () #

(LeftReductive s, FactorialMonoid s) => InputParsing (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Associated Types

type ParserInput (Parser g s) #

Methods

getInput :: Parser g s (ParserInput (Parser g s)) #

getSourcePos :: Parser g s Position #

anyToken :: Parser g s (ParserInput (Parser g s)) #

take :: Int -> Parser g s (ParserInput (Parser g s)) #

satisfy :: (ParserInput (Parser g s) -> Bool) -> Parser g s (ParserInput (Parser g s)) #

notSatisfy :: (ParserInput (Parser g s) -> Bool) -> Parser g s () #

scan :: state -> (state -> ParserInput (Parser g s) -> Maybe state) -> Parser g s (ParserInput (Parser g s)) #

string :: ParserInput (Parser g s) -> Parser g s (ParserInput (Parser g s)) #

takeWhile :: (ParserInput (Parser g s) -> Bool) -> Parser g s (ParserInput (Parser g s)) #

takeWhile1 :: (ParserInput (Parser g s) -> Bool) -> Parser g s (ParserInput (Parser g s)) #

(Show s, TextualMonoid s) => InputCharParsing (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

satisfyCharInput :: (Char -> Bool) -> Parser g s (ParserInput (Parser g s)) #

notSatisfyChar :: (Char -> Bool) -> Parser g s () #

scanChars :: state -> (state -> Char -> Maybe state) -> Parser g s (ParserInput (Parser g s)) #

takeCharsWhile :: (Char -> Bool) -> Parser g s (ParserInput (Parser g s)) #

takeCharsWhile1 :: (Char -> Bool) -> Parser g s (ParserInput (Parser g s)) #

MonoidNull s => LookAheadParsing (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

lookAhead :: Parser g s a -> Parser g s a #

(Show s, TextualMonoid s) => CharParsing (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

satisfy :: (Char -> Bool) -> Parser g s Char #

char :: Char -> Parser g s Char #

notChar :: Char -> Parser g s Char #

anyChar :: Parser g s Char #

string :: String -> Parser g s String #

text :: Text -> Parser g s Text #

MonoidNull s => Parsing (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

try :: Parser g s a -> Parser g s a #

(<?>) :: Parser g s a -> String -> Parser g s a #

skipMany :: Parser g s a -> Parser g s () #

skipSome :: Parser g s a -> Parser g s () #

unexpected :: String -> Parser g s a #

eof :: Parser g s () #

notFollowedBy :: Show a => Parser g s a -> Parser g s () #

(Eq s, LeftReductive s, FactorialMonoid s) => GrammarParsing (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Associated Types

type ParserGrammar (Parser g s) :: (Type -> Type) -> Type Source #

type GrammarFunctor (Parser g s) :: Type -> Type Source #

Methods

parsingResult :: ParserInput (Parser g s) -> GrammarFunctor (Parser g s) a -> ResultFunctor (Parser g s) (ParserInput (Parser g s), a) Source #

nonTerminal :: (g0 ~ ParserGrammar (Parser g s), GrammarConstraint (Parser g s) g0) => (g0 (GrammarFunctor (Parser g s)) -> GrammarFunctor (Parser g s) a) -> Parser g s a Source #

selfReferring :: (g0 ~ ParserGrammar (Parser g s), GrammarConstraint (Parser g s) g0, Distributive g0) => g0 (Parser g s) Source #

fixGrammar :: (g0 ~ ParserGrammar (Parser g s), GrammarConstraint (Parser g s) g0, Distributive g0) => (g0 (Parser g s) -> g0 (Parser g s)) -> g0 (Parser g s) Source #

recursive :: Parser g s a -> Parser g s a Source #

(LeftReductive s, FactorialMonoid s) => MultiParsing (Parser g s) Source #

Memoizing parser guarantees O(n²) performance for grammars with unambiguous productions, but provides no left recursion support.

parseComplete :: (Rank2.Functor g, FactorialMonoid s) =>
                 g (Memoizing.Parser g s) -> s -> g (Compose (ParseResults s) [])
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Associated Types

type ResultFunctor (Parser g s) :: Type -> Type Source #

type GrammarConstraint (Parser g s) g Source #

Methods

parseComplete :: (ParserInput (Parser g s) ~ s0, GrammarConstraint (Parser g s) g0, Eq s0, FactorialMonoid s0) => g0 (Parser g s) -> s0 -> g0 (ResultFunctor (Parser g s)) Source #

parsePrefix :: (ParserInput (Parser g s) ~ s0, GrammarConstraint (Parser g s) g0, Eq s0, FactorialMonoid s0) => g0 (Parser g s) -> s0 -> g0 (Compose (ResultFunctor (Parser g s)) ((,) s0)) Source #

Semigroup x => Semigroup (Parser g s x) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

(<>) :: Parser g s x -> Parser g s x -> Parser g s x #

sconcat :: NonEmpty (Parser g s x) -> Parser g s x #

stimes :: Integral b => b -> Parser g s x -> Parser g s x #

Monoid x => Monoid (Parser g s x) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

Methods

mempty :: Parser g s x #

mappend :: Parser g s x -> Parser g s x -> Parser g s x #

mconcat :: [Parser g s x] -> Parser g s x #

type ParserInput (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

type ParserInput (Parser g s) = s
type ParserGrammar (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

type ParserGrammar (Parser g s) = g
type GrammarFunctor (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

type ResultFunctor (Parser g s) Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

type GrammarConstraint (Parser g s) g' Source # 
Instance details

Defined in Text.Grampa.ContextFree.Memoizing

type GrammarConstraint (Parser g s) g' = (g ~ g', Functor g)

data BinTree a Source #

Constructors

Fork !(BinTree a) !(BinTree a) 
Leaf !a 
EmptyTree 

Instances

Instances details
Functor BinTree Source # 
Instance details

Defined in Text.Grampa.Internal

Methods

fmap :: (a -> b) -> BinTree a -> BinTree b #

(<$) :: a -> BinTree b -> BinTree a #

Foldable BinTree Source # 
Instance details

Defined in Text.Grampa.Internal

Methods

fold :: Monoid m => BinTree m -> m #

foldMap :: Monoid m => (a -> m) -> BinTree a -> m #

foldMap' :: Monoid m => (a -> m) -> BinTree a -> m #

foldr :: (a -> b -> b) -> b -> BinTree a -> b #

foldr' :: (a -> b -> b) -> b -> BinTree a -> b #

foldl :: (b -> a -> b) -> b -> BinTree a -> b #

foldl' :: (b -> a -> b) -> b -> BinTree a -> b #

foldr1 :: (a -> a -> a) -> BinTree a -> a #

foldl1 :: (a -> a -> a) -> BinTree a -> a #

toList :: BinTree a -> [a] #

null :: BinTree a -> Bool #

length :: BinTree a -> Int #

elem :: Eq a => a -> BinTree a -> Bool #

maximum :: Ord a => BinTree a -> a #

minimum :: Ord a => BinTree a -> a #

sum :: Num a => BinTree a -> a #

product :: Num a => BinTree a -> a #

Show a => Show (BinTree a) Source # 
Instance details

Defined in Text.Grampa.Internal

Methods

showsPrec :: Int -> BinTree a -> ShowS #

show :: BinTree a -> String #

showList :: [BinTree a] -> ShowS #

Semigroup (BinTree a) Source # 
Instance details

Defined in Text.Grampa.Internal

Methods

(<>) :: BinTree a -> BinTree a -> BinTree a #

sconcat :: NonEmpty (BinTree a) -> BinTree a #

stimes :: Integral b => b -> BinTree a -> BinTree a #

Monoid (BinTree a) Source # 
Instance details

Defined in Text.Grampa.Internal

Methods

mempty :: BinTree a #

mappend :: BinTree a -> BinTree a -> BinTree a #

mconcat :: [BinTree a] -> BinTree a #

fromResultList :: (Eq s, FactorialMonoid s) => s -> ResultList g s r -> ParseResults s [(s, r)] Source #

reparseTails :: Functor g => g (Parser g s) -> [(s, g (ResultList g s))] -> [(s, g (ResultList g s))] Source #

longest :: Parser g s a -> Parser g [(s, g (ResultList g s))] a Source #

Turns a context-free parser into a backtracking PEG parser that consumes the longest possible prefix of the list of input tails, opposite of peg

peg :: Parser g [(s, g (ResultList g s))] a -> Parser g s a Source #

Turns a backtracking PEG parser of the list of input tails into a context-free parser, opposite of longest

terminalPEG :: Monoid s => Parser g s a -> Parser g s a Source #

Turns a backtracking PEG parser into a context-free parser