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

Portability | portable
Stability | experimental
Maintainer | libraries@haskell.org
Safe Haskell | None

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

Monad P |

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

Monad ParseResult |
Functor ParseResult |
Applicative ParseResult |
Show a => Show (ParseResult a) |
Monoid m => Monoid (ParseResult m) |

atSrcLoc :: P a -> SrcLoc -> P aSource

data LexContext Source

Constructors

NoLayout |
Layout Int |

Instances

Eq LexContext |
Ord LexContext |
Show LexContext |

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 aSource

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

getSrcLoc :: P SrcLoc Source

pushCurrentContext :: P ()Source

popContext :: P ()Source

# Lexing

data Lex r a Source

Instances

Monad (Lex r) |

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