Copyright | (c) 2009 Bernie Pope |
---|---|
License | BSD-style |
Maintainer | bjpop@csse.unimelb.edu.au |
Stability | experimental |
Portability | ghc |
Safe Haskell | Safe |
Language | Haskell98 |
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
- | UnicodeStringToken {
- 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
- | AsyncToken {
- token_span :: !SrcSpan
- | AwaitToken {
- 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
- | MatrixMultAssignToken {
- 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
- = IndentToken {
- 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
Lexical tokens.
IndentToken | Indentation: increase. |
| |
DedentToken | Indentation: decrease. |
| |
NewlineToken | Newline. |
| |
LineJoinToken | Line join (backslash at end of line). |
| |
CommentToken | Single line comment. |
| |
IdentifierToken | Identifier. |
| |
StringToken | Literal: string. |
| |
ByteStringToken | Literal: byte string. |
| |
UnicodeStringToken | Literal: unicode string, version 2 only. |
| |
IntegerToken | Literal: integer. |
| |
LongIntegerToken | Literal: long integer. Version 2 only. |
| |
FloatToken | Literal: floating point. |
| |
ImaginaryToken | Literal: imaginary number. |
| |
DefToken | Keyword: 'def'. |
| |
WhileToken | Keyword: 'while'. |
| |
IfToken | Keyword: 'if'. |
| |
TrueToken | Keyword: 'True'. |
| |
FalseToken | Keyword: 'False'. |
| |
ReturnToken | Keyword: 'Return'. |
| |
TryToken | Keyword: 'try'. |
| |
ExceptToken | Keyword: 'except'. |
| |
RaiseToken | Keyword: 'raise'. |
| |
InToken | Keyword: 'in'. |
| |
IsToken | Keyword: 'is'. |
| |
LambdaToken | Keyword: 'lambda'. |
| |
ClassToken | Keyword: 'class'. |
| |
FinallyToken | Keyword: 'finally'. |
| |
NoneToken | Keyword: 'None'. |
| |
ForToken | Keyword: 'for'. |
| |
FromToken | Keyword: 'from'. |
| |
GlobalToken | Keyword: 'global'. |
| |
WithToken | Keyword: 'with'. |
| |
AsToken | Keyword: 'as'. |
| |
ElifToken | Keyword: 'elif'. |
| |
YieldToken | Keyword: 'yield'. |
| |
AssertToken | Keyword: 'assert'. |
| |
ImportToken | Keyword: 'import'. |
| |
PassToken | Keyword: 'pass'. |
| |
BreakToken | Keyword: 'break'. |
| |
ContinueToken | Keyword: 'continue'. |
| |
DeleteToken | Keyword: 'del'. |
| |
ElseToken | Keyword: 'else'. |
| |
NotToken | Keyword: 'not'. |
| |
AndToken | Keyword: boolean conjunction 'and'. |
| |
OrToken | Keyword: boolean disjunction 'or'. Version 3.x only: |
| |
NonLocalToken | Keyword: 'nonlocal' (Python 3.x only) |
| |
AsyncToken | Keyword: 'async' (Python 3.x only) |
| |
AwaitToken | Keyword: 'await' (Python 3.x only) Version 2.x only: |
| |
PrintToken | Keyword: 'print'. (Python 2.x only) |
| |
ExecToken | Keyword: 'exec'. (Python 2.x only) |
| |
AtToken | Delimiter: at sign '@'. |
| |
LeftRoundBracketToken | Delimiter: left round bracket '('. |
| |
RightRoundBracketToken | Delimiter: right round bracket ')'. |
| |
LeftSquareBracketToken | Delimiter: left square bracket '['. |
| |
RightSquareBracketToken | Delimiter: right square bracket ']'. |
| |
LeftBraceToken | Delimiter: left curly bracket '{'. |
| |
RightBraceToken | Delimiter: right curly bracket '}'. |
| |
DotToken | Delimiter: dot (full stop) '.'. |
| |
CommaToken | Delimiter: comma ','. |
| |
SemiColonToken | Delimiter: semicolon ';'. |
| |
ColonToken | Delimiter: colon ':'. |
| |
EllipsisToken | Delimiter: ellipses (three dots) '...'. |
| |
RightArrowToken | Delimiter: right facing arrow '->'. |
| |
AssignToken | Delimiter: assignment '='. |
| |
PlusAssignToken | Delimiter: plus assignment '+='. |
| |
MinusAssignToken | Delimiter: minus assignment '-='. |
| |
MultAssignToken | Delimiter: multiply assignment '*=' |
| |
DivAssignToken | Delimiter: divide assignment '/='. |
| |
ModAssignToken | Delimiter: modulus assignment '%='. |
| |
PowAssignToken | Delimiter: power assignment '**='. |
| |
BinAndAssignToken | Delimiter: binary-and assignment '&='. |
| |
BinOrAssignToken | Delimiter: binary-or assignment '|='. |
| |
BinXorAssignToken | Delimiter: binary-xor assignment '^='. |
| |
LeftShiftAssignToken | Delimiter: binary-left-shift assignment '<<='. |
| |
RightShiftAssignToken | Delimiter: binary-right-shift assignment '>>='. |
| |
FloorDivAssignToken | Delimiter: floor-divide assignment '//='. |
| |
MatrixMultAssignToken | Delimiter: matrix multiplication assignment '@='. |
| |
BackQuoteToken | Delimiter: back quote character '`\'. |
| |
PlusToken | Operator: plus '+'. |
| |
MinusToken | Operator: minus: '-'. |
| |
MultToken | Operator: multiply '*'. |
| |
DivToken | Operator: divide '/'. |
| |
GreaterThanToken | Operator: greater-than '>'. |
| |
LessThanToken | Operator: less-than '<'. |
| |
EqualityToken | Operator: equals '=='. |
| |
GreaterThanEqualsToken | Operator: greater-than-or-equals '>='. |
| |
LessThanEqualsToken | Operator: less-than-or-equals '<='. |
| |
ExponentToken | Operator: exponential '**'. |
| |
BinaryOrToken | Operator: binary-or '|'. |
| |
XorToken | Operator: binary-xor '^'. |
| |
BinaryAndToken | Operator: binary-and '&'. |
| |
ShiftLeftToken | Operator: binary-shift-left '<<'. |
| |
ShiftRightToken | Operator: binary-shift-right '>>'. |
| |
ModuloToken | Operator: modulus '%'. |
| |
FloorDivToken | Operator: floor-divide '//'. |
| |
TildeToken | Operator: tilde '~'. |
| |
NotEqualsToken | Operator: not-equals '!='. |
| |
NotEqualsV2Token | Operator: not-equals '<>'. Version 2 only. |
| |
EOFToken | End of file |
|
Instances
Eq Token Source # | |
Data Token Source # | |
Defined in Language.Python.Common.Token gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Token -> c Token # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Token # dataTypeOf :: Token -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Token) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Token) # gmapT :: (forall b. Data b => b -> b) -> Token -> Token # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Token -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Token -> r # gmapQ :: (forall d. Data d => d -> u) -> Token -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Token -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Token -> m Token # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Token -> m Token # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Token -> m Token # | |
Ord Token Source # | |
Show Token Source # | |
Pretty Token Source # | |
Span Token Source # | |
String conversion
debugTokenString :: Token -> String Source #
Produce a string from a token containing detailed information. Mainly intended for debugging.
tokenString :: Token -> String Source #
Produce a string from a token which is suitable for printing as Python concrete syntax. Invisible tokens yield an empty string.
Classification
hasLiteral :: Token -> Bool Source #
Test if a token contains its literal source text.
data TokenClass Source #
Classification of tokens
Instances
Eq TokenClass Source # | |
Defined in Language.Python.Common.Token (==) :: TokenClass -> TokenClass -> Bool # (/=) :: TokenClass -> TokenClass -> Bool # | |
Ord TokenClass Source # | |
Defined in Language.Python.Common.Token compare :: TokenClass -> TokenClass -> Ordering # (<) :: TokenClass -> TokenClass -> Bool # (<=) :: TokenClass -> TokenClass -> Bool # (>) :: TokenClass -> TokenClass -> Bool # (>=) :: TokenClass -> TokenClass -> Bool # max :: TokenClass -> TokenClass -> TokenClass # min :: TokenClass -> TokenClass -> TokenClass # | |
Show TokenClass Source # | |
Defined in Language.Python.Common.Token showsPrec :: Int -> TokenClass -> ShowS # show :: TokenClass -> String # showList :: [TokenClass] -> ShowS # |
classifyToken :: Token -> TokenClass Source #