Portability | ghc |
---|---|
Stability | experimental |
Maintainer | bjpop@csse.unimelb.edu.au |
A lexer and set of tokens for Python version 3 programs. See: http://docs.python.org/dev/3.0/reference/lexical_analysis.html.
- lex :: String -> String -> Either ParseError [Token]
- lexOneToken :: String -> String -> Either ParseError (Token, String)
- data Token
- = Indent SrcLocation
- | Dedent SrcLocation
- | Newline SrcLocation
- | Identifier SrcLocation !String
- | String SrcLocation !String
- | ByteString SrcLocation !ByteString
- | Integer SrcLocation !Integer
- | Float SrcLocation !Double
- | Imaginary SrcLocation !Double
- | Def SrcLocation
- | While SrcLocation
- | If SrcLocation
- | True SrcLocation
- | False SrcLocation
- | Return SrcLocation
- | Try SrcLocation
- | Except SrcLocation
- | Raise SrcLocation
- | In SrcLocation
- | Is SrcLocation
- | Lambda SrcLocation
- | Class SrcLocation
- | Finally SrcLocation
- | None SrcLocation
- | For SrcLocation
- | From SrcLocation
- | NonLocal SrcLocation
- | Global SrcLocation
- | With SrcLocation
- | As SrcLocation
- | Elif SrcLocation
- | Yield SrcLocation
- | Assert SrcLocation
- | Import SrcLocation
- | Pass SrcLocation
- | Break SrcLocation
- | Continue SrcLocation
- | Delete SrcLocation
- | Else SrcLocation
- | Not SrcLocation
- | And SrcLocation
- | Or SrcLocation
- | At SrcLocation
- | LeftRoundBracket SrcLocation
- | RightRoundBracket SrcLocation
- | LeftSquareBracket SrcLocation
- | RightSquareBracket SrcLocation
- | LeftBrace SrcLocation
- | RightBrace SrcLocation
- | Dot SrcLocation
- | Comma SrcLocation
- | SemiColon SrcLocation
- | Colon SrcLocation
- | Ellipsis SrcLocation
- | RightArrow SrcLocation
- | Assign SrcLocation
- | PlusAssign SrcLocation
- | MinusAssign SrcLocation
- | MultAssign SrcLocation
- | DivAssign SrcLocation
- | ModAssign SrcLocation
- | PowAssign SrcLocation
- | BinAndAssign SrcLocation
- | BinOrAssign SrcLocation
- | BinXorAssign SrcLocation
- | LeftShiftAssign SrcLocation
- | RightShiftAssign SrcLocation
- | FloorDivAssign SrcLocation
- | Plus SrcLocation
- | Minus SrcLocation
- | Mult SrcLocation
- | Div SrcLocation
- | GreaterThan SrcLocation
- | LessThan SrcLocation
- | Equality SrcLocation
- | GreaterThanEquals SrcLocation
- | LessThanEquals SrcLocation
- | Exponent SrcLocation
- | BinaryOr SrcLocation
- | Xor SrcLocation
- | BinaryAnd SrcLocation
- | ShiftLeft SrcLocation
- | ShiftRight SrcLocation
- | Modulo SrcLocation
- | FloorDiv SrcLocation
- | Tilde SrcLocation
- | NotEquals SrcLocation
- | EOF
- newtype ParseError = ParseError ([String], SrcLocation)
Lexical analysis
:: String | The input stream (python source code). |
-> String | The name of the python source (filename or input device). |
-> Either ParseError [Token] | An error or a list of tokens. |
Parse a string into a list of Python Tokens, or return an error.
:: String | The input stream (python source code). |
-> String | The name of the python source (filename or input device). |
-> Either ParseError (Token, String) | An error or the next token and the rest of the input after the token. |
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.
Tokens
Lexical tokens.
Indent SrcLocation | Indentation: increase. |
Dedent SrcLocation | Indentation: decrease. |
Newline SrcLocation | Newline. |
Identifier SrcLocation !String | Identifier. |
String SrcLocation !String | Literal: string. |
ByteString SrcLocation !ByteString | Literal: byte string. |
Integer SrcLocation !Integer | Literal: integer. |
Float SrcLocation !Double | Literal: floating point. |
Imaginary SrcLocation !Double | Literal: imaginary number. |
Def SrcLocation | Keyword: 'def'. |
While SrcLocation | Keyword: 'while'. |
If SrcLocation | Keyword: 'if'. |
True SrcLocation | Keyword: 'True'. |
False SrcLocation | Keyword: 'False'. |
Return SrcLocation | Keyword: 'Return'. |
Try SrcLocation | Keyword: 'try'. |
Except SrcLocation | Keyword: 'except'. |
Raise SrcLocation | Keyword: 'raise'. |
In SrcLocation | Keyword: 'in'. |
Is SrcLocation | Keyword: 'is'. |
Lambda SrcLocation | Keyword: 'lambda'. |
Class SrcLocation | Keyword: 'class'. |
Finally SrcLocation | Keyword: 'finally'. |
None SrcLocation | Keyword: 'None' |
For SrcLocation | Keyword: 'for'. |
From SrcLocation | Keyword: 'from'. |
NonLocal SrcLocation | Keyword: 'nonlocal'. |
Global SrcLocation | Keyword: 'global'. |
With SrcLocation | Keyword: 'with'. |
As SrcLocation | Keyword: 'as'. |
Elif SrcLocation | Keyword: 'elif'. |
Yield SrcLocation | Keyword: 'yield'. |
Assert SrcLocation | Keyword: 'assert'. |
Import SrcLocation | Keyword: 'import'. |
Pass SrcLocation | Keyword: 'pass'. |
Break SrcLocation | Keyword: 'break'. |
Continue SrcLocation | Keyword: 'continue'. |
Delete SrcLocation | Keyword: 'del'. |
Else SrcLocation | Keyword: 'else'. |
Not SrcLocation | Keyword: 'not'. |
And SrcLocation | Keyword: boolean conjunction 'and'. |
Or SrcLocation | Keyword: boolean disjunction 'or'. |
At SrcLocation | Delimiter: at sign '@'. |
LeftRoundBracket SrcLocation | Delimiter: left round bracket '('. |
RightRoundBracket SrcLocation | Delimiter: right round bracket ')'. |
LeftSquareBracket SrcLocation | Delimiter: left square bracket '['. |
RightSquareBracket SrcLocation | Delimiter: right square bracket ']'. |
LeftBrace SrcLocation | Delimiter: left curly bracket '{'. |
RightBrace SrcLocation | Delimiter: right curly bracket '}'. |
Dot SrcLocation | Delimiter: dot (full stop) '.'. |
Comma SrcLocation | Delimiter: comma ','. |
SemiColon SrcLocation | Delimiter: semicolon ';'. |
Colon SrcLocation | Delimiter: colon ':'. |
Ellipsis SrcLocation | Delimiter: ellipses (three dots) '...'. |
RightArrow SrcLocation | Delimiter: right facing arrow '->'. |
Assign SrcLocation | Delimiter: assignment '='. |
PlusAssign SrcLocation | Delimiter: plus assignment '+='. |
MinusAssign SrcLocation | Delimiter: minus assignment '-='. |
MultAssign SrcLocation | Delimiter: multiply assignment '*=' |
DivAssign SrcLocation | Delimiter: divide assignment '/='. |
ModAssign SrcLocation | Delimiter: modulus assignment '%='. |
PowAssign SrcLocation | Delimiter: power assignment '**='. |
BinAndAssign SrcLocation | Delimiter: binary-and assignment '&='. |
BinOrAssign SrcLocation | Delimiter: binary-or assignment '|='. |
BinXorAssign SrcLocation | Delimiter: binary-xor assignment '^='. |
LeftShiftAssign SrcLocation | Delimiter: binary-left-shift assignment '<<='. |
RightShiftAssign SrcLocation | Delimiter: binary-right-shift assignment '>>='. |
FloorDivAssign SrcLocation | Delimiter: floor-divide assignment '='. |
Plus SrcLocation | Operator: plus '+'. |
Minus SrcLocation | Operator: minus: '-'. |
Mult SrcLocation | Operator: multiply '*'. |
Div SrcLocation | Operator: divide '/'. |
GreaterThan SrcLocation | Operator: greater-than '>'. |
LessThan SrcLocation | Operator: less-than '<'. |
Equality SrcLocation | Operator: equals '=='. |
GreaterThanEquals SrcLocation | Operator: greater-than-or-equals '>='. |
LessThanEquals SrcLocation | Operator: less-than-or-equals '<='. |
Exponent SrcLocation | Operator: exponential '**'. |
BinaryOr SrcLocation | Operator: binary-or '|'. |
Xor SrcLocation | Operator: binary-xor '^'. |
BinaryAnd SrcLocation | Operator: binary-and '&'. |
ShiftLeft SrcLocation | Operator: binary-shift-left '<<'. |
ShiftRight SrcLocation | Operator: binary-shift-right '>>'. |
Modulo SrcLocation | Operator: modulus '%'. |
FloorDiv SrcLocation | Operator: floor-divide ''. |
Tilde SrcLocation | Operator: tilde '~'. |
NotEquals SrcLocation | Operator: not-equals '!='. |
EOF | End of file (no source location). |
Parse errors
newtype ParseError Source
Parse error. A list of error messages and a source location.
ParseError ([String], SrcLocation) |