definitive-parser-3.1: General LogicT-based parser combinator library compatible with the definitive-base Prelude

Safe HaskellNone
LanguageHaskell2010

Language.Parser

Contents

Description

A module providing simple Parser combinator functionality. Useful for small parsing tasks such as identifier parsing or command-line argument parsing

Synopsis

Documentation

module Definitive

data Proxy a Source #

A proxy type to specify response types

Constructors

Proxy 

Instances

SerialStream stream => Format stream (Proxy a) Source # 

Methods

datum :: Parser stream (Proxy a) Source #

SerialStream stream => Serializable stream (Proxy a) Source # 

Methods

encode :: Proxy stream -> Proxy a -> StreamBuilder stream Source #

Eq (Proxy a) Source # 

Methods

(==) :: Proxy a -> Proxy a -> Bool #

(/=) :: Proxy a -> Proxy a -> Bool #

Ord (Proxy a) Source # 

Methods

compare :: Proxy a -> Proxy a -> Ordering #

(<) :: Proxy a -> Proxy a -> Bool #

(<=) :: Proxy a -> Proxy a -> Bool #

(>) :: Proxy a -> Proxy a -> Bool #

(>=) :: Proxy a -> Proxy a -> Bool #

max :: Proxy a -> Proxy a -> Proxy a #

min :: Proxy a -> Proxy a -> Proxy a #

Show (Proxy a) Source # 

Methods

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

show :: Proxy a -> String #

showList :: [Proxy a] -> ShowS #

The ParserT Type

newtype ParserT s m a Source #

Constructors

ParserT (StateT s (LogicT m) a) 

Instances

MonadReader r m => MonadReader r (ParserT s m) Source # 

Methods

ask :: ParserT s m r #

local :: (r -> r) -> ParserT s m a -> ParserT s m a #

MonadWriter w m => MonadWriter w (ParserT s m) Source # 

Methods

tell :: w -> ParserT s m () #

listen :: ParserT s m a -> ParserT s m (w, a) #

censor :: ParserT s m (a, w -> w) -> ParserT s m a #

Monad m => MonadError Void (ParserT s m) Source # 

Methods

throw :: Void -> ParserT s m a #

catch :: (Void -> ParserT s m a) -> ParserT s m a -> ParserT s m a #

Monad m => MonadParser s (StateT s m) (ParserT s m) Source # 

Methods

runStreamState :: State s a -> ParserT s m a Source #

tokenParser :: (StreamToken s -> Either [StreamChar s] Bool) -> ParserT s m (StreamChar s) Source #

noParse :: ParserT s m a Source #

(<+?) :: ParserT s m a -> ParserT s m a -> ParserT s m a Source #

(<+>) :: ParserT s m a -> ParserT s m a -> ParserT s m a Source #

MonadTrans (ParserT s) Source # 

Methods

lift :: Monad m => m a -> ParserT s m a #

ConcreteMonad (ParserT s) Source # 

Methods

generalize :: Monad m => ParserT s Id a -> ParserT s m a #

Functor (ParserT s m) Source # 

Methods

map :: (a -> b) -> ParserT s m a -> ParserT s m b #

SemiApplicative (ParserT s m) Source # 

Methods

(<*>) :: ParserT s m (a -> b) -> ParserT s m a -> ParserT s m b #

Applicative (ParserT s m) Source # 
Monad (ParserT s m) Source # 

Methods

join :: ParserT s m (ParserT s m a) -> ParserT s m a #

(>>=) :: ParserT s m a -> (a -> ParserT s m b) -> ParserT s m b #

MonadFix m => MonadFix (ParserT s m) Source # 

Methods

mfix :: (a -> ParserT s m a) -> ParserT s m a #

Unit (ParserT s m) Source # 

Methods

pure :: a -> ParserT s m a #

Monad m => MonadLogic (StateT s m) (ParserT s m) Source # 

Methods

deduce :: ParserT s m a -> StateT s m (Maybe (a, ParserT s m a)) #

induce :: StateT s m (Maybe (a, ParserT s m a)) -> ParserT s m a #

(Monad m, ParseStream s, (~) * (StreamChar s) Char) => IsString (ParserT s m a) Source # 

Methods

fromString :: String -> ParserT s m a #

Semigroup (ParserT s m a) Source # 

Methods

(+) :: ParserT s m a -> ParserT s m a -> ParserT s m a #

Monoid (ParserT s m a) Source # 

Methods

zero :: ParserT s m a #

type Parser c a = ParserT c Id a Source #

newtype ParserA m s a Source #

Constructors

ParserA (ParserT s m a) 

Instances

Monad m => Arrow (ParserA m) Source # 

Methods

arr :: (a -> b) -> ParserA m a b #

Deductive (ParserA m) Source # 

Methods

(.) :: ParserA m b c -> ParserA m a b -> ParserA m a c #

Monad m => Category (ParserA m) Source # 

Methods

id :: ParserA m a a #

Monad m => Choice (ParserA m) Source # 

Methods

