{-# OPTIONS #-}------------------------------------------------------------------------------- |-- Module : Language.Python.Version3.Lexer-- Copyright : (c) 2009 Bernie Pope -- License : BSD-style-- Maintainer : bjpop@csse.unimelb.edu.au-- Stability : experimental-- Portability : ghc---- Lexical analysis for Python version 3.x programs. -- See: <http://www.python.org/doc/3.1/reference/lexical_analysis.html>.-----------------------------------------------------------------------------moduleLanguage.Python.Version3.Lexer(-- * Lexical analysislex,lexOneToken,lexer,initLexState)whereimportPreludehiding(lex)importLanguage.Python.Version3.Parser.Lexer(lexToken,initStartCodeStack)importLanguage.Python.Common.TokenasTokenimportLanguage.Python.Common.SrcLocation(initialSrcLocation)importLanguage.Python.Common.ParserMonad(ParseState(input),P,runParser,execParser,ParseError,initialState)initLexState::String->String->ParseStateinitLexStateinputsrcName=initialState(initialSrcLocationsrcName)inputinitStartCodeStack-- | Parse a string into a list of Python Tokens, or return an error. lex::String-- ^ The input stream (python source code). ->String-- ^ The name of the python source (filename or input device).->EitherParseError[Token]-- ^ An error or a list of tokens.lexinputsrcName=execParserlexer$initLexStateinputsrcName-- | Try to lex the first token in an input string. Return either a parse error-- or a pair containing the next token and the rest of the input after the token.lexOneToken::String-- ^ The input stream (python source code).->String-- ^ The name of the python source (filename or input device).->EitherParseError(Token,String)-- ^ An error or the next token and the rest of the input after the token. lexOneTokensourcesrcName=caserunParserlexTokenstateofLefterr->LefterrRight(tok,state)->Right(tok,inputstate)wherestate=initLexStatesourcesrcName-- | Lex a sequence of tokens.lexer::P[Token]lexer=loop[]wherelooptoks=dotok<-lexTokencasetokofEOFToken{}->return(reversetoks)other->loop(tok:toks)