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

Copyright | (c) The GHC Team 1997-2000
License | BSD-3-Clause
Maintainer | Andreas Abel
Stability | stable
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 Source #

Monad for parsing

#### Instances

Instances details

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

data ParseResult a Source #

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

Instances details

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

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

data LexContext Source #

Constructors

NoLayout |
Layout Int |

#### Instances

Instances details

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

Instance details

Defined in Language.Haskell.ParseMonad

Methods

compare :: LexContext -> LexContext -> Ordering Source #

(<) :: LexContext -> LexContext -> Bool Source #

(<=) :: LexContext -> LexContext -> Bool Source #

(>) :: LexContext -> LexContext -> Bool Source #

(>=) :: LexContext -> LexContext -> Bool Source #

max :: LexContext -> LexContext -> LexContext Source #

min :: LexContext -> LexContext -> LexContext Source #

data ParseMode Source #

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 Source #

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

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

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

getSrcLoc :: P SrcLoc Source #

pushCurrentContext :: P () Source #

popContext :: P () Source #

# Lexing

data Lex r a Source #

#### Instances

Instances details

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

getInput :: Lex r String Source #

discard :: Int -> Lex r () Source #

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

lexNewline :: Lex a () Source #

Discard the next character, which must be a newline.

lexTab :: Lex a () Source #

Discard the next character, which must be a tab.

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

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

checkBOL :: Lex a Bool Source #

setBOL :: Lex a () Source #

startToken :: Lex a () Source #

getOffside :: Lex a Ordering Source #

pushContextL :: LexContext -> Lex a () Source #

popContextL :: String -> Lex a () Source #