Language.Python.Common.ParserMonad

language-python-0.5.4: Parsing and pretty printing of Python code.

Copyright | (c) 2009 Bernie Pope
License | BSD-style
Maintainer | bjpop@csse.unimelb.edu.au
Stability | experimental
Portability | ghc
Safe Haskell | Safe
Language | Haskell98

Language.Python.Common.ParserMonad

Description

Monad support for Python parser and lexer.

# Documentation

type P a = StateT ParseState (Either ParseError) a #

execParser :: P a -> ParseState -> Either ParseError a #

execParserKeepComments :: P a -> ParseState -> Either ParseError (a, [Token]) #

runParser :: P a -> ParseState -> Either ParseError (a, ParseState) #

thenP :: P a -> (a -> P b) -> P b #

returnP :: a -> P a #

setLocation :: SrcLocation -> P () #

getLocation :: P SrcLocation #

getInput :: P String #

setInput :: String -> P () #

getLastToken :: P Token #

setLastToken :: Token -> P () #

setLastEOL :: SrcSpan -> P () #

getLastEOL :: P SrcSpan #

data ParseError #

Constructors

UnexpectedToken Token | An error from the parser. Token found where it should not be. Note: tokens contain their own source span.
UnexpectedChar Char SrcLocation | An error from the lexer. Character found where it should not be.
StrError String | A generic error containing a string message. No source location.

Instances

Eq ParseError # |
Methods (==) :: ParseError -> ParseError -> Bool # (/=) :: ParseError -> ParseError -> Bool #
Ord ParseError # |
Methods compare :: ParseError -> ParseError -> Ordering # (<) :: ParseError -> ParseError -> Bool # (<=) :: ParseError -> ParseError -> Bool # (>) :: ParseError -> ParseError -> Bool # (>=) :: ParseError -> ParseError -> Bool # max :: ParseError -> ParseError -> ParseError # min :: ParseError -> ParseError -> ParseError #
Show ParseError # |
Methods showsPrec :: Int -> ParseError -> ShowS # show :: ParseError -> String # showList :: [ParseError] -> ShowS #
Error ParseError # |
Methods noMsg :: ParseError # strMsg :: String -> ParseError #

data ParseState #

Constructors

ParseState |
Fields location :: !SrcLocation input :: !String previousToken :: !Token startCodeStack :: [Int] indentStack :: [Int] parenStack :: [Token] lastEOL :: !SrcSpan comments :: [Token]

Instances

Show ParseState # |
Methods showsPrec :: Int -> ParseState -> ShowS # show :: ParseState -> String # showList :: [ParseState] -> ShowS #

initialState :: SrcLocation -> String -> [Int] -> ParseState #

pushStartCode :: Int -> P () #

popStartCode :: P () #

getStartCode :: P Int #

getIndent :: P Int #

pushIndent :: Int -> P () #

popIndent :: P () #

getIndentStackDepth :: P Int #

getParen :: P (Maybe Token) #

pushParen :: Token -> P () #

popParen :: P () #

getParenStackDepth :: P Int #

addComment :: Token -> P () #

getComments :: P [Token] #

spanError :: Span a => a -> String -> P b #