ast

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2023 License: BSD-3-Clause Imports: 4 Imported by: 19

Documentation

Index

Constants

View Source
const (
	Load = ExprContext(iota + 1)
	Store
	Del
	AugLoad
	AugStore
	Param
)
View Source
const (
	And = BoolOpNumber(iota + 1)
	Or
)
View Source
const (
	Add = OperatorNumber(iota + 1)
	Sub
	Mult
	Div
	Modulo
	Pow
	LShift
	RShift
	BitOr
	BitXor
	BitAnd
	FloorDiv
)
View Source
const (
	Invert = UnaryOpNumber(iota + 1)
	Not
	UAdd
	USub
)
View Source
const (
	Eq = CmpOp(iota + 1)
	NotEq
	Lt
	LtE
	Gt
	GtE
	Is
	IsNot
	In
	NotIn
)

Variables

View Source
var ASTType = py.ObjectType.NewTypeFlags("AST", "AST Node", nil, nil, py.ObjectType.Flags|py.TPFLAGS_BASE_EXC_SUBCLASS)

Python types

View Source
var AliasType = ASTType.NewType("Alias", "Alias Node", nil, nil)
View Source
var ArgType = ASTType.NewType("Arg", "Arg Node", nil, nil)
View Source
var ArgumentsType = ASTType.NewType("Arguments", "Arguments Node", nil, nil)
View Source
var AssertType = StmtBaseType.NewType("Assert", "Assert Node", nil, nil)
View Source
var AssignType = StmtBaseType.NewType("Assign", "Assign Node", nil, nil)
View Source
var AttributeType = ExprBaseType.NewType("Attribute", "Attribute Node", nil, nil)
View Source
var AugAssignType = StmtBaseType.NewType("AugAssign", "AugAssign Node", nil, nil)
View Source
var BinOpType = ExprBaseType.NewType("BinOp", "BinOp Node", nil, nil)
View Source
var BoolOpType = ExprBaseType.NewType("BoolOp", "BoolOp Node", nil, nil)
View Source
var BreakType = StmtBaseType.NewType("Break", "Break Node", nil, nil)
View Source
var BytesType = ExprBaseType.NewType("Bytes", "Bytes Node", nil, nil)
View Source
var CallType = ExprBaseType.NewType("Call", "Call Node", nil, nil)
View Source
var ClassDefType = StmtBaseType.NewType("ClassDef", "ClassDef Node", nil, nil)
View Source
var CompareType = ExprBaseType.NewType("Compare", "Compare Node", nil, nil)
View Source
var ContinueType = StmtBaseType.NewType("Continue", "Continue Node", nil, nil)
View Source
var DeleteType = StmtBaseType.NewType("Delete", "Delete Node", nil, nil)
View Source
var DictCompType = ExprBaseType.NewType("DictComp", "DictComp Node", nil, nil)
View Source
var DictType = ExprBaseType.NewType("Dict", "Dict Node", nil, nil)
View Source
var EllipsisType = ExprBaseType.NewType("Ellipsis", "Ellipsis Node", nil, nil)
View Source
var ExceptHandlerType = ASTType.NewType("ExceptHandler", "ExceptHandler Node", nil, nil)

Misc

View Source
var ExprBaseType = ASTType.NewType("Expr", "Expr Node", nil, nil)

Expr

View Source
var ExprStmtType = StmtBaseType.NewType("ExprStmt", "ExprStmt Node", nil, nil)
View Source
var ExpressionType = ModBaseType.NewType("Expression", "Expression Node", nil, nil)
View Source
var ExtSliceType = SliceBaseType.NewType("ExtSlice", "ExtSlice Node", nil, nil)
View Source
var ForType = StmtBaseType.NewType("For", "For Node", nil, nil)
View Source
var FunctionDefType = StmtBaseType.NewType("FunctionDef", "FunctionDef Node", nil, nil)
View Source
var GeneratorExpType = ExprBaseType.NewType("GeneratorExp", "GeneratorExp Node", nil, nil)
View Source
var GlobalType = StmtBaseType.NewType("Global", "Global Node", nil, nil)
View Source
var IfExpType = ExprBaseType.NewType("IfExp", "IfExp Node", nil, nil)
View Source
var IfType = StmtBaseType.NewType("If", "If Node", nil, nil)
View Source
var ImportFromType = StmtBaseType.NewType("ImportFrom", "ImportFrom Node", nil, nil)
View Source
var ImportType = StmtBaseType.NewType("Import", "Import Node", nil, nil)
View Source
var IndexType = SliceBaseType.NewType("Index", "Index Node", nil, nil)
View Source
var InteractiveType = ModBaseType.NewType("Interactive", "Interactive Node", nil, nil)
View Source
var KeywordType = ASTType.NewType("Keyword", "Keyword Node", nil, nil)
View Source
var LambdaType = ExprBaseType.NewType("Lambda", "Lambda Node", nil, nil)
View Source
var ListCompType = ExprBaseType.NewType("ListComp", "ListComp Node", nil, nil)
View Source
var ListType = ExprBaseType.NewType("List", "List Node", nil, nil)
View Source
var ModBaseType = ASTType.NewType("Mod", "Mod Node", nil, nil)

