Documentation
¶
Index ¶
- func Compile(source []byte, filename string) error
- func ConstantRepr(v any) (string, error)
- func LiteralEval(source string) (any, error)
- func LiteralEvalNode(n *Node) (v any, err error)
- func LiteralStrList(text string) ([]string, bool, error)
- func ParseWith(source string, opts Options) (*Node, []Warning, error)
- func Unparse(n *Node) (s string, err error)
- type Complex
- type Dict
- type Ellipsis
- type IntDigitsError
- type LimitError
- type LiteralError
- type Node
- func (n *Node) Child(name string) *Node
- func (n *Node) Children(name string) []*Node
- func (n *Node) Fields() []string
- func (n *Node) Get(name string) any
- func (n *Node) HasLocation() bool
- func (n *Node) Int(name string) (int, bool)
- func (n *Node) Is(types ...string) bool
- func (n *Node) Names(name string) []string
- func (n *Node) Repr() (string, error)
- func (n *Node) Set(name string, v any)
- func (n *Node) Str(name string) (string, bool)
- type Options
- type Set
- type SyntaxError
- type UnparseError
- type Warning
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶
Compile compiles source bytes like compile(source, filename, "exec") and returns the error it raises
func ConstantRepr ¶
ConstantRepr renders a constant value with repr, raising the int digit limit error CPython raises
func LiteralEval ¶
LiteralEval evaluates a Python literal expression from source text like ast.literal_eval(str)
func LiteralEvalNode ¶
LiteralEvalNode evaluates an expression node, or the body of an Expression, like ast.literal_eval(node)
func LiteralStrList ¶
Items of a list literal rendered with str, false on ValueError, SyntaxError or a non list, other exceptions returned
Types ¶
type Complex ¶
type Complex struct{ Real, Imag float64 }
Complex is a complex constant such as an imaginary literal
type Dict ¶
type Dict struct{ Keys, Values []any }
Dict is a literal dict keeping insertion order, its keys compared with Python equality
func (*Dict) PyTypeName ¶
PyTypeName names the Python type for pyrepr
type Ellipsis ¶
type Ellipsis struct{}
Ellipsis is the ... constant
type IntDigitsError ¶
type IntDigitsError struct{}
IntDigitsError is the ValueError CPython raises converting an int over 4300 decimal digits to text
func (*IntDigitsError) Error ¶
func (e *IntDigitsError) Error() string
type LimitError ¶
type LimitError struct{ Class, Msg string }
LimitError is the MemoryError raised when the source nests deeper than the parser stack allows
func (*LimitError) Error ¶
func (e *LimitError) Error() string
type LiteralError ¶
type LiteralError struct{ Class, Msg string }
LiteralError is the ValueError or TypeError literal_eval raises for a node that is not a literal
func (*LiteralError) Error ¶
func (e *LiteralError) Error() string
type Node ¶
type Node struct {
Type string
Lineno, ColOffset, EndLineno, EndColOffset int
// contains filtered or unexported fields
}
Node is one ast.AST instance with its fields in _fields order and its location attributes
func IterChildNodes ¶
IterChildNodes yields direct child nodes in field order like ast.iter_child_nodes
func ParseBytes ¶
ParseBytes parses encoded source like ast.parse(bytes), honouring a UTF-8 BOM and a PEP 263 coding declaration
func ParseExpression ¶
ParseExpression parses source in eval mode like ast.parse(source, mode='eval'), returning an Expression
func (*Node) Get ¶
Get returns a field value, nil when the class has no such field or the field holds None
func (*Node) HasLocation ¶
HasLocation reports whether the class carries lineno and col_offset attributes
type Options ¶
type Options struct {
Filename string
Mode string
TypeComments bool
FeatureVersion *int
// FeatureMajor is the major of a (major, minor) feature_version tuple whose minor is FeatureVersion
FeatureMajor *int
Optimize int
WarningsAsErrors bool
// contains filtered or unexported fields
}
Options holds the ast.parse arguments filename, mode, type_comments, feature_version and optimize and the warnings error filter
type Set ¶
type Set []any
Set is a literal set holding distinct members in insertion order
type SyntaxError ¶
type SyntaxError struct {
Class string
Msg string
Lineno, Offset, EndLineno, EndOffset int
Text string
HasLineno, HasText, HasEnd bool
Filename string
}
SyntaxError is the SyntaxError, IndentationError or TabError ast.parse raises
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
Error renders str(exc) with the <unknown> filename ast.parse passes
type UnparseError ¶
type UnparseError struct{ Msg string }
UnparseError is the ValueError ast.unparse raises for a node it cannot render
func (*UnparseError) Error ¶
func (e *UnparseError) Error() string