Abstract Syntax Tree (xonsh.ast)

The xonsh abstract syntax tree node.

class xonsh.ast.CtxAwareTransformer(parser)[source]

Transforms a xonsh AST based to use subprocess calls when the first name in an expression statement is not known in the context. This assumes that the expression statement is instead parseable as a subprocess.

Parameters:

parser : xonsh.Parser

A parse instance to try to parse suprocess statements with.

ctxadd(value)[source]

Adds a value the most recent context.

ctxremove(value)[source]

Removes a value the most recent context.

ctxupdate(iterable)[source]

Updated the most recent context.

ctxvisit(node, inp, ctx, mode='exec')[source]

Transforms the node in a context-dependent way.

Parameters:

node : ast.AST

A syntax tree to transform.

input : str

The input code in string format.

ctx : dict

The root context to use.

Returns:

node : ast.AST

The transformed node.

generic_visit(node)
is_in_scope(node)[source]

Determines whether or not the current node is in scope.

try_subproc_toks(node, strip_expr=False)[source]

Tries to parse the line of the node as a subprocess.

visit(node)

Visit a node.

visit_Assign(node)[source]

Handle visiting an assignment statement.

visit_BoolOp(node)[source]

Handle visiting an boolean operands, like and/or.

visit_ClassDef(node)[source]

Handle visiting a class definition.

visit_Delete(node)[source]

Handle visiting a del statement.

visit_Expr(node)[source]

Handle visiting an expression.

visit_Expression(node)[source]

Handle visiting an expression body.

visit_For(node)[source]

Handle visiting a for statement.

visit_FunctionDef(node)[source]

Handle visiting a function definition.

visit_Global(node)[source]

Handle visiting a global statement.

visit_Import(node)[source]

Handle visiting a import statement.

visit_ImportFrom(node)[source]

Handle visiting a “from ... import ...” statement.

visit_Try(node)[source]

Handle visiting a try statement.

visit_UnaryOp(node)[source]

Handle visiting an unary operands, like not.

visit_With(node)[source]

Handle visiting a with statement.

xonsh.ast.get_col(node, default=-1)[source]

Gets the col_offset of a node, or returns the default

xonsh.ast.isdescendable(node)[source]

Deteremines whether or not a node is worth visiting. Currently only UnaryOp and BoolOp nodes are visited.

xonsh.ast.leftmostname(node)[source]

Attempts to find the first name in the tree.

xonsh.ast.max_col(node)[source]

Returns the maximum col_offset of the node and all sub-nodes.

xonsh.ast.min_col(node)[source]

Computes the minimum col_offset.

xonsh.ast.pdump(s, **kwargs)[source]

performs a pretty dump of an AST node.