Mod

View Source
var ModuleType = ModBaseType.NewType("Module", "Module Node", nil, nil)
View Source
var NameConstantType = ExprBaseType.NewType("NameConstant", "NameConstant Node", nil, nil)
View Source
var NameType = ExprBaseType.NewType("Name", "Name Node", nil, nil)
View Source
var NonlocalType = StmtBaseType.NewType("Nonlocal", "Nonlocal Node", nil, nil)
View Source
var NumType = ExprBaseType.NewType("Num", "Num Node", nil, nil)
View Source
var PassType = StmtBaseType.NewType("Pass", "Pass Node", nil, nil)
View Source
var RaiseType = StmtBaseType.NewType("Raise", "Raise Node", nil, nil)
View Source
var ReturnType = StmtBaseType.NewType("Return", "Return Node", nil, nil)
View Source
var SetCompType = ExprBaseType.NewType("SetComp", "SetComp Node", nil, nil)
View Source
var SetType = ExprBaseType.NewType("Set", "Set Node", nil, nil)
View Source
var SliceBaseType = ASTType.NewType("SliceBase", "SliceBase Node", nil, nil)
View Source
var SliceType = SliceBaseType.NewType("Slice", "Slice Node", nil, nil)

Slicer

View Source
var StarredType = ExprBaseType.NewType("Starred", "Starred Node", nil, nil)
View Source
var StmtBaseType = ASTType.NewType("Stmt", "Stmt Node", nil, nil)

Stmt

View Source
var StrType = ExprBaseType.NewType("Str", "Str Node", nil, nil)
View Source
var SubscriptType = ExprBaseType.NewType("Subscript", "Subscript Node", nil, nil)
View Source
var SuiteType = ModBaseType.NewType("Suite", "Suite Node", nil, nil)
View Source
var TryType = StmtBaseType.NewType("Try", "Try Node", nil, nil)
View Source
var TupleType = ExprBaseType.NewType("Tuple", "Tuple Node", nil, nil)
View Source
var UnaryOpType = ExprBaseType.NewType("UnaryOp", "UnaryOp Node", nil, nil)
View Source
var WhileType = StmtBaseType.NewType("While", "While Node", nil, nil)
View Source
var WithItemType = ASTType.NewType("WithItem", "WithItem Node", nil, nil)
View Source
var WithType = StmtBaseType.NewType("With", "With Node", nil, nil)
View Source
var YieldFromType = ExprBaseType.NewType("YieldFrom", "YieldFrom Node", nil, nil)
View Source
var YieldType = ExprBaseType.NewType("Yield", "Yield Node", nil, nil)

Functions

func Dump

func Dump(ast Ast) string

Dump an Ast node as a string

func Walk

func Walk(ast Ast, Visit func(Ast) bool)

Walk calls Visit on every node in the ast. The parent is visited first, then the children

Visit returns true to continue the walk

Types

type AST

type AST struct {
	Pos
}

Base AST node

func (*AST) Type

func (o *AST) Type() *py.Type

Python type definitions

type Alias

type Alias struct {
	Pos
	Name   Identifier
	AsName Identifier
}

func (*Alias) Type

func (o *Alias) Type() *py.Type

type Arg

type Arg struct {
	Pos
	Arg        Identifier
	Annotation Expr
}

func (*Arg) Type

func (o *Arg) Type() *py.Type

type Arguments

type Arguments struct {
	Pos
	Args       []*Arg
	Vararg     *Arg
	Kwonlyargs []*Arg
	KwDefaults []Expr
	Kwarg      *Arg
	Defaults   []Expr
}

