Safe Haskell | None |
---|---|
Language | Haskell2010 |
Text.Parsec.Prim
- unknownError :: State s u -> ParseError
- sysUnExpectError :: String -> SourcePos -> Reply s u a
- unexpected :: Stream s m t => String -> ParsecT s u m a
- newtype ParsecT s u m a = ParsecT {
- runParsecT :: ParsecDSL s u m a
- mkPT :: Monad m => (State s u -> m (Consumed (m (Reply s u a)))) -> ParsecT s u m a
- type Parsec s u = ParsecT s u Identity
- data Consumed a :: * -> *
- data Reply s u a :: * -> * -> * -> *
- = Ok a ~(State s u) ParseError
- | Error ParseError
- data State s u :: * -> * -> * = State {
- stateInput :: s
- statePos :: ~SourcePos
- stateUser :: ~u
- parsecMap :: (a -> b) -> ParsecT s u m a -> ParsecT s u m b
- parserReturn :: a -> ParsecT s u m a
- parserBind :: ParsecT s u m a -> (a -> ParsecT s u m b) -> ParsecT s u m b
- mergeErrorReply :: ParseError -> Reply s u a -> Reply s u a
- parserFail :: String -> ParsecT s u m a
- parserZero :: ParsecT s u m a
- parserPlus :: ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
- (<?>) :: ParsecT s u m a -> String -> ParsecT s u m a
- (<|>) :: ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
- label :: ParsecT s u m a -> String -> ParsecT s u m a
- labels :: ParsecT s u m a -> [String] -> ParsecT s u m a
- lookAhead :: Stream s m t => ParsecT s u m a -> ParsecT s u m a
- class Monad m => Stream s m t | s -> t where
- tokens :: (Monad m, Stream s m t, Eq t) => ([t] -> String) -> (SourcePos -> [t] -> SourcePos) -> [t] -> ParsecT s u m [t]
- try :: ParsecT s u m a -> ParsecT s u m a
- token :: Stream s Identity t => (t -> String) -> (t -> SourcePos) -> (t -> Maybe a) -> Parsec s u a
- tokenPrim :: Stream s m t => (t -> String) -> (SourcePos -> t -> s -> SourcePos) -> (t -> Maybe a) -> ParsecT s u m a
- tokenPrimEx :: Stream s m t => (t -> String) -> (SourcePos -> t -> s -> SourcePos) -> Maybe (SourcePos -> t -> s -> u -> u) -> (t -> Maybe a) -> ParsecT s u m a
- many :: ParsecT s u m a -> ParsecT s u m [a]
- skipMany :: ParsecT s u m a -> ParsecT s u m ()
- manyAccum :: (a -> [a] -> [a]) -> ParsecT s u m a -> ParsecT s u m [a]
- runPT :: (Monad m, Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
- runPTLog :: (MonadIO m, MonadReader LogType m, Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
- runP :: Stream s Identity t => Parsec s u a -> u -> SourceName -> s -> Either ParseError a
- runParserT :: Stream s m t => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
- runParserTLog :: (MonadIO m, MonadReader LogType m, Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
- runParser :: Stream s Identity t => Parsec s u a -> u -> SourceName -> s -> Either ParseError a
- parse :: Stream s Identity t => Parsec s () a -> SourceName -> s -> Either ParseError a
- parseTest :: (Stream s Identity t, Show a) => Parsec s () a -> s -> IO ()
- parseTestLog :: (MonadIO m, MonadReader LogType m, Stream s m t, Show a) => ParsecT s () m a -> s -> m ()
- getPosition :: Monad m => ParsecT s u m SourcePos
- getInput :: Monad m => ParsecT s u m s
- setPosition :: Monad m => SourcePos -> ParsecT s u m ()
- setInput :: Monad m => s -> ParsecT s u m ()
- getParserState :: Monad m => ParsecT s u m (State s u)
- setParserState :: Monad m => State s u -> ParsecT s u m (State s u)
- updateParserState :: Monad m => (State s u -> State s u) -> ParsecT s u m (State s u)
- getState :: Monad m => ParsecT s u m u
- putState :: Monad m => u -> ParsecT s u m ()
- modifyState :: Monad m => (u -> u) -> ParsecT s u m ()
- setState :: Monad m => u -> ParsecT s u m ()
- updateState :: Monad m => (u -> u) -> ParsecT s u m ()
Documentation
unknownError :: State s u -> ParseError #
sysUnExpectError :: String -> SourcePos -> Reply s u a #
newtype ParsecT s u m a Source #
Constructors
ParsecT | |
Fields
|
Instances
MonadError e m => MonadError e (ParsecT s u m) Source # | |
MonadReader r m => MonadReader r (ParsecT s u m) Source # | |
MonadState s m => MonadState s (ParsecT s u m) Source # | |
MonadTrans (ParsecT s u) Source # | |
Monad (ParsecT s u m) Source # | |
Functor (ParsecT s u m) Source # | |
Applicative (ParsecT s u m) Source # | |
Alternative (ParsecT s u m) Source # | |
MonadPlus (ParsecT s u m) Source # | |
MonadCont m => MonadCont (ParsecT s u m) Source # | |
mkPT :: Monad m => (State s u -> m (Consumed (m (Reply s u a)))) -> ParsecT s u m a #
Low-level creation of the ParsecT type. You really shouldn't have to do this.
data State s u :: * -> * -> * #
Constructors
State | |
Fields
|
parserReturn :: a -> ParsecT s u m a Source #
mergeErrorReply :: ParseError -> Reply s u a -> Reply s u a #
parserFail :: String -> ParsecT s u m a Source #
parserZero :: ParsecT s u m a Source #
label :: ParsecT s u m a -> String -> ParsecT s u m a Source #
A synonym for <?>
, but as a function instead of an operator.
class Monad m => Stream s m t | s -> t where #
An instance of Stream
has stream type s
, underlying monad m
and token type t
determined by the stream
Some rough guidelines for a "correct" instance of Stream:
- unfoldM uncons gives the [t] corresponding to the stream
- A
Stream
instance is responsible for maintaining the "position within the stream" in the stream states
. This is trivial unless you are using the monad in a non-trivial way.
Minimal complete definition
tokens :: (Monad m, Stream s m t, Eq t) => ([t] -> String) -> (SourcePos -> [t] -> SourcePos) -> [t] -> ParsecT s u m [t] Source #
tokenPrimEx :: Stream s m t => (t -> String) -> (SourcePos -> t -> s -> SourcePos) -> Maybe (SourcePos -> t -> s -> u -> u) -> (t -> Maybe a) -> ParsecT s u m a Source #
runPT :: (Monad m, Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a) Source #
runPTLog :: (MonadIO m, MonadReader LogType m, Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a) Source #
runP :: Stream s Identity t => Parsec s u a -> u -> SourceName -> s -> Either ParseError a Source #
runParserT :: Stream s m t => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a) Source #
runParserTLog :: (MonadIO m, MonadReader LogType m, Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a) Source #
runParser :: Stream s Identity t => Parsec s u a -> u -> SourceName -> s -> Either ParseError a Source #
parse :: Stream s Identity t => Parsec s () a -> SourceName -> s -> Either ParseError a Source #
parseTestLog :: (MonadIO m, MonadReader LogType m, Stream s m t, Show a) => ParsecT s () m a -> s -> m () Source #
getPosition :: Monad m => ParsecT s u m SourcePos #
Returns the current source position. See also SourcePos
.
setPosition :: Monad m => SourcePos -> ParsecT s u m () #
setPosition pos
sets the current source position to pos
.
setInput :: Monad m => s -> ParsecT s u m () #
setInput input
continues parsing with input
. The getInput
and
setInput
functions can for example be used to deal with #include
files.
getParserState :: Monad m => ParsecT s u m (State s u) Source #
Returns the full parser state as a State
record.
setParserState :: Monad m => State s u -> ParsecT s u m (State s u) Source #
setParserState st
set the full parser state to st
.
updateParserState :: Monad m => (State s u -> State s u) -> ParsecT s u m (State s u) Source #
updateParserState f
applies function f
to the parser state.
modifyState :: Monad m => (u -> u) -> ParsecT s u m () Source #
modifyState f
applies function f
to the user state. Suppose
that we want to count identifiers in a source, we could use the user
state as:
expr = do{ x <- identifier ; modifyState (+1) ; return (Id x) }
setState :: Monad m => u -> ParsecT s u m () Source #
An alias for putState for backwards compatibility.
updateState :: Monad m => (u -> u) -> ParsecT s u m () Source #
An alias for modifyState for backwards compatibility.