language-python-0.2: Parsing and pretty printing of Python code.Source codeContentsIndex
Language.Python.Common.Token
Portabilityghc
Stabilityexperimental
Maintainerbjpop@csse.unimelb.edu.au
Contents
The tokens
String conversion
Classification
Description
Lexical tokens for the Python lexer. Contains the superset of tokens from version 2 and version 3 of Python (they are mostly the same).
Synopsis
data Token
= IndentToken {
token_span :: !SrcSpan
}
| DedentToken {
token_span :: !SrcSpan
}
| NewlineToken {
token_span :: !SrcSpan
}
| LineJoinToken {
token_span :: !SrcSpan
}
| CommentToken {
token_span :: !SrcSpan
token_literal :: !String
}
| IdentifierToken {
token_span :: !SrcSpan
token_literal :: !String
}
| StringToken {
token_span :: !SrcSpan
token_literal :: !String
}
| ByteStringToken {
token_span :: !SrcSpan
token_literal :: !String
}
| IntegerToken {
token_span :: !SrcSpan
token_literal :: !String
token_integer :: !Integer
}
| LongIntegerToken {
token_span :: !SrcSpan
token_literal :: !String
token_integer :: !Integer
}
| FloatToken {
token_span :: !SrcSpan
token_literal :: !String
token_double :: !Double
}
| ImaginaryToken {
token_span :: !SrcSpan
token_literal :: !String
token_double :: !Double
}
| DefToken {
token_span :: !SrcSpan
}
| WhileToken {
token_span :: !SrcSpan
}
| IfToken {
token_span :: !SrcSpan
}
| TrueToken {
token_span :: !SrcSpan
}
| FalseToken {
token_span :: !SrcSpan
}
| ReturnToken {
token_span :: !SrcSpan
}
| TryToken {
token_span :: !SrcSpan
}
| ExceptToken {
token_span :: !SrcSpan
}
| RaiseToken {
token_span :: !SrcSpan
}
| InToken {
token_span :: !SrcSpan
}
| IsToken {
token_span :: !SrcSpan
}
| LambdaToken {
token_span :: !SrcSpan
}
| ClassToken {
token_span :: !SrcSpan
}
| FinallyToken {
token_span :: !SrcSpan
}
| NoneToken {
token_span :: !SrcSpan
}
| ForToken {
token_span :: !SrcSpan
}
| FromToken {
token_span :: !SrcSpan
}
| GlobalToken {
token_span :: !SrcSpan
}
| WithToken {
token_span :: !SrcSpan
}
| AsToken {
token_span :: !SrcSpan
}
| ElifToken {
token_span :: !SrcSpan
}
| YieldToken {
token_span :: !SrcSpan
}
| AssertToken {
token_span :: !SrcSpan
}
| ImportToken {
token_span :: !SrcSpan
}
| PassToken {
token_span :: !SrcSpan
}
| BreakToken {
token_span :: !SrcSpan
}
| ContinueToken {
token_span :: !SrcSpan
}
| DeleteToken {
token_span :: !SrcSpan
}
| ElseToken {
token_span :: !SrcSpan
}
| NotToken {
token_span :: !SrcSpan
}
| AndToken {
token_span :: !SrcSpan
}
| OrToken {
token_span :: !SrcSpan
}
| NonLocalToken {
token_span :: !SrcSpan
}
| PrintToken {
token_span :: !SrcSpan
}
| ExecToken {
token_span :: !SrcSpan
}
| AtToken {
token_span :: !SrcSpan
}
| LeftRoundBracketToken {
token_span :: !SrcSpan
}
| RightRoundBracketToken {
token_span :: !SrcSpan
}
| LeftSquareBracketToken {
token_span :: !SrcSpan
}
| RightSquareBracketToken {
token_span :: !SrcSpan
}
| LeftBraceToken {
token_span :: !SrcSpan
}
| RightBraceToken {
token_span :: !SrcSpan
}
| DotToken {
token_span :: !SrcSpan
}
| CommaToken {
token_span :: !SrcSpan
}
| SemiColonToken {
token_span :: !SrcSpan
}
| ColonToken {
token_span :: !SrcSpan
}
| EllipsisToken {
token_span :: !SrcSpan
}
| RightArrowToken {
token_span :: !SrcSpan
}
| AssignToken {
token_span :: !SrcSpan
}
| PlusAssignToken {
token_span :: !SrcSpan
}
| MinusAssignToken {
token_span :: !SrcSpan
}
| MultAssignToken {
token_span :: !SrcSpan
}
| DivAssignToken {
token_span :: !SrcSpan
}
| ModAssignToken {
token_span :: !SrcSpan
}
| PowAssignToken {
token_span :: !SrcSpan
}
| BinAndAssignToken {
token_span :: !SrcSpan
}
| BinOrAssignToken {
token_span :: !SrcSpan
}
| BinXorAssignToken {
token_span :: !SrcSpan
}
| LeftShiftAssignToken {
token_span :: !SrcSpan
}
| RightShiftAssignToken {
token_span :: !SrcSpan
}
| FloorDivAssignToken {
token_span :: !SrcSpan
}
| BackQuoteToken {
token_span :: !SrcSpan
}
| PlusToken {
token_span :: !SrcSpan
}
| MinusToken {
token_span :: !SrcSpan
}
| MultToken {
token_span :: !SrcSpan
}
| DivToken {
token_span :: !SrcSpan
}
| GreaterThanToken {
token_span :: !SrcSpan
}
| LessThanToken {
token_span :: !SrcSpan
}
| EqualityToken {
token_span :: !SrcSpan
}
| GreaterThanEqualsToken {
token_span :: !SrcSpan
}
| LessThanEqualsToken {
token_span :: !SrcSpan
}
| ExponentToken {
token_span :: !SrcSpan
}
| BinaryOrToken {
token_span :: !SrcSpan
}
| XorToken {
token_span :: !SrcSpan
}
| BinaryAndToken {
token_span :: !SrcSpan
}
| ShiftLeftToken {
token_span :: !SrcSpan
}
| ShiftRightToken {
token_span :: !SrcSpan
}
| ModuloToken {
token_span :: !SrcSpan
}
| FloorDivToken {
token_span :: !SrcSpan
}
| TildeToken {
token_span :: !SrcSpan
}
| NotEqualsToken {
token_span :: !SrcSpan
}
| NotEqualsV2Token {
token_span :: !SrcSpan
}
| EOFToken {
token_span :: !SrcSpan
}
debugTokenString :: Token -> String
tokenString :: Token -> String
hasLiteral :: Token -> Bool
data TokenClass
= Comment
| Number
| Identifier
| Punctuation
| Bracket
| Layout
| Keyword
| String
| Operator
| Assignment
classifyToken :: Token -> TokenClass
The tokens
data Token Source
Lexical tokens.
Constructors
IndentTokenIndentation: increase.
token_span :: !SrcSpan
DedentTokenIndentation: decrease.
token_span :: !SrcSpan
NewlineTokenNewline.
token_span :: !SrcSpan
LineJoinTokenLine join (backslash at end of line).
token_span :: !SrcSpan
CommentTokenSingle line comment.
token_span :: !SrcSpan
token_literal :: !String
IdentifierTokenIdentifier.
token_span :: !SrcSpan
token_literal :: !String
StringTokenLiteral: string.
token_span :: !SrcSpan
token_literal :: !String
ByteStringTokenLiteral: byte string.
token_span :: !SrcSpan
token_literal :: !String
IntegerTokenLiteral: integer.
token_span :: !SrcSpan
token_literal :: !String
token_integer :: !Integer
LongIntegerTokenLiteral: long integer. Version 2 only.
token_span :: !SrcSpan
token_literal :: !String
token_integer :: !Integer
FloatTokenLiteral: floating point.
token_span :: !SrcSpan
token_literal :: !String
token_double :: !Double
ImaginaryTokenLiteral: imaginary number.
token_span :: !SrcSpan
token_literal :: !String
token_double :: !Double
DefTokenKeyword: 'def'.
token_span :: !SrcSpan
WhileTokenKeyword: 'while'.
token_span :: !SrcSpan
IfTokenKeyword: 'if'.
token_span :: !SrcSpan
TrueTokenKeyword: 'True'.
token_span :: !SrcSpan
FalseTokenKeyword: 'False'.
token_span :: !SrcSpan
ReturnTokenKeyword: 'Return'.
token_span :: !SrcSpan
TryTokenKeyword: 'try'.
token_span :: !SrcSpan
ExceptTokenKeyword: 'except'.
token_span :: !SrcSpan
RaiseTokenKeyword: 'raise'.
token_span :: !SrcSpan
InTokenKeyword: 'in'.
token_span :: !SrcSpan
IsTokenKeyword: 'is'.
token_span :: !SrcSpan
LambdaTokenKeyword: 'lambda'.
token_span :: !SrcSpan
ClassTokenKeyword: 'class'.
token_span :: !SrcSpan
FinallyTokenKeyword: 'finally'.
token_span :: !SrcSpan
NoneTokenKeyword: 'None'.
token_span :: !SrcSpan
ForTokenKeyword: 'for'.
token_span :: !SrcSpan
FromTokenKeyword: 'from'.
token_span :: !SrcSpan
GlobalTokenKeyword: 'global'.
token_span :: !SrcSpan
WithTokenKeyword: 'with'.
token_span :: !SrcSpan
AsTokenKeyword: 'as'.
token_span :: !SrcSpan
ElifTokenKeyword: 'elif'.
token_span :: !SrcSpan
YieldTokenKeyword: 'yield'.
token_span :: !SrcSpan
AssertTokenKeyword: 'assert'.
token_span :: !SrcSpan
ImportTokenKeyword: 'import'.
token_span :: !SrcSpan
PassTokenKeyword: 'pass'.
token_span :: !SrcSpan
BreakTokenKeyword: 'break'.
token_span :: !SrcSpan
ContinueTokenKeyword: 'continue'.
token_span :: !SrcSpan
DeleteTokenKeyword: 'del'.
token_span :: !SrcSpan
ElseTokenKeyword: 'else'.
token_span :: !SrcSpan
NotTokenKeyword: 'not'.
token_span :: !SrcSpan
AndTokenKeyword: boolean conjunction 'and'.
token_span :: !SrcSpan
OrTokenKeyword: boolean disjunction 'or'. Version 3.x only:
token_span :: !SrcSpan
NonLocalTokenKeyword: 'nonlocal' (Python 3.x only) Version 2.x only:
token_span :: !SrcSpan
PrintTokenKeyword: 'print'. (Python 2.x only)
token_span :: !SrcSpan
ExecTokenKeyword: 'exec'. (Python 2.x only)
token_span :: !SrcSpan
AtTokenDelimiter: at sign '@'.
token_span :: !SrcSpan
LeftRoundBracketTokenDelimiter: left round bracket '('.
token_span :: !SrcSpan
RightRoundBracketTokenDelimiter: right round bracket ')'.
token_span :: !SrcSpan
LeftSquareBracketTokenDelimiter: left square bracket '['.
token_span :: !SrcSpan
RightSquareBracketTokenDelimiter: right square bracket ']'.
token_span :: !SrcSpan
LeftBraceTokenDelimiter: left curly bracket '{'.
token_span :: !SrcSpan
RightBraceTokenDelimiter: right curly bracket '}'.
token_span :: !SrcSpan
DotTokenDelimiter: dot (full stop) '.'.
token_span :: !SrcSpan
CommaTokenDelimiter: comma ','.
token_span :: !SrcSpan
SemiColonTokenDelimiter: semicolon ';'.
token_span :: !SrcSpan
ColonTokenDelimiter: colon ':'.
token_span :: !SrcSpan
EllipsisTokenDelimiter: ellipses (three dots) '...'.
token_span :: !SrcSpan
RightArrowTokenDelimiter: right facing arrow '->'.
token_span :: !SrcSpan
AssignTokenDelimiter: assignment '='.
token_span :: !SrcSpan
PlusAssignTokenDelimiter: plus assignment '+='.
token_span :: !SrcSpan
MinusAssignTokenDelimiter: minus assignment '-='.
token_span :: !SrcSpan
MultAssignTokenDelimiter: multiply assignment '*='
token_span :: !SrcSpan
DivAssignTokenDelimiter: divide assignment '/='.
token_span :: !SrcSpan
ModAssignTokenDelimiter: modulus assignment '%='.
token_span :: !SrcSpan
PowAssignTokenDelimiter: power assignment '**='.
token_span :: !SrcSpan
BinAndAssignTokenDelimiter: binary-and assignment '&='.
token_span :: !SrcSpan
BinOrAssignTokenDelimiter: binary-or assignment '|='.
token_span :: !SrcSpan
BinXorAssignTokenDelimiter: binary-xor assignment '^='.
token_span :: !SrcSpan
LeftShiftAssignTokenDelimiter: binary-left-shift assignment '<<='.
token_span :: !SrcSpan
RightShiftAssignTokenDelimiter: binary-right-shift assignment '>>='.
token_span :: !SrcSpan
FloorDivAssignTokenDelimiter: floor-divide assignment '='.
token_span :: !SrcSpan
BackQuoteTokenDelimiter: back quote character '`\'.
token_span :: !SrcSpan
PlusTokenOperator: plus '+'.
token_span :: !SrcSpan
MinusTokenOperator: minus: '-'.
token_span :: !SrcSpan
MultTokenOperator: multiply '*'.
token_span :: !SrcSpan
DivTokenOperator: divide '/'.
token_span :: !SrcSpan
GreaterThanTokenOperator: greater-than '>'.
token_span :: !SrcSpan
LessThanTokenOperator: less-than '<'.
token_span :: !SrcSpan
EqualityTokenOperator: equals '=='.
token_span :: !SrcSpan
GreaterThanEqualsTokenOperator: greater-than-or-equals '>='.
token_span :: !SrcSpan
LessThanEqualsTokenOperator: less-than-or-equals '<='.
token_span :: !SrcSpan
ExponentTokenOperator: exponential '**'.
token_span :: !SrcSpan
BinaryOrTokenOperator: binary-or '|'.
token_span :: !SrcSpan
XorTokenOperator: binary-xor '^'.
token_span :: !SrcSpan
BinaryAndTokenOperator: binary-and '&'.
token_span :: !SrcSpan
ShiftLeftTokenOperator: binary-shift-left '<<'.
token_span :: !SrcSpan
ShiftRightTokenOperator: binary-shift-right '>>'.
token_span :: !SrcSpan
ModuloTokenOperator: modulus '%'.
token_span :: !SrcSpan
FloorDivTokenOperator: floor-divide ''.
token_span :: !SrcSpan
TildeTokenOperator: tilde '~'.
token_span :: !SrcSpan
NotEqualsTokenOperator: not-equals '!='.
token_span :: !SrcSpan
NotEqualsV2TokenOperator: not-equals ''. Version 2 only.
token_span :: !SrcSpan
EOFTokenEnd of file
token_span :: !SrcSpan
show/hide Instances
String conversion
debugTokenString :: Token -> StringSource
Produce a string from a token containing detailed information. Mainly intended for debugging.
tokenString :: Token -> StringSource
Produce a string from a token which is suitable for printing as Python concrete syntax. Invisible tokens yield an empty string.
Classification
hasLiteral :: Token -> BoolSource
Test if a token contains its literal source text.
data TokenClass Source
Classification of tokens
Constructors
Comment
Number
Identifier
Punctuation
Bracket
Layout
Keyword
String
Operator
Assignment
show/hide Instances
classifyToken :: Token -> TokenClassSource
Produced by Haddock version 2.4.2