func (*Arguments) Type

func (o *Arguments) Type() *py.Type

type Assert

type Assert struct {
	StmtBase
	Test Expr
	Msg  Expr
}

func (*Assert) Type

func (o *Assert) Type() *py.Type

type Assign

type Assign struct {
	StmtBase
	Targets []Expr
	Value   Expr
}

func (*Assign) Type

func (o *Assign) Type() *py.Type

type Ast

type Ast interface {
	py.Object
	GetLineno() int
	GetColOffset() int
}

All node types implement the Ast interface

type Attribute

type Attribute struct {
	ExprBase
	Value Expr
	Attr  Identifier
	Ctx   ExprContext
}

func (*Attribute) SetCtx

func (o *Attribute) SetCtx(Ctx ExprContext)

func (*Attribute) Type

func (o *Attribute) Type() *py.Type

type AugAssign

type AugAssign struct {
	StmtBase
	Target Expr
	Op     OperatorNumber
	Value  Expr
}

func (*AugAssign) Type

func (o *AugAssign) Type() *py.Type

type BinOp

type BinOp struct {
	ExprBase
	Left  Expr
	Op    OperatorNumber
	Right Expr
}

func (*BinOp) Type

func (o *BinOp) Type() *py.Type

type BoolOp

type BoolOp struct {
	ExprBase
	Op     BoolOpNumber
	Values []Expr
}

func (*BoolOp) Type

func (o *BoolOp) Type() *py.Type

type BoolOpNumber

type BoolOpNumber int

func (BoolOpNumber) String

func (o BoolOpNumber) String() string

type Break

type Break struct {
	StmtBase
}

func (*Break) Type

func (o *Break) Type() *py.Type

type Bytes

type Bytes struct {
	ExprBase
	S py.Bytes
}

func (*Bytes) Type

func (o *Bytes) Type() *py.Type

type Call

type Call struct {
	ExprBase
	Func     Expr
	Args     []Expr
	Keywords []*Keyword
	Starargs Expr
	Kwargs   Expr
}

func (*Call) Type

func (o *Call) Type() *py.Type

type ClassDef

type ClassDef struct {
	StmtBase
	Name          Identifier
	Bases         []Expr
	Keywords      []*Keyword
	Starargs      Expr
	Kwargs        Expr
	Body          []Stmt
	DecoratorList []Expr
}

func (*ClassDef) Type

func (o *ClassDef) Type() *py.Type

type CmpOp

type CmpOp int

func (CmpOp) String

func (o CmpOp) String() string

type Compare

type Compare struct {
	ExprBase
	Left        Expr
	Ops         []CmpOp
	Comparators []Expr
}

need sequences for compare to distinguish between

func (*Compare) Type

func (o *Compare) Type() *py.Type

type Comprehension

type Comprehension struct {
	Target Expr
	Iter   Expr
	Ifs    []Expr
}

type Continue

type Continue struct {
	StmtBase
}

func (*Continue) Type

func (o *Continue) Type() *py.Type

type Delete

type Delete struct {
	StmtBase
	Targets []Expr
}

func (*Delete) Type

func (o *Delete) Type() *py.Type

type Dict

type Dict struct {
	ExprBase
	Keys   []Expr
	Values []Expr
}

func (*Dict) Type

func (o *Dict) Type() *py.Type

type DictComp

type DictComp struct {
	ExprBase
	Key        Expr
	Value      Expr
	Generators []Comprehension
}

func (*DictComp) Type

func (o *DictComp) Type() *py.Type

type Ellipsis

type Ellipsis struct {
	ExprBase
}

func (*Ellipsis) Type

func (o *Ellipsis) Type() *py.Type

type ExceptHandler

type ExceptHandler struct {
	Pos
	ExprType Expr
	Name     Identifier
	Body     []Stmt
}

func (*ExceptHandler) Type

func (o *ExceptHandler) Type() *py.Type

type Expr

type Expr interface {
	Ast
	// contains filtered or unexported methods
}

All ExprBase notes implement the Expr interface

type ExprBase

type ExprBase struct{ Pos }

func (*ExprBase) Type

func (o *ExprBase) Type() *py.Type

type ExprContext

type ExprContext int

func (ExprContext) String

func (o ExprContext) String() string

type ExprStmt

type ExprStmt struct {
	StmtBase
	Value Expr
}

