Documentation
¶
Index ¶
- func ChildNodes(n *Node) iter.Seq[*Node]
- func Compile(src []byte, filename string) error
- func LauncherInterpreter(data []byte) (string, bool)
- func Literal(v any) string
- func LiteralEval(src string) (any, error)
- func LiteralStrings(src string) ([]string, bool)
- func Quote(s string) string
- func Unparse(n *Node) (s string, err error)
- func Walk(n *Node) iter.Seq[*Node]
- type Dict
- type Ellipsis
- type ErrorKind
- type LimitError
- type LiteralError
- type Node
- type Set
- type SyntaxError
- type Tuple
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChildNodes ¶
Direct child nodes in field order, contexts and operators included
func Compile ¶
Error Python's compiler would raise for the bytes of a file, nil when it compiles: parse errors and the later ones a parser alone misses, such as return outside a function or a nonlocal with no binding; a *SyntaxError naming filename, or a *LimitError
func LauncherInterpreter ¶
Interpreter path a Windows console script launcher executable embeds: the loader stub, a "#!<python> -I" line, then a zip archive; false for any other layout
func Literal ¶
Python source text of a literal value: a Constant value of a tree or a value LiteralEval gives
func LiteralEval ¶
Value of a Python literal expression: nil for None, bool, int64, *big.Int past int64, float64, complex128, string, []byte, Ellipsis, []any for a list, Tuple, Set or *Dict
func LiteralStrings ¶
Items of a Python list literal as text, a string item as it is, None items left out and any other item in its literal form, false when src is not a list literal
func Quote ¶
s as a Python string literal, single quoted unless only double quotes spare an escape, escaped as Python's repr writes it; a byte that is not UTF-8 becomes the \udcXX escape Python's surrogateescape gives it, so the literal encodes back to the same bytes as a file name or argument, as the embedded interpreter receives such a string
Types ¶
type Dict ¶
type Dict struct{ Keys, Values []any }
Value of a dict literal, keys in source order, a repeated key keeping its first place and its last value
type ErrorKind ¶
type ErrorKind uint8
Category of a syntax error, told apart the way Python reports it
type LimitError ¶
type LimitError struct {
Line, Limit int
}
Source nested deeper than the parser accepts, the guard that keeps hostile input from exhausting the stack
func (*LimitError) Error ¶
func (e *LimitError) Error() string
Limit crossed and the line where it happened
type LiteralError ¶
Expression that parses but is not a literal, or a literal whose set member or dict key cannot be one
func (*LiteralError) Error ¶
func (e *LiteralError) Error() string
Message prefixed with the line of the offending expression when it is known
type Node ¶
type Node struct {
Type string
Line, Col, EndLine, EndCol int
// contains filtered or unexported fields
}
One syntax tree node: Type is the class name the Python ast module uses, lines count from 1 and columns are 0-based UTF-8 byte offsets, all zero for a node without a position
func Parse ¶
Module tree of Python source text, already decoded so a coding declaration is not applied; the error is a *SyntaxError or a *LimitError
func ParseBytes ¶
Module tree of the bytes of a Python file, decoded as its BOM or coding declaration says and as UTF-8 otherwise; the error is a *SyntaxError or a *LimitError
func (*Node) Get ¶
Value of a field, nil when absent or None; a Constant value is a bool, int64, *big.Int past int64, float64, complex128, string, []byte or Ellipsis
type SyntaxError ¶
type SyntaxError struct {
Kind ErrorKind
Msg string
Line, Column, EndLine, EndColumn int
Text string
Filename string
}
Python source the parser or the compiler rejects, with Python's own message, 1-based character columns and the source line, Line zero when the error has no position
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
Location and message as file:line:column: message, the parts that are not known left out