haskell-src-1.0.3.0: Support for manipulating Haskell source code

Copyright | (c) The GHC Team 1997-2000
License | BSD-style (see the file libraries/base/LICENSE)
Maintainer | libraries@haskell.org
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell98

Language.Haskell.ParseMonad

Contents

- Parsing
- Lexing

Description

Monads for the Haskell parser and lexer.

Synopsis

- data P a
- data ParseResult a
  - = ParseOk a
  - | ParseFailed SrcLoc String
- atSrcLoc :: P a -> SrcLoc -> P a
- data LexContext
  - = NoLayout
  - | Layout Int
- data ParseMode = ParseMode {
  - parseFilename :: String
  }
- defaultParseMode :: ParseMode
- runParserWithMode :: ParseMode -> P a -> String -> ParseResult a
- runParser :: P a -> String -> ParseResult a
- getSrcLoc :: P SrcLoc
- pushCurrentContext :: P ()
- popContext :: P ()
- data Lex r a
- getInput :: Lex r String
- discard :: Int -> Lex r ()
- lexNewline :: Lex a ()
- lexTab :: Lex a ()
- lexWhile :: (Char -> Bool) -> Lex a String
- alternative :: Lex a v -> Lex a (Lex a v)
- checkBOL :: Lex a Bool
- setBOL :: Lex a ()
- startToken :: Lex a ()
- getOffside :: Lex a Ordering
- pushContextL :: LexContext -> Lex a ()
- popContextL :: String -> Lex a ()

# Parsing

data P a #

Monad for parsing

Instances

Monad P # |
Instance details Defined in Language.Haskell.ParseMonad Methods (>>=) :: P a -> (a -> P b) -> P b # (>>) :: P a -> P b -> P b # return :: a -> P a # fail :: String -> P a #
Functor P # | Since: haskell-src-1.0.2.0
Instance details Defined in Language.Haskell.ParseMonad Methods fmap :: (a -> b) -> P a -> P b # (<$) :: a -> P b -> P a #
MonadFail P # | Since: haskell-src-1.0.3.0
Instance details Defined in Language.Haskell.ParseMonad Methods fail :: String -> P a #
Applicative P # | Since: haskell-src-1.0.2.0
Instance details Defined in Language.Haskell.ParseMonad Methods pure :: a -> P a # (<*>) :: P (a -> b) -> P a -> P b # liftA2 :: (a -> b -> c) -> P a -> P b -> P c # (*>) :: P a -> P b -> P b # (<*) :: P a -> P b -> P a #

data ParseResult a #

The result of a parse.

Constructors

ParseOk a | The parse succeeded, yielding a value.
ParseFailed SrcLoc String | The parse failed at the specified source location, with an error message.

Instances

Monad ParseResult # |
Instance details Defined in Language.Haskell.ParseMonad Methods (>>=) :: ParseResult a -> (a -> ParseResult b) -> ParseResult b # (>>) :: ParseResult a -> ParseResult b -> ParseResult b # return :: a -> ParseResult a # fail :: String -> ParseResult a #
Functor ParseResult # |
Instance details Defined in Language.Haskell.ParseMonad Methods fmap :: (a -> b) -> ParseResult a -> ParseResult b # (<$) :: a -> ParseResult b -> ParseResult a #
Applicative ParseResult # |
Instance details Defined in Language.Haskell.ParseMonad Methods pure :: a -> ParseResult a # (<*>) :: ParseResult (a -> b) -> ParseResult a -> ParseResult b # liftA2 :: (a -> b -> c) -> ParseResult a -> ParseResult b -> ParseResult c # (*>) :: ParseResult a -> ParseResult b -> ParseResult b # (<*) :: ParseResult a -> ParseResult b -> ParseResult a #
Show a => Show (ParseResult a) # |
Instance details Defined in Language.Haskell.ParseMonad Methods showsPrec :: Int -> ParseResult a -> ShowS # show :: ParseResult a -> String # showList :: [ParseResult a] -> ShowS #
Monoid m => Semigroup (ParseResult m) # | Since: haskell-src-1.0.3.0
Instance details Defined in Language.Haskell.ParseMonad Methods (<>) :: ParseResult m -> ParseResult m -> ParseResult m # sconcat :: NonEmpty (ParseResult m) -> ParseResult m # stimes :: Integral b => b -> ParseResult m -> ParseResult m #
Monoid m => Monoid (ParseResult m) # |
Instance details Defined in Language.Haskell.ParseMonad Methods mempty :: ParseResult m # mappend :: ParseResult m -> ParseResult m -> ParseResult m # mconcat :: [ParseResult m] -> ParseResult m #