func (*ExprStmt) Type

func (o *ExprStmt) Type() *py.Type

type Expression

type Expression struct {
	ModBase
	Body Expr
}

func (*Expression) Type

func (o *Expression) Type() *py.Type

type ExtSlice

type ExtSlice struct {
	SliceBase
	Dims []Slicer
}

func (*ExtSlice) Type

func (o *ExtSlice) Type() *py.Type

type For

type For struct {
	StmtBase
	Target Expr
	Iter   Expr
	Body   []Stmt
	Orelse []Stmt
}

func (*For) Type

func (o *For) Type() *py.Type

type FunctionDef

type FunctionDef struct {
	StmtBase
	Name          Identifier
	Args          *Arguments
	Body          []Stmt
	DecoratorList []Expr
	Returns       Expr
}

func (*FunctionDef) Type

func (o *FunctionDef) Type() *py.Type

type GeneratorExp

type GeneratorExp struct {
	ExprBase
	Elt        Expr
	Generators []Comprehension
}

func (*GeneratorExp) Type

func (o *GeneratorExp) Type() *py.Type

type Global

type Global struct {
	StmtBase
	Names []Identifier
}

func (*Global) Type

func (o *Global) Type() *py.Type

type Identifier

type Identifier py.String

type If

type If struct {
	StmtBase
	Test   Expr
	Body   []Stmt
	Orelse []Stmt
}

func (*If) Type

func (o *If) Type() *py.Type

type IfExp

type IfExp struct {
	ExprBase
	Test   Expr
	Body   Expr
	Orelse Expr
}

func (*IfExp) Type

func (o *IfExp) Type() *py.Type

type Import

type Import struct {
	StmtBase
	Names []*Alias
}

func (*Import) Type

func (o *Import) Type() *py.Type

type ImportFrom

type ImportFrom struct {
	StmtBase
	Module Identifier
	Names  []*Alias
	Level  int
}

func (*ImportFrom) Type

func (o *ImportFrom) Type() *py.Type

type Index

type Index struct {
	SliceBase
	Value Expr
}

func (*Index) Type

func (o *Index) Type() *py.Type

type Interactive

type Interactive struct {
	ModBase
	Body []Stmt
}

func (*Interactive) Type

func (o *Interactive) Type() *py.Type

type Keyword

type Keyword struct {
	Pos
	Arg   Identifier
	Value Expr
}

func (*Keyword) Type

func (o *Keyword) Type() *py.Type

type Lambda

type Lambda struct {
	ExprBase
	Args *Arguments
	Body Expr
}

func (*Lambda) Type

func (o *Lambda) Type() *py.Type

type List

type List struct {
	ExprBase
	Elts []Expr
	Ctx  ExprContext
}

func (*List) SetCtx

func (o *List) SetCtx(Ctx ExprContext)

func (*List) Type

func (o *List) Type() *py.Type

type ListComp

type ListComp struct {
	ExprBase
	Elt        Expr
	Generators []Comprehension
}

func (*ListComp) Type

func (o *ListComp) Type() *py.Type

type Mod

type Mod interface {
	Ast
	// contains filtered or unexported methods
}

All ModBase nodes implement the Mod interface

type ModBase

type ModBase struct {
	Pos
}

func (*ModBase) Type

func (o *ModBase) Type() *py.Type

type Module

type Module struct {
	ModBase
	Body []Stmt
}

func (*Module) Type

func (o *Module) Type() *py.Type

type Name

type Name struct {
	ExprBase
	Id  Identifier
	Ctx ExprContext
}

func (*Name) SetCtx

func (o *Name) SetCtx(Ctx ExprContext)

func (*Name) Type

func (o *Name) Type() *py.Type

type NameConstant

type NameConstant struct {
	ExprBase
	Value Singleton
}

func (*NameConstant) Type

func (o *NameConstant) Type() *py.Type

type Nonlocal

type Nonlocal struct {
	StmtBase
	Names []Identifier
}

func (*Nonlocal) Type

func (o *Nonlocal) Type() *py.Type

type Num

type Num struct {
	ExprBase
	N Object
}

func (*Num) Type

func (o *Num) Type() *py.Type

type Object

type Object py.Object

type OperatorNumber

type OperatorNumber int

func (OperatorNumber) String

func (o OperatorNumber) String() string

type Pass

type Pass struct {
	StmtBase
}

func (*Pass) Type