(<|>) :: ParserA m a c -> ParserA m b c -> ParserA m (a :+: b) c #

Monad m => Split (ParserA m) Source # 

Methods

(<#>) :: ParserA m a c -> ParserA m b d -> ParserA m (a, b) (c, d) #

i'ParserA :: Iso (ParserA m s a) (ParserA m' s' a') (ParserT s m a) (ParserT s' m' a') Source #

The Stream class

class Stream c s | s -> c where #

Minimal complete definition

uncons, cons

Methods

uncons :: s -> Maybe (c, s) #

cons :: c -> s -> s #

Instances

Stream Char Chunk 

Methods

uncons :: Chunk -> Maybe (Char, Chunk) #

cons :: Char -> Chunk -> Chunk #

Stream Word8 Bytes 

Methods

uncons :: Bytes -> Maybe (Word8, Bytes) #

cons :: Word8 -> Bytes -> Bytes #

Stream a [a] 

Methods

uncons :: [a] -> Maybe (a, [a]) #

cons :: a -> [a] -> [a] #

Stream a (StreamC a) 

Methods

uncons :: StreamC a -> Maybe (a, StreamC a) #

cons :: a -> StreamC a -> StreamC a #

emptyStream :: Stream c s => s -> Bool Source #

Test if a Stream is empty

Converting to/from Parsers

parserT :: (Monad n, Monad m) => Iso (ParserT s m a) (ParserT t n b) (s -> m [(s, a)]) (t -> n [(t, b)]) Source #

parser :: Iso (Parser s a) (Parser t b) (s -> [(s, a)]) (t -> [(t, b)]) Source #

ioParser :: Parser a b -> a -> IO b Source #

matchesT :: (Monad f, Monoid m) => (a -> m) -> ParserT s f a -> s -> f m Source #

matches :: Monoid m => (a -> m) -> Parser s a -> s -> m Source #

readsParser :: Parser s a -> s -> [(a, s)] Source #

lookingAt :: MonadParser s m p => p a -> p a Source #

notLookingAt :: MonadParser s m p => p a -> p () Source #

The MonadParser class

class (MonadLogic m p, Monoid (p ()), Monad p, Monad m) => MonadParser s m p | p -> m s where Source #

Minimal complete definition

runStreamState, noParse, (<+?), (<+>)

Methods

runStreamState :: State s a -> p a Source #

tokenParser :: ParseStream s => (StreamToken s -> Either [StreamChar s] Bool) -> p (StreamChar s) Source #

noParse :: p a Source #

(<+?), (<+>) :: p a -> p a -> p a infixr 0 <+?, <+> Source #

Instances

Monad m => MonadParser s (StateT s m) (ParserT s m) Source # 

Methods

runStreamState :: State s a -> ParserT s m a Source #

tokenParser :: (StreamToken s -> Either [StreamChar s] Bool) -> ParserT s m (StreamChar s) Source #

noParse :: ParserT s m a Source #

(<+?) :: ParserT s m a -> ParserT s m a -> ParserT s m a Source #

(<+>) :: ParserT s m a -> ParserT s m a -> ParserT s m a Source #

(MonadParser s m p, Monoid (p ((), Void, Void))) => MonadParser s (ReaderT s' m) (ReaderT s' p) Source # 

Methods

runStreamState :: State s a -> ReaderT s' p a Source #

tokenParser :: (StreamToken s -> Either [StreamChar s] Bool) -> ReaderT s' p (StreamChar s) Source #

noParse :: ReaderT s' p a Source #

(<+?) :: ReaderT s' p a -> ReaderT s' p a -> ReaderT s' p a Source #

(<+>) :: ReaderT s' p a -> ReaderT s' p a -> ReaderT s' p a Source #

(MonadParser s m p, Monoid (p ((), s', Void))) => MonadParser s (StateT s' m) (StateT s' p) Source # 

Methods

runStreamState :: State s a -> StateT s' p a Source #

tokenParser :: (StreamToken s -> Either [StreamChar s] Bool) -> StateT s' p (StreamChar s) Source #

noParse :: StateT s' p a Source #

(<+?) :: StateT s' p a -> StateT s' p a -> StateT s' p a Source #

(<+>) :: StateT s' p a -> StateT s' p a -> StateT s' p a Source #

class ParseStreamType s Source #

Associated Types

type StreamToken s :: * Source #

type StreamChar s :: * Source #

Instances

ParseStreamType [a] Source # 

Associated Types

type StreamToken [a] :: * Source #

type StreamChar [a] :: * Source #

class (ParseStreamType s, Stream (StreamToken s) s) => ParseStream s where Source #

Minimal complete definition

tokenPayload

Instances

ParseStream [c] Source # 

Methods

completeBefore :: Proxy [c] -> StreamToken [c] -> Bool Source #

tokenPayload :: Proxy [c] -> StreamToken [c] -> StreamChar [c] Source #

acceptToken :: StreamChar [c] -> [c] -> [c] Source #

Basic combinators

(>*>) :: Monad m => ParserT a m b -> ParserT b m c -> ParserT a m c Source #

The (+) operator with lower priority

(<*<) :: Monad m => ParserT b m c -> ParserT a m b -> ParserT a m c Source #

token :: (ParseStream s, MonadParser s m p) => p (StreamChar s) Source #

Consume a token from the Stream

satisfy :: forall s m p. (MonadParser s m p, ParseStream s) => (StreamChar s -> Bool) -> p (StreamChar s) Source #

Consume a token and succeed if it verifies a predicate

oneOf :: forall s t m p. (Eq (StreamChar s), Foldable t, ParseStream s, MonadParser s m p) => t (StreamChar s) -> p (StreamChar s) Source #

Parse a member of a set of values

oneOfSet :: forall s m p. (Ord (StreamChar s), ParseStream s, MonadParser s m p) => Set (StreamChar s) -> p (StreamChar s) Source #

noneOf :: (Eq (StreamChar s), Foldable t, ParseStream s, MonadParser s m p) => t (StreamChar s) -> p (StreamChar s) Source #

Parse anything but a member of a set

single :: forall s m p. (MonadParser s m p, Eq (StreamChar s), ParseStream s) => StreamChar s -> p () Source #

Consume a single fixed token or fail.

several :: (Eq (StreamChar s), Foldable t, MonadParser s m p, ParseStream s) => t (StreamChar s) -> p () Source #

Consume a structure of characters or fail

like :: (Eq (StreamChar s), MonadParser s m p, ParseStream s) => [StreamChar s] -> p () Source #

Consume a structure of characters or fail

keyword :: (Eq (StreamChar s), MonadParser s m p, Foldable t, ParseStream s) => a -> t (StreamChar s) -> p a Source #

Consume a structure of characters or fail

remaining :: MonadParser s m p => p s Source #

The remaining Stream to parse

eoi :: (MonadParser s m p, ParseStream s) => p () Source #

Succeed only at the End Of Input.

Specialized utilities

number :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char, Num n) => p n Source #

Parse a litteral decimal number

digit :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p Char Source #

Parse a single decimal digit

quotedString :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => Char -> p String Source #

Parse a delimited string, using \\ as the quoting character

space :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #

Zero or more spaces

nbspace :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #

One or more spaces

hspace :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #

Zero or more horizontal spaces (no newlines)

nbhspace :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #

One or more horizontal spaces (no newlines)

eol :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #

The end of a line

Useful combinators

many :: MonadParser s m p => p a -> p [a] Source #

Parse zero, one or more successive occurences of a parser

many1 :: MonadParser s m p => p a -> p [a] Source #

Parse one or more successiveé occurences of a parser

sepBy :: MonadParser s m p => p a -> p b -> p [a] infixl 1 Source #

Parse zero or more successive occurences of a parser separated by occurences of a second parser.

sepBy1 :: MonadParser s m p => p a -> p b -> p [a] infixl 1 Source #

Parse one or more successive occurences of a parser separated by occurences of a second parser.

skipMany :: MonadParser s m p => p a -> p () Source #

Skip many occurences of a parser

skipMany1 :: MonadParser s m p => p a -> p () Source #

Skip multiple occurences of a parser

many' :: MonadParser s m p => p a -> p [a] Source #

Parse zero, one or more successive occurences of a parser (no backtracking)

many1' :: MonadParser s m p => p a -> p [a] Source #

Parse one or more successiveé occurences of a parser (no backtracking)

sepBy' :: MonadParser s m p => p a -> p b -> p [a] Source #

Parse zero or more successive occurences of a parser separated by occurences of a second parser (no backtracking)

sepBy1' :: MonadParser s m p => p a -> p b -> p [a] Source #

Parse one or more successive occurences of a parser separated by occurences of a second parser (no backtracking)

skipMany' :: MonadParser s m p => p a -> p () Source #

Skip many occurences of a parser (no backtracking)

skipMany1' :: MonadParser s m p => p a -> p () Source #

Skip multiple occurences of a parser (no backtracking)

chainl :: MonadParser s m p => p a -> p (a -> b -> a) -> p b -> p a Source #

Chain an operator with an initial value

chainl' :: MonadParser s m p => p a -> p (a -> b -> a) -> p b -> p a Source #

Chain an operator with an initial value (eager)

chainr :: MonadParser s m p => p a -> p (b -> a -> a) -> p b -> p a Source #

Chain an operator with an initial value and several tail values.

chainr' :: MonadParser s m p => p a -> p (b -> a -> a) -> p b -> p a Source #

Chain an operator with an initial value and several tail values.

option :: MonadParser s m p => a -> p a -> p a Source #

Try to consume a parser. Return a default value when it fails.

option' :: MonadParser s m p => a -> p a -> p a Source #

Try to consume a parser. Return a default value when it fails.

optionMaybe :: MonadParser s m p => p a -> p (Maybe a) Source #

optionMaybe' :: MonadParser s m p => p a -> p (Maybe a) Source #