Text.Trifecta.Parser

trifecta-1.5.2: A modern parser combinator library with convenient diagnostics

Copyright | (c) Edward Kmett 2011-2014
License | BSD3
Maintainer | ekmett@gmail.com
Stability | experimental
Portability | non-portable
Safe Haskell | None
Language | Haskell2010

Text.Trifecta.Parser

Contents

- Feeding a parser more more input
- Parsing

Description

Synopsis

- newtype Parser a = Parser {
  - unparser :: forall r. (a -> Err -> It Rope r) -> (Err -> It Rope r) -> (a -> Set String -> Delta -> ByteString -> It Rope r) -> (Doc -> It Rope r) -> Delta -> ByteString -> It Rope r
  }
- manyAccum :: (a -> [a] -> [a]) -> Parser a -> Parser [a]
- data Step a
  - = StepDone !Rope a
  - | StepFail !Rope Doc
  - | StepCont !Rope (Result a) (Rope -> Step a)
- feed :: Reducer t Rope => t -> Step r -> Step r
- starve :: Step a -> Result a
- stepParser :: Parser a -> Delta -> ByteString -> Step a
- stepResult :: Rope -> Result a -> Step a
- stepIt :: It Rope a -> Step a
- parseFromFile :: MonadIO m => Parser a -> String -> m (Maybe a)
- parseFromFileEx :: MonadIO m => Parser a -> String -> m (Result a)
- parseString :: Parser a -> Delta -> String -> Result a
- parseByteString :: Parser a -> Delta -> ByteString -> Result a
- parseTest :: (MonadIO m, Show a) => Parser a -> String -> m ()

# Documentation

newtype Parser a

Constructors

Parser |
Fields unparser :: forall r. (a -> Err -> It Rope r) -> (Err -> It Rope r) -> (a -> Set String -> Delta -> ByteString -> It Rope r) -> (Doc -> It Rope r) -> Delta -> ByteString -> It Rope r

Instances

Monad Parser |
Functor Parser |
Applicative Parser |
Alternative Parser |
MonadPlus Parser |
TokenParsing Parser |
CharParsing Parser |
LookAheadParsing Parser |
Parsing Parser |
DeltaParsing Parser |
Errable Parser |
MarkParsing Delta Parser |
Monoid a => Monoid (Parser a) |
Semigroup a => Semigroup (Parser a) |

manyAccum :: (a -> [a] -> [a]) -> Parser a -> Parser [a]

# Feeding a parser more more input

data Step a

Constructors

StepDone !Rope a |
StepFail !Rope Doc |
StepCont !Rope (Result a) (Rope -> Step a) |

Instances

Functor Step |
Show a => Show (Step a) |

feed :: Reducer t Rope => t -> Step r -> Step r

starve :: Step a -> Result a

stepParser :: Parser a -> Delta -> ByteString -> Step a

stepResult :: Rope -> Result a -> Step a

stepIt :: It Rope a -> Step a

# Parsing

parseFromFile :: MonadIO m => Parser a -> String -> m (Maybe a)

`parseFromFile p filePath` runs a parser `p` on the input read from `filePath` using `readFile`. All diagnostic messages emitted over the course of the parse attempt are shown to the user on the console.

    main = do
      result <- parseFromFile numbers "digits.txt"
      case result of
        Nothing -> return ()
        Just a  -> print $ sum a

parseFromFileEx :: MonadIO m => Parser a -> String -> m (Result a)

`parseFromFileEx p filePath` runs a parser `p` on the input read from `filePath` using `readFile`. Returns all diagnostic messages emitted over the course of the parse and the answer if the parse was successful.

    main = do
      result <- parseFromFileEx (many number) "digits.txt"
      case result of
        Failure xs -> displayLn xs
        Success a  -> print (sum a)

parseString :: Parser a -> Delta -> String -> Result a

parseByteString :: Parser a -> Delta -> ByteString -> Result a

`parseByteString p delta i` runs a parser `p` on `i`.

parseTest :: (MonadIO m, Show a) => Parser a -> String -> m ()