{-# OPTIONS #-}
module Language.Python.Version2.Parser (
parseModule,
parseStmt,
parseExpr) where
import Language.Python.Version2.Parser.Parser (parseFileInput, parseSingleInput, parseEval)
import Language.Python.Version2.Parser.Lexer (initStartCodeStack)
import Language.Python.Common.AST (ModuleSpan, StatementSpan, ExprSpan)
import Language.Python.Common.Token (Token)
import Language.Python.Common.SrcLocation (initialSrcLocation)
import Language.Python.Common.ParserMonad (execParserKeepComments, ParseError, initialState)
parseModule :: String
-> String
-> Either ParseError (ModuleSpan, [Token])
parseModule :: String -> String -> Either ParseError (ModuleSpan, [Token])
parseModule String
input String
srcName =
P ModuleSpan
-> ParseState -> Either ParseError (ModuleSpan, [Token])
forall a. P a -> ParseState -> Either ParseError (a, [Token])
execParserKeepComments P ModuleSpan
parseFileInput ParseState
state
where
initLoc :: SrcLocation
initLoc = String -> SrcLocation
initialSrcLocation String
srcName
state :: ParseState
state = SrcLocation -> String -> [Int] -> ParseState
initialState SrcLocation
initLoc String
input [Int]
initStartCodeStack
parseStmt :: String
-> String
-> Either ParseError ([StatementSpan], [Token])
parseStmt :: String -> String -> Either ParseError ([StatementSpan], [Token])
parseStmt String
input String
srcName =
P [StatementSpan]
-> ParseState -> Either ParseError ([StatementSpan], [Token])
forall a. P a -> ParseState -> Either ParseError (a, [Token])
execParserKeepComments P [StatementSpan]
parseSingleInput ParseState
state
where
initLoc :: SrcLocation
initLoc = String -> SrcLocation
initialSrcLocation String
srcName
state :: ParseState
state = SrcLocation -> String -> [Int] -> ParseState
initialState SrcLocation
initLoc String
input [Int]
initStartCodeStack
parseExpr :: String
-> String
-> Either ParseError (ExprSpan, [Token])
parseExpr :: String -> String -> Either ParseError (ExprSpan, [Token])
parseExpr String
input String
srcName =
P ExprSpan -> ParseState -> Either ParseError (ExprSpan, [Token])
forall a. P a -> ParseState -> Either ParseError (a, [Token])
execParserKeepComments P ExprSpan
parseEval ParseState
state
where
initLoc :: SrcLocation
initLoc = String -> SrcLocation
initialSrcLocation String
srcName
state :: ParseState
state = SrcLocation -> String -> [Int] -> ParseState
initialState SrcLocation
initLoc String
input [Int]
initStartCodeStack