Skip to content

dpmxl.references

Static analysis of what a rule reads. See Analyse rules statically.

dpmxl.references

Static analysis: the selections and templates an expression refers to.

Reference dataclass

Reference(spec: SelectionSpec, span: tuple[int, int])

A selection completed by its inherited with context.

spec.table is the table code of a cell selection; for a table group ({g_Group, ...}) or operation ({o_Code, ...}) reference it is None and kind and code say what is referenced. Typed parameters ({p_Name, ...}) are not selections and are not listed.

Attributes:

  • spec (SelectionSpec) –

    The selection with its with context applied.

  • span (tuple[int, int]) –

    The selection's source span.

spec instance-attribute

span instance-attribute

span: tuple[int, int]

kind property

kind: Literal['table', 'table_group', 'operation']

What the selection reads: a table, a table group or an operation.

code property

code: str | None

The table, table group or operation code.

references

references(node: Node) -> tuple[Reference, ...]

Return every selection with its inherited context applied.

Table-group and operation references are included with spec.table set to None: check Reference.kind and read the group or operation code from Reference.code. A group read reads every table the provider's table_group(code) lists; tables expands groups that way when given the provider. Targets of persistent assignments are included too.

Returns:

  • tuple[Reference, ...] –

    tuple[Reference, ...]: Selections in source order.

Examples:

>>> from dpmxl import parse
>>> node = parse("with {tC_01.00, c0010}: {r0010} = {r0020} + {g_G1, r0010}")
>>> [(ref.spec.text(), ref.kind, ref.code) for ref in references(node)]
...
[('{tC_01.00, r0010, c0010}', 'table', 'C_01.00'),
 ('{tC_01.00, r0020, c0010}', 'table', 'C_01.00'),
 ('{gG1, r0010, c0010}', 'table_group', 'G1')]

tables

tables(
    node: Node, provider: object | None = None
) -> tuple[str, ...]

Return the distinct table codes referenced by cell selections.

Parameters:

  • node (Node) –

    The expression tree.

  • provider (object | None, default: None ) –

    Optional provider whose table_group(code) method resolves table groups; each group read then counts as reading all its tables. Without it, groups are left out.

Returns:

  • tuple[str, ...] –

    tuple[str, ...]: Table codes in first-seen order.

Examples:

>>> from dpmxl import MemoryProvider, parse
>>> node = parse("{tC_01.00, r0010} = {g_G1, r0010}")
>>> tables(node)
('C_01.00',)
>>> tables(node, MemoryProvider([], {}, table_groups={"G1": ("C_05.01",)}))
('C_01.00', 'C_05.01')

reported_templates

reported_templates(node: Node) -> tuple[str, ...]

Return templates tested with {v_...} filing-indicator checks.

Returns:

  • tuple[str, ...] –

    tuple[str, ...]: Template codes in first-seen order.

Examples:

>>> from dpmxl import parse
>>> reported_templates(parse("{v_C_01.00} and not {v_C_02.00}"))
('C_01.00', 'C_02.00')