Skip to content

topmark.toml.parse

topmark / toml / parse

Split-parse helpers for TopMark TOML sources.

This module defines the per-source parse result used when reading a single TopMark TOML document. A parsed source may contribute three distinct semantic channels:

  • layered configuration tables that later deserialize into MutableConfig
  • non-layered writer preferences from [writer]
  • discovery/config-loading metadata from [config]

This module is intentionally pure and TOML-facing: - no file I/O - no merge or precedence resolution - no deserialization into MutableConfig

SourceConfigLoadingOptions dataclass

SourceConfigLoadingOptions(*, strict=None)

Config-loading behaviour parsed from the [config] table.

This is a pure per-source metadata carrier for config-loading toggles. It does not participate in layered config merging.

Attributes:

Name Type Description
strict bool | None

Per-source strictness preference for later staged config-loading validation. If True, warnings in staged config-validation are treated as failures. None means that the TOML source does not specify a strictness preference.

SourceTomlOptions dataclass

SourceTomlOptions(*, root=None)

Discovery metadata parsed from the [config] table.

This is a pure per-source metadata carrier. These options do not participate in layered config merging.

Attributes:

Name Type Description
root bool | None

If True, stop config discovery above the directory containing this TOML source. None means that the TOML source does not set a discovery boundary.

ParsedTopmarkToml dataclass

ParsedTopmarkToml(
    *,
    config_loading_options,
    layered_config,
    writer_options,
    source_options,
    toml_fragment,
    validation_issues=(),
)

Per-source split parse result for a TopMark TOML document.

This is not a merged or resolved result.

Attributes:

Name Type Description
config_loading_options SourceConfigLoadingOptions

Config-loading behaviour parsed from the [config] table.

layered_config TomlTable

Layered TOML fragment extracted from the source. This fragment participates in normal config-layer deserialization and merging.

writer_options WriterOptions | None

Non-layered writer preferences parsed from the [writer] table, if present.

source_options SourceTomlOptions

Discovery metadata parsed from the [config] table.

toml_fragment TomlTable

Full source-local TopMark TOML fragment.

validation_issues tuple[TomlValidationIssue, ...]

TOML schema validation issues encountered.

parse_topmark_toml_table

parse_topmark_toml_table(data, *, validation_issues)

Split a TopMark TOML table into its semantic domains.

Parameters:

Name Type Description Default
data TomlTable

A TopMark TOML table, already normalized to plain-Python TOML structures.

required
validation_issues tuple[TomlValidationIssue, ...]

The list of TOML schema validaiton issues.

required

Returns:

Type Description
ParsedTopmarkToml

The per-source split parse result.

Source code in src/topmark/toml/parse.py
def parse_topmark_toml_table(
    data: TomlTable,
    *,
    validation_issues: tuple[TomlValidationIssue, ...],
) -> ParsedTopmarkToml:
    """Split a TopMark TOML table into its semantic domains.

    Args:
        data: A TopMark TOML table, already normalized to plain-Python TOML
            structures.
        validation_issues: The list of TOML schema validaiton issues.

    Returns:
        The per-source split parse result.
    """
    config_tbl: TomlTable | None = _get_table(data, Toml.SECTION_CONFIG)
    writer_tbl: TomlTable | None = _get_table(data, Toml.SECTION_WRITER)

    return ParsedTopmarkToml(
        config_loading_options=_parse_config_loading_options(config_tbl),
        layered_config=_extract_layered_config_toml(data),
        writer_options=_parse_writer_options(writer_tbl),
        source_options=_parse_source_toml_options(config_tbl),
        toml_fragment=_extract_toml_fragment(data),
        validation_issues=validation_issues,
    )