func (o *Pass) Type() *py.Type

type Pos

type Pos struct {
	Lineno    int
	ColOffset int
}

Position in the parse tree

func (*Pos) GetColOffset

func (o *Pos) GetColOffset() int

func (*Pos) GetLineno

func (o *Pos) GetLineno() int

type Raise

type Raise struct {
	StmtBase
	Exc   Expr
	Cause Expr
}

func (*Raise) Type

func (o *Raise) Type() *py.Type

type Return

type Return struct {
	StmtBase
	Value Expr
}

func (*Return) Type

func (o *Return) Type() *py.Type

type Set

type Set struct {
	ExprBase
	Elts []Expr
}

func (*Set) Type

func (o *Set) Type() *py.Type

type SetComp

type SetComp struct {
	ExprBase
	Elt        Expr
	Generators []Comprehension
}

func (*SetComp) Type

func (o *SetComp) Type() *py.Type

type SetCtxer

type SetCtxer interface {
	SetCtx(ExprContext)
}

ExprNodes which have a settable context implement this

type Singleton

type Singleton py.Object

type Slice

type Slice struct {
	SliceBase
	Lower Expr
	Upper Expr
	Step  Expr
}

func (*Slice) Type

func (o *Slice) Type() *py.Type

type SliceBase

type SliceBase struct {
	Pos
}

func (*SliceBase) Type

func (o *SliceBase) Type() *py.Type

type Slicer

type Slicer interface {
	Ast
	// contains filtered or unexported methods
}

All SliceBase nodes implement the Slicer interface

type Starred

type Starred struct {
	ExprBase
	Value Expr
	Ctx   ExprContext
}

func (*Starred) SetCtx

func (o *Starred) SetCtx(Ctx ExprContext)

func (*Starred) Type

func (o *Starred) Type() *py.Type

type Stmt

type Stmt interface {
	Ast
	// contains filtered or unexported methods
}

All StmtBase nodes implement the Stmt interface

type StmtBase

type StmtBase struct {
	Pos
}

func (*StmtBase) Type

func (o *StmtBase) Type() *py.Type

type Str

type Str struct {
	ExprBase
	S py.String
}

func (*Str) Type

func (o *Str) Type() *py.Type

type String

type String py.String

type Subscript

type Subscript struct {
	ExprBase
	Value Expr
	Slice Slicer
	Ctx   ExprContext
}

func (*Subscript) SetCtx

func (o *Subscript) SetCtx(Ctx ExprContext)

func (*Subscript) Type

func (o *Subscript) Type() *py.Type

type Suite

type Suite struct {
	ModBase
	Body []Stmt
}

func (*Suite) Type

func (o *Suite) Type() *py.Type

type Try

type Try struct {
	StmtBase
	Body      []Stmt
	Handlers  []*ExceptHandler
	Orelse    []Stmt
	Finalbody []Stmt
}

func (*Try) Type

func (o *Try) Type() *py.Type

type Tuple

type Tuple struct {
	ExprBase
	Elts []Expr
	Ctx  ExprContext
}

func (*Tuple) SetCtx

func (o *Tuple) SetCtx(Ctx ExprContext)

func (*Tuple) Type

func (o *Tuple) Type() *py.Type

type UnaryOp

type UnaryOp struct {
	ExprBase
	Op      UnaryOpNumber
	Operand Expr
}

func (*UnaryOp) Type

func (o *UnaryOp) Type() *py.Type

type UnaryOpNumber

type UnaryOpNumber int

func (UnaryOpNumber) String

func (o UnaryOpNumber) String() string

type While

type While struct {
	StmtBase
	Test   Expr
	Body   []Stmt
	Orelse []Stmt
}

func (*While) Type

func (o *While) Type() *py.Type

type With

type With struct {
	StmtBase
	Items []*WithItem
	Body  []Stmt
}

func (*With) Type

func (o *With) Type() *py.Type

type WithItem

type WithItem struct {
	Pos
	ContextExpr  Expr
	OptionalVars Expr
}

func (*WithItem) Type

func (o *WithItem) Type() *py.Type

type Yield

type Yield struct {
	ExprBase
	Value Expr
}

func (*Yield) Type

func (o *Yield) Type() *py.Type

type YieldFrom

type YieldFrom struct {
	ExprBase
	Value Expr
}

func (*YieldFrom) Type

func (o *YieldFrom) Type() *py.Type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL