| Copyright | (C) 2011-2019 Edward Kmett |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Text.Trifecta
Description
For a short introduction, see the Text.Trifecta.Tutorial module.
Synopsis
- module Text.Trifecta.Rendering
- module Text.Trifecta.Highlight
- module Text.Trifecta.Parser
- module Text.Trifecta.Combinators
- module Text.Trifecta.Result
- module Text.Trifecta.Rope
- some :: Alternative f => f a -> f [a]
- many :: Alternative f => f a -> f [a]
- class Alternative m => Parsing (m :: Type -> Type) where
- try :: m a -> m a
- (<?>) :: m a -> String -> m a
- skipMany :: m a -> m ()
- skipSome :: m a -> m ()
- unexpected :: String -> m a
- eof :: m ()
- notFollowedBy :: Show a => m a -> m ()
- choice :: Alternative m => [m a] -> m a
- count :: Applicative m => Int -> m a -> m [a]
- between :: Applicative m => m bra -> m ket -> m a -> m a
- option :: Alternative m => a -> m a -> m a
- optional :: Alternative f => f a -> f (Maybe a)
- sepBy :: Alternative m => m a -> m sep -> m [a]
- sepBy1 :: Alternative m => m a -> m sep -> m [a]
- endBy :: Alternative m => m a -> m sep -> m [a]
- endBy1 :: Alternative m => m a -> m sep -> m [a]
- chainr :: Alternative m => m a -> m (a -> a -> a) -> a -> m a
- chainl :: Alternative m => m a -> m (a -> a -> a) -> a -> m a
- chainr1 :: Alternative m => m a -> m (a -> a -> a) -> m a
- chainl1 :: Alternative m => m a -> m (a -> a -> a) -> m a
- manyTill :: Alternative m => m a -> m end -> m [a]
- sepEndBy1 :: Alternative m => m a -> m sep -> m [a]
- sepEndBy :: Alternative m => m a -> m sep -> m [a]
- skipOptional :: Alternative m => m a -> m ()
- surroundedBy :: Applicative m => m a -> m sur -> m a
- sepByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)
- sepEndByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)
- endByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)
- class Parsing m => CharParsing (m :: Type -> Type) where
- space :: CharParsing m => m Char
- lower :: CharParsing m => m Char
- upper :: CharParsing m => m Char
- alphaNum :: CharParsing m => m Char
- digit :: CharParsing m => m Char
- octDigit :: CharParsing m => m Char
- letter :: CharParsing m => m Char
- noneOf :: CharParsing m => [Char] -> m Char
- oneOf :: CharParsing m => [Char] -> m Char
- spaces :: CharParsing m => m ()
- newline :: CharParsing m => m Char
- tab :: CharParsing m => m Char
- hexDigit :: CharParsing m => m Char
- oneOfSet :: CharParsing m => CharSet -> m Char
- noneOfSet :: CharParsing m => CharSet -> m Char
- satisfyRange :: CharParsing m => Char -> Char -> m Char
- scientific :: TokenParsing m => m Scientific
- parens :: TokenParsing m => m a -> m a
- symbol :: TokenParsing m => String -> m String
- octal :: TokenParsing m => m Integer
- decimal :: TokenParsing m => m Integer
- class CharParsing m => TokenParsing (m :: Type -> Type) where
- commaSep1 :: TokenParsing m => m a -> m [a]
- commaSep :: TokenParsing m => m a -> m [a]
- semiSep1 :: TokenParsing m => m a -> m [a]
- semiSep :: TokenParsing m => m a -> m [a]
- dot :: TokenParsing m => m Char
- colon :: TokenParsing m => m Char
- comma :: TokenParsing m => m Char
- brackets :: TokenParsing m => m a -> m a
- angles :: TokenParsing m => m a -> m a
- braces :: TokenParsing m => m a -> m a
- whiteSpace :: TokenParsing m => m ()
- hexadecimal :: TokenParsing m => m Integer
- integer :: TokenParsing m => m Integer
- natural :: TokenParsing m => m Integer
- stringLiteral :: (TokenParsing m, IsString s) => m s
- charLiteral :: TokenParsing m => m Char
- newtype Unlined (m :: Type -> Type) a = Unlined {
- runUnlined :: m a
- newtype Unspaced (m :: Type -> Type) a = Unspaced {
- runUnspaced :: m a
- newtype Unhighlighted (m :: Type -> Type) a = Unhighlighted {
- runUnhighlighted :: m a
- data IdentifierStyle (m :: Type -> Type) = IdentifierStyle {
- _styleName :: String
- _styleStart :: m Char
- _styleLetter :: m Char
- _styleReserved :: HashSet String
- _styleHighlight :: Highlight
- _styleReservedHighlight :: Highlight
- stringLiteral' :: (TokenParsing m, IsString s) => m s
- double :: TokenParsing m => m Double
- naturalOrDouble :: TokenParsing m => m (Either Integer Double)
- integerOrDouble :: TokenParsing m => m (Either Integer Double)
- naturalOrScientific :: TokenParsing m => m (Either Integer Scientific)
- integerOrScientific :: TokenParsing m => m (Either Integer Scientific)
- textSymbol :: TokenParsing m => Text -> m Text
- symbolic :: TokenParsing m => Char -> m Char
- styleName :: forall f (m :: Type -> Type). Functor f => (String -> f String) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleStart :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleLetter :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleChars :: Applicative f => (m Char -> f (n Char)) -> IdentifierStyle m -> f (IdentifierStyle n)
- styleReserved :: forall f (m :: Type -> Type). Functor f => (HashSet String -> f (HashSet String)) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleHighlight :: forall f (m :: Type -> Type). Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleReservedHighlight :: forall f (m :: Type -> Type). Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleHighlights :: forall f (m :: Type -> Type). Applicative f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m)
- liftIdentifierStyle :: forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type). (MonadTrans t, Monad m) => IdentifierStyle m -> IdentifierStyle (t m)
- reserve :: (TokenParsing m, Monad m) => IdentifierStyle m -> String -> m ()
- reserveText :: (TokenParsing m, Monad m) => IdentifierStyle m -> Text -> m ()
- ident :: (TokenParsing m, Monad m, IsString s) => IdentifierStyle m -> m s
- characterChar :: TokenParsing m => m Char
- integer' :: TokenParsing m => m Integer
Documentation
module Text.Trifecta.Rendering
module Text.Trifecta.Highlight
module Text.Trifecta.Parser
module Text.Trifecta.Combinators
module Text.Trifecta.Result
module Text.Trifecta.Rope
some :: Alternative f => f a -> f [a] Source #
One or more.
Examples
>>>some (putStr "la")lalalalalalalalala... * goes on forever *
>>>some Nothingnothing
>>>take 5 <$> some (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case some parser will attempt to
parse parser one or more times until it fails.
many :: Alternative f => f a -> f [a] Source #
Zero or more.
Examples
>>>many (putStr "la")lalalalalalalalala... * goes on forever *
>>>many NothingJust []
>>>take 5 <$> many (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case many parser will attempt to
parse parser zero or more times until it fails.
class Alternative m => Parsing (m :: Type -> Type) where #
Minimal complete definition
Methods
(<?>) :: m a -> String -> m a #
unexpected :: String -> m a #
notFollowedBy :: Show a => m a -> m () #
Instances
choice :: Alternative m => [m a] -> m a #
count :: Applicative m => Int -> m a -> m [a] #
between :: Applicative m => m bra -> m ket -> m a -> m a #
option :: Alternative m => a -> m a -> m a #
optional :: Alternative f => f a -> f (Maybe a) Source #
One or none.
It is useful for modelling any computation that is allowed to fail.
Examples
Using the Alternative instance of Control.Monad.Except, the following functions:
>>>import Control.Monad.Except
>>>canFail = throwError "it failed" :: Except String Int>>>final = return 42 :: Except String Int
Can be combined by allowing the first function to fail:
>>>runExcept $ canFail *> finalLeft "it failed"
>>>runExcept $ optional canFail *> finalRight 42
sepBy :: Alternative m => m a -> m sep -> m [a] #
sepBy1 :: Alternative m => m a -> m sep -> m [a] #
endBy :: Alternative m => m a -> m sep -> m [a] #
endBy1 :: Alternative m => m a -> m sep -> m [a] #
chainr :: Alternative m => m a -> m (a -> a -> a) -> a -> m a #
chainl :: Alternative m => m a -> m (a -> a -> a) -> a -> m a #
chainr1 :: Alternative m => m a -> m (a -> a -> a) -> m a #
chainl1 :: Alternative m => m a -> m (a -> a -> a) -> m a #
manyTill :: Alternative m => m a -> m end -> m [a] #
sepEndBy1 :: Alternative m => m a -> m sep -> m [a] #
sepEndBy :: Alternative m => m a -> m sep -> m [a] #
skipOptional :: Alternative m => m a -> m () #
surroundedBy :: Applicative m => m a -> m sur -> m a #
sepByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a) #
sepEndByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a) #
endByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a) #
class Parsing m => CharParsing (m :: Type -> Type) where #
Minimal complete definition
Nothing
Instances
space :: CharParsing m => m Char #
lower :: CharParsing m => m Char #
upper :: CharParsing m => m Char #
alphaNum :: CharParsing m => m Char #
digit :: CharParsing m => m Char #
octDigit :: CharParsing m => m Char #
letter :: CharParsing m => m Char #
noneOf :: CharParsing m => [Char] -> m Char #
oneOf :: CharParsing m => [Char] -> m Char #
spaces :: CharParsing m => m () #
newline :: CharParsing m => m Char #
tab :: CharParsing m => m Char #
hexDigit :: CharParsing m => m Char #
oneOfSet :: CharParsing m => CharSet -> m Char #
noneOfSet :: CharParsing m => CharSet -> m Char #
satisfyRange :: CharParsing m => Char -> Char -> m Char #
scientific :: TokenParsing m => m Scientific #
parens :: TokenParsing m => m a -> m a #
symbol :: TokenParsing m => String -> m String #
octal :: TokenParsing m => m Integer #
decimal :: TokenParsing m => m Integer #
class CharParsing m => TokenParsing (m :: Type -> Type) where #
Minimal complete definition
Nothing
Instances
commaSep1 :: TokenParsing m => m a -> m [a] #
commaSep :: TokenParsing m => m a -> m [a] #
semiSep1 :: TokenParsing m => m a -> m [a] #
semiSep :: TokenParsing m => m a -> m [a] #
dot :: TokenParsing m => m Char #
colon :: TokenParsing m => m Char #
comma :: TokenParsing m => m Char #
brackets :: TokenParsing m => m a -> m a #
angles :: TokenParsing m => m a -> m a #
braces :: TokenParsing m => m a -> m a #
whiteSpace :: TokenParsing m => m () #
hexadecimal :: TokenParsing m => m Integer #
integer :: TokenParsing m => m Integer #
natural :: TokenParsing m => m Integer #
stringLiteral :: (TokenParsing m, IsString s) => m s #
charLiteral :: TokenParsing m => m Char #
newtype Unlined (m :: Type -> Type) a #
Constructors
| Unlined | |
Fields
| |
Instances
| MonadTrans Unlined | |
| MonadReader e m => MonadReader e (Unlined m) | |
| MonadState s m => MonadState s (Unlined m) | |
| MonadWriter e m => MonadWriter e (Unlined m) | |
| Alternative m => Alternative (Unlined m) | |
| Applicative m => Applicative (Unlined m) | |
Defined in Text.Parser.Token | |
| Functor m => Functor (Unlined m) | |
| Monad m => Monad (Unlined m) | |
| MonadPlus m => MonadPlus (Unlined m) | |
| CharParsing m => CharParsing (Unlined m) | |
| Parsing m => Parsing (Unlined m) | |
Defined in Text.Parser.Token | |
| TokenParsing m => TokenParsing (Unlined m) | |
newtype Unspaced (m :: Type -> Type) a #
Constructors
| Unspaced | |
Fields
| |
Instances
| MonadTrans Unspaced | |
| MonadReader e m => MonadReader e (Unspaced m) | |
| MonadState s m => MonadState s (Unspaced m) | |
| MonadWriter e m => MonadWriter e (Unspaced m) | |
| Alternative m => Alternative (Unspaced m) | |
| Applicative m => Applicative (Unspaced m) | |
Defined in Text.Parser.Token Methods pure :: a -> Unspaced m a Source # (<*>) :: Unspaced m (a -> b) -> Unspaced m a -> Unspaced m b Source # liftA2 :: (a -> b -> c) -> Unspaced m a -> Unspaced m b -> Unspaced m c Source # (*>) :: Unspaced m a -> Unspaced m b -> Unspaced m b Source # (<*) :: Unspaced m a -> Unspaced m b -> Unspaced m a Source # | |
| Functor m => Functor (Unspaced m) | |
| Monad m => Monad (Unspaced m) | |
| MonadPlus m => MonadPlus (Unspaced m) | |
| CharParsing m => CharParsing (Unspaced m) | |
| Parsing m => Parsing (Unspaced m) | |
Defined in Text.Parser.Token | |
| TokenParsing m => TokenParsing (Unspaced m) | |
newtype Unhighlighted (m :: Type -> Type) a #
Constructors
| Unhighlighted | |
Fields
| |
Instances
data IdentifierStyle (m :: Type -> Type) #
Constructors
| IdentifierStyle | |
Fields
| |
stringLiteral' :: (TokenParsing m, IsString s) => m s #
double :: TokenParsing m => m Double #
naturalOrDouble :: TokenParsing m => m (Either Integer Double) #
integerOrDouble :: TokenParsing m => m (Either Integer Double) #
naturalOrScientific :: TokenParsing m => m (Either Integer Scientific) #
integerOrScientific :: TokenParsing m => m (Either Integer Scientific) #
textSymbol :: TokenParsing m => Text -> m Text #
symbolic :: TokenParsing m => Char -> m Char #
styleName :: forall f (m :: Type -> Type). Functor f => (String -> f String) -> IdentifierStyle m -> f (IdentifierStyle m) #
styleStart :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m) #
styleLetter :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m) #
styleChars :: Applicative f => (m Char -> f (n Char)) -> IdentifierStyle m -> f (IdentifierStyle n) #
styleReserved :: forall f (m :: Type -> Type). Functor f => (HashSet String -> f (HashSet String)) -> IdentifierStyle m -> f (IdentifierStyle m) #
styleHighlight :: forall f (m :: Type -> Type). Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m) #
styleReservedHighlight :: forall f (m :: Type -> Type). Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m) #
styleHighlights :: forall f (m :: Type -> Type). Applicative f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m) #
liftIdentifierStyle :: forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type). (MonadTrans t, Monad m) => IdentifierStyle m -> IdentifierStyle (t m) #
reserve :: (TokenParsing m, Monad m) => IdentifierStyle m -> String -> m () #
reserveText :: (TokenParsing m, Monad m) => IdentifierStyle m -> Text -> m () #
ident :: (TokenParsing m, Monad m, IsString s) => IdentifierStyle m -> m s #
characterChar :: TokenParsing m => m Char #
integer' :: TokenParsing m => m Integer #