xonsh.parsers.ast¶
Abstract Syntax Tree handler
- class xonsh.parsers.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:
- parserxonsh.Parser
A parse instance to try to parse subprocess statements with.
- ctxvisit(node, inp, ctx, mode='exec', filename=None, debug_level=0)[source]¶
Transforms the node in a context-dependent way.
- Parameters:
- nodeast.AST
A syntax tree to transform.
- inpstr
The input code in string format.
- ctxdict
The root context to use.
- filenamestr, optional
File we are to transform.
- debug_levelint, optional
Debugging level to use in lexing and parsing.
- Returns:
- nodeast.AST
The transformed node.
- generic_visit(node)¶
Called if no explicit visitor function exists for a node.
- 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_Constant(node)¶
- xonsh.parsers.ast.gather_load_store_names(node)[source]¶
Returns the names present in the node’s tree in a set of load nodes and a set of store nodes.
- xonsh.parsers.ast.gather_names(node)[source]¶
Returns the set of all names present in the node’s tree.
- xonsh.parsers.ast.get_col(node, default=-1)[source]¶
Gets the col_offset of a node, or returns the default
- xonsh.parsers.ast.get_id(node, default=None)[source]¶
Gets the id attribute of a node, or returns a default.
- xonsh.parsers.ast.get_id_ctx(node)[source]¶
Gets the id and attribute of a node, or returns a default.
- xonsh.parsers.ast.get_lineno(node, default=0)[source]¶
Gets the lineno of a node or returns the default.
- xonsh.parsers.ast.isdescendable(node)[source]¶
Determines whether or not a node is worth visiting. Currently only UnaryOp and BoolOp nodes are visited.
- xonsh.parsers.ast.isexpression(node, ctx=None, *args, **kwargs)[source]¶
Determines whether a node (or code string) is an expression, and does not contain any statements. The execution context (ctx) and other args and kwargs are passed down to the parser, as needed.
- xonsh.parsers.ast.load_attribute_chain(name, lineno=None, col=None)[source]¶
Creates an AST that loads variable name that may (or may not) have attribute chains. For example, “a.b.c”
- xonsh.parsers.ast.max_col(node)[source]¶
Returns the maximum col_offset of the node and all sub-nodes.