atSrcLoc :: P a -> SrcLoc -> P a #

data LexContext #

Constructors

NoLayout |
Layout Int |

Instances

Eq LexContext # |
Instance details Defined in Language.Haskell.ParseMonad Methods (==) :: LexContext -> LexContext -> Bool # (/=) :: LexContext -> LexContext -> Bool #
Ord LexContext # |
Instance details Defined in Language.Haskell.ParseMonad Methods compare :: LexContext -> LexContext -> Ordering # (<) :: LexContext -> LexContext -> Bool # (<=) :: LexContext -> LexContext -> Bool # (>) :: LexContext -> LexContext -> Bool # (>=) :: LexContext -> LexContext -> Bool # max :: LexContext -> LexContext -> LexContext # min :: LexContext -> LexContext -> LexContext #
Show LexContext # |
Instance details Defined in Language.Haskell.ParseMonad Methods showsPrec :: Int -> LexContext -> ShowS # show :: LexContext -> String # showList :: [LexContext] -> ShowS #

data ParseMode #

Static parameters governing a parse. More to come later, e.g. literate mode, language extensions.

Constructors

ParseMode |
Fields parseFilename :: String original name of the file being parsed

defaultParseMode :: ParseMode #

Default parameters for a parse, currently just a marker for an unknown filename.

runParserWithMode :: ParseMode -> P a -> String -> ParseResult a #

runParser :: P a -> String -> ParseResult a #

getSrcLoc :: P SrcLoc #

pushCurrentContext :: P () #

popContext :: P () #

# Lexing

data Lex r a #

Instances

Monad (Lex r) # |
Instance details Defined in Language.Haskell.ParseMonad Methods (>>=) :: Lex r a -> (a -> Lex r b) -> Lex r b # (>>) :: Lex r a -> Lex r b -> Lex r b # return :: a -> Lex r a # fail :: String -> Lex r a #
Functor (Lex r) # | Since: haskell-src-1.0.2.0
Instance details Defined in Language.Haskell.ParseMonad Methods fmap :: (a -> b) -> Lex r a -> Lex r b # (<$) :: a -> Lex r b -> Lex r a #
MonadFail (Lex r) # | Since: haskell-src-1.0.3.0
Instance details Defined in Language.Haskell.ParseMonad Methods fail :: String -> Lex r a #
Applicative (Lex r) # | Since: haskell-src-1.0.2.0
Instance details Defined in Language.Haskell.ParseMonad Methods pure :: a -> Lex r a # (<*>) :: Lex r (a -> b) -> Lex r a -> Lex r b # liftA2 :: (a -> b -> c) -> Lex r a -> Lex r b -> Lex r c # (*>) :: Lex r a -> Lex r b -> Lex r b # (<*) :: Lex r a -> Lex r b -> Lex r a #

getInput :: Lex r String #

discard :: Int -> Lex r () #

Discard some input characters (these must not include tabs or newlines).

lexNewline :: Lex a () #

Discard the next character, which must be a newline.

lexTab :: Lex a () #

Discard the next character, which must be a tab.

lexWhile :: (Char -> Bool) -> Lex a String #

alternative :: Lex a v -> Lex a (Lex a v) #

checkBOL :: Lex a Bool #

setBOL :: Lex a () #

startToken :: Lex a () #

getOffside :: Lex a Ordering #

pushContextL :: LexContext -> Lex a () #

popContextL :: String -> Lex a () #