simvx.core.scene_io.source._source_ast.calls

Argument-level operations on one call expression, in text.

Every operation here is a span and a replacement: the argument to overwrite, the place a new one is appended, the run a removal takes out. Nothing is rebuilt from the tree, so an argument the edit did not touch survives byte for byte, down to its quotes and its digits.

Afterwards the statement is laid out again, by the same

mod:

~simvx.core.scene_io.layout rule the emitter writes new files by, so a call that outgrew its line breaks the way a formatter would have broken it and one that fits again comes back together. Laying out from text needs the flat form first, which is what :func:relayout builds: the whitespace the layout owns is normalised inside the statement’s trailing bracket group and nothing else is touched.

Three statements are left exactly as they were found, because laying them out would destroy something this layer cannot put back: one carrying a comment, which belongs to the line it was written on; one holding a value that spans lines of its own (a triple-quoted string, a backslash continuation); and one sharing its line with others behind semicolons, whose width is not one statement’s to measure.

Module Contents

Classes

AstCallView

A view onto one call, resolved from its statement on every use.

Functions

ordered_arguments

Everything call passes, in the order it is written.

argument_expression

The expression an argument passes, without the keyword or the stars in front of it.

relayout

text laid out again as one statement written at column indent.

Data

API

simvx.core.scene_io.source._source_ast.calls.__all__

[‘AstCallView’, ‘ordered_arguments’, ‘relayout’]

simvx.core.scene_io.source._source_ast.calls.ordered_arguments(table: simvx.core.scene_io.source._source_ast.spans.LineTable, call: ast.Call) list[ast.expr | ast.keyword][source]

Everything call passes, in the order it is written.

ast lists positionals and keywords separately and a call may interleave them (f(a, k=1, *rest) is legal), so source order is established here once, by span, exactly as :func:~.spans.call_spans establishes it for the spans that run alongside these nodes.

simvx.core.scene_io.source._source_ast.calls.argument_expression(item: ast.expr | ast.keyword) ast.expr[source]

The expression an argument passes, without the keyword or the stars in front of it.

simvx.core.scene_io.source._source_ast.calls.relayout(text: str, *, indent: int, limit: int = LINE_LIMIT) str[source]

text laid out again as one statement written at column indent.

The flat form is built first and every later decision only adds line breaks back, which is what makes laying a statement out twice give what laying it out once gave. A statement whose flat form still holds a line break holds it somewhere the layout does not own – inside a string, or in front of the group – and comes back untouched rather than reflowed.

class simvx.core.scene_io.source._source_ast.calls.AstCallView(document: simvx.core.scene_io.source._source_ast.document.AstDocument, statement: simvx.core.scene_io.source._source_ast.document.AstStatement, path: tuple[int, ...])[source]

Bases: simvx.core.scene_io.source.CallView

A view onto one call, resolved from its statement on every use.

The call is named by the path of argument positions leading to it from the statement’s value, rather than by an offset, so a view survives the statement being laid out again underneath it: what moved is where the call is written, and the path says which call it is.

Initialization

__slots__

(‘_document’, ‘_statement’, ‘_path’)

callee() str[source]
text() str[source]
arguments() list[simvx.core.scene_io.source.Argument][source]
kwarg(name: str) str | None[source]
set_kwarg(name: str, value_expr: str) None[source]
remove_kwarg(name: str) None[source]
set_positional(index: int, value_expr: str) None[source]
argument_call(index: int) simvx.core.scene_io.source._source_ast.calls.AstCallView | None[source]