Documentation
¶
Index ¶
- Variables
- type Alias
- type AnnAssign
- type Arg
- type Arguments
- type Assert
- type Assign
- type Attribute
- type AugAssign
- type Await
- type BinaryOp
- type BoolLit
- type BoolOp
- type Break
- type BytesLit
- type Call
- type ClassDef
- type Compare
- type Comprehension
- type Continue
- type Delete
- type Dict
- type DictComp
- type Ellipsis
- type ExceptHandler
- type Expr
- type ExprStmt
- type FStringLit
- type FStringPart
- type FloatLit
- type For
- type FunctionDef
- type GeneratorExpr
- type Global
- type Identifier
- type If
- type IfExpr
- type ImaginaryLit
- type Import
- type ImportFrom
- type IntLit
- type Keyword
- type Lambda
- type List
- type ListComp
- type Match
- type MatchAs
- type MatchCase
- type MatchClass
- type MatchMapping
- type MatchOr
- type MatchSequence
- type MatchSingleton
- type MatchStar
- type MatchValue
- type Module
- type NamedExpr
- type Node
- type NoneLit
- type Nonlocal
- type Pass
- type Pattern
- type Position
- type Raise
- type Return
- type Set
- type SetComp
- type Slice
- type Starred
- type Stmt
- type StringLit
- type Subscript
- type Token
- type TokenKind
- type Try
- type Tuple
- type TypeAlias
- type TypeParam
- type UnaryOp
- type While
- type With
- type WithItem
- type Yield
- type YieldFrom
Constants ¶
This section is empty.
Variables ¶
var Keywords = map[string]TokenKind{ "False": TK_False, "None": TK_None, "True": TK_True, "and": TK_And, "as": TK_As, "assert": TK_Assert, "async": TK_Async, "await": TK_Await, "break": TK_Break, "case": TK_Case, "class": TK_Class, "continue": TK_Continue, "def": TK_Def, "del": TK_Del, "elif": TK_Elif, "else": TK_Else, "except": TK_Except, "finally": TK_Finally, "for": TK_For, "from": TK_From, "global": TK_Global, "if": TK_If, "import": TK_Import, "in": TK_In, "is": TK_Is, "lambda": TK_Lambda, "match": TK_Match, "nonlocal": TK_Nonlocal, "not": TK_Not, "or": TK_Or, "pass": TK_Pass, "raise": TK_Raise, "return": TK_Return, "try": TK_Try, "while": TK_While, "with": TK_With, "yield": TK_Yield, }
Keywords maps Python keywords to their token kinds.
Functions ¶
This section is empty.
Types ¶
type Alias ¶
type Alias struct {
Name *Identifier
AsName *Identifier // can be nil
StartPos Position
EndPos Position
}
Alias represents an import alias.
type AnnAssign ¶
type AnnAssign struct {
Target Expr
Annotation Expr
Value Expr // can be nil
Simple bool
StartPos Position
}
AnnAssign represents an annotated assignment.
type Arg ¶
type Arg struct {
Arg *Identifier
Annotation Expr // can be nil
StartPos Position
EndPos Position
}
Arg represents a single argument.
type Arguments ¶
type Arguments struct {
PosOnlyArgs []*Arg
Args []*Arg
VarArg *Arg // *args
KwOnlyArgs []*Arg
KwDefaults []Expr // defaults for kwonly args
KwArg *Arg // **kwargs
Defaults []Expr // defaults for positional args
}
Arguments represents function arguments.
type Attribute ¶
type Attribute struct {
Value Expr
Attr *Identifier
}
Attribute represents attribute access (obj.attr).
type ClassDef ¶
type ClassDef struct {
Name *Identifier
Bases []Expr
Keywords []*Keyword
Body []Stmt
Decorators []Expr
StartPos Position
EndPos Position
}
ClassDef represents a class definition.
type Comprehension ¶
Comprehension represents a single for clause in a comprehension.
type Dict ¶
type Dict struct {
Keys []Expr // nil key means **unpacking
Values []Expr
StartPos Position
EndPos Position
}
Dict represents a dictionary {k: v, ...}.
type DictComp ¶
type DictComp struct {
Key Expr
Value Expr
Generators []*Comprehension
StartPos Position
EndPos Position
}
DictComp represents a dict comprehension {k: v for k, v in items}.
type ExceptHandler ¶
type ExceptHandler struct {
Type Expr // can be nil for bare except
Name *Identifier // can be nil
Body []Stmt
IsStar bool // true for "except* Type:"
StartPos Position
EndPos Position
}
ExceptHandler represents an except clause.
func (*ExceptHandler) End ¶
func (e *ExceptHandler) End() Position
func (*ExceptHandler) Pos ¶
func (e *ExceptHandler) Pos() Position
type Expr ¶
type Expr interface {
Node
// contains filtered or unexported methods
}
Expr is the interface for all expression nodes.
type FStringLit ¶
type FStringLit struct {
Parts []FStringPart
StartPos Position
EndPos Position
}
FStringLit represents an f-string literal like f"hello {name}".
func (*FStringLit) End ¶
func (f *FStringLit) End() Position
func (*FStringLit) Pos ¶
func (f *FStringLit) Pos() Position
type FStringPart ¶
type FStringPart struct {
IsExpr bool // true if this part is an expression, false if literal string
Value string // the literal string value (if IsExpr is false)
Expr Expr // the expression (if IsExpr is true)
FormatSpec string // optional format spec after ':'
Conversion byte // 0 for none, 'r' for !r, 's' for !s, 'a' for !a
}
FStringPart represents either a string literal or an expression in an f-string.
type For ¶
type For struct {
Target Expr
Iter Expr
Body []Stmt
OrElse []Stmt
IsAsync bool
StartPos Position
EndPos Position
}
For represents a for statement.
type FunctionDef ¶
type FunctionDef struct {
Name *Identifier
Args *Arguments
Body []Stmt
Decorators []Expr
Returns Expr // return type annotation, can be nil
IsAsync bool
StartPos Position
EndPos Position
}
FunctionDef represents a function definition.
func (*FunctionDef) End ¶
func (f *FunctionDef) End() Position
func (*FunctionDef) Pos ¶
func (f *FunctionDef) Pos() Position
type GeneratorExpr ¶
type GeneratorExpr struct {
Elt Expr
Generators []*Comprehension
StartPos Position
EndPos Position
}
GeneratorExpr represents a generator expression (x for x in xs).
func (*GeneratorExpr) End ¶
func (g *GeneratorExpr) End() Position
func (*GeneratorExpr) Pos ¶
func (g *GeneratorExpr) Pos() Position
type Global ¶
type Global struct {
Names []*Identifier
StartPos Position
EndPos Position
}
Global represents a global statement.
type Identifier ¶
Identifier represents a name/identifier.
func (*Identifier) End ¶
func (i *Identifier) End() Position
func (*Identifier) Pos ¶
func (i *Identifier) Pos() Position
type If ¶
type If struct {
Test Expr
Body []Stmt
OrElse []Stmt // can include elif (nested If) or else body
StartPos Position
EndPos Position
}
If represents an if statement.
type ImaginaryLit ¶
ImaginaryLit represents an imaginary number literal.
func (*ImaginaryLit) End ¶
func (i *ImaginaryLit) End() Position
func (*ImaginaryLit) Pos ¶
func (i *ImaginaryLit) Pos() Position
type ImportFrom ¶
type ImportFrom struct {
Module *Identifier // can be nil for relative imports
Names []*Alias
Level int // number of dots for relative import
StartPos Position
EndPos Position
}
ImportFrom represents a from ... import statement.
func (*ImportFrom) End ¶
func (i *ImportFrom) End() Position
func (*ImportFrom) Pos ¶
func (i *ImportFrom) Pos() Position
type Keyword ¶
type Keyword struct {
Arg *Identifier // nil for **kwargs
Value Expr
StartPos Position
}
Keyword represents a keyword argument in a call.
type ListComp ¶
type ListComp struct {
Elt Expr
Generators []*Comprehension
StartPos Position
EndPos Position
}
ListComp represents a list comprehension [x for x in xs].
type MatchAs ¶
type MatchAs struct {
Pattern Pattern // nil for wildcard _
Name *Identifier // nil for wildcard _
StartPos Position
EndPos Position
}
MatchAs represents an as pattern or wildcard.
type MatchCase ¶
type MatchCase struct {
Pattern Pattern
Guard Expr // can be nil
Body []Stmt
StartPos Position
EndPos Position
}
MatchCase represents a case in a match statement.
type MatchClass ¶
type MatchClass struct {
Cls Expr
Patterns []Pattern
KwdAttrs []*Identifier
KwdPatterns []Pattern
StartPos Position
EndPos Position
}
MatchClass represents a class pattern Cls(a, b=c).
func (*MatchClass) End ¶
func (m *MatchClass) End() Position
func (*MatchClass) Pos ¶
func (m *MatchClass) Pos() Position
type MatchMapping ¶
type MatchMapping struct {
Keys []Expr
Patterns []Pattern
Rest *Identifier // **rest, can be nil
StartPos Position
EndPos Position
}
MatchMapping represents a mapping pattern {k: v, ...}.
func (*MatchMapping) End ¶
func (m *MatchMapping) End() Position
func (*MatchMapping) Pos ¶
func (m *MatchMapping) Pos() Position
type MatchSequence ¶
MatchSequence represents a sequence pattern [a, b, c].
func (*MatchSequence) End ¶
func (m *MatchSequence) End() Position
func (*MatchSequence) Pos ¶
func (m *MatchSequence) Pos() Position
type MatchSingleton ¶
MatchSingleton represents True, False, or None in patterns.
func (*MatchSingleton) End ¶
func (m *MatchSingleton) End() Position
func (*MatchSingleton) Pos ¶
func (m *MatchSingleton) Pos() Position
type MatchStar ¶
type MatchStar struct {
Name *Identifier // can be nil for _
StartPos Position
EndPos Position
}
MatchStar represents a starred pattern *rest.
type MatchValue ¶
MatchValue represents a literal or constant pattern.
func (*MatchValue) End ¶
func (m *MatchValue) End() Position
func (*MatchValue) Pos ¶
func (m *MatchValue) Pos() Position
type NamedExpr ¶
type NamedExpr struct {
Target *Identifier
Value Expr
}
NamedExpr represents a named expression (walrus operator x := value).
type Nonlocal ¶
type Nonlocal struct {
Names []*Identifier
StartPos Position
EndPos Position
}
Nonlocal represents a nonlocal statement.
type Pattern ¶
type Pattern interface {
Node
// contains filtered or unexported methods
}
Pattern is the interface for match patterns.
type Raise ¶
type Raise struct {
Exc Expr // can be nil
Cause Expr // can be nil
StartPos Position
EndPos Position
}
Raise represents a raise statement.
type SetComp ¶
type SetComp struct {
Elt Expr
Generators []*Comprehension
StartPos Position
EndPos Position
}
SetComp represents a set comprehension {x for x in xs}.
type Slice ¶
type Slice struct {
Lower Expr // can be nil
Upper Expr // can be nil
Step Expr // can be nil
StartPos Position
EndPos Position
}
Slice represents a slice (lower:upper:step).
type Stmt ¶
type Stmt interface {
Node
// contains filtered or unexported methods
}
Stmt is the interface for all statement nodes.
type TokenKind ¶
type TokenKind int
TokenKind represents the type of a Python token.
const ( // Special tokens TK_Illegal TokenKind = iota TK_Newline TK_Indent TK_Dedent TK_Comment // Literals TK_Identifier TK_IntLit TK_FloatLit TK_ImaginaryLit TK_StringLit TK_BytesLit TK_FStringLit TK_FStringStart TK_FStringMiddle TK_FStringEnd // Keywords TK_False TK_None TK_True TK_And TK_As TK_Assert TK_Async TK_Await TK_Break TK_Case TK_Class TK_Continue TK_Def TK_Del TK_Elif TK_Else TK_Except TK_Finally TK_For TK_From TK_Global TK_If TK_Import TK_In TK_Is TK_Lambda TK_Match TK_Nonlocal TK_Not TK_Or TK_Pass TK_Raise TK_Return TK_Try TK_Type TK_While TK_With TK_Yield // Operators TK_Plus // + TK_Minus // - TK_Star // * TK_DoubleStar // ** TK_Slash // / TK_DoubleSlash // // TK_Percent // % TK_At // @ TK_LShift // << TK_RShift // >> TK_Ampersand // & TK_Pipe // | TK_Caret // ^ TK_Tilde // ~ TK_Walrus // := TK_Less // < TK_Greater // > TK_LessEqual // <= TK_GreaterEqual // >= TK_Equal // == TK_NotEqual // != TK_Arrow // -> TK_NotIn // not in (compound) TK_IsNot // is not (compound) // Delimiters TK_LParen // ( TK_RParen // ) TK_LBracket // [ TK_RBracket // ] TK_LBrace // { TK_RBrace // } TK_Comma // , TK_Colon // : TK_Semicolon // ; TK_Dot // . TK_Ellipsis // ... TK_Assign // = TK_PlusAssign // += TK_MinusAssign // -= TK_StarAssign // *= TK_SlashAssign // /= TK_DoubleSlashAssign // //= TK_PercentAssign // %= TK_AtAssign // @= TK_AmpersandAssign // &= TK_PipeAssign // |= TK_CaretAssign // ^= TK_RShiftAssign // >>= TK_LShiftAssign // <<= TK_DoubleStarAssign // **= TK_EOF )
func LookupIdent ¶
LookupIdent checks if an identifier is a keyword.
type Try ¶
type Try struct {
Body []Stmt
Handlers []*ExceptHandler
OrElse []Stmt
FinalBody []Stmt
StartPos Position
EndPos Position
}
Try represents a try statement.
type TypeAlias ¶
type TypeAlias struct {
Name *Identifier
TypeParams []*TypeParam
Value Expr
StartPos Position
EndPos Position
}
TypeAlias represents a type alias statement (type X = ...).
type TypeParam ¶
type TypeParam struct {
Name *Identifier
Bound Expr // can be nil
StartPos Position
EndPos Position
}
TypeParam represents a type parameter.