Source code for autobean_refactor.models.generated.cost_spec

# DO NOT EDIT
# This file is automatically generated by autobean_refactor.modelgen.

from typing import Iterator, final
from typing_extensions import Self
from .. import base, internal
from ..cost import TotalCost, UnitCost


@internal.tree_model
class CostSpec(base.RawTreeModel, internal.SpacingAccessorsMixin):
    """Unit cost or total cost."""
    RULE = 'cost_spec'
    INLINE = True

    _cost = internal.required_field[TotalCost | UnitCost]()

    raw_cost = internal.required_node_property[TotalCost | UnitCost](_cost)

    @final
    def __init__(
            self,
            token_store: base.TokenStore,
            cost: TotalCost | UnitCost,
    ):
        super().__init__(token_store)
        self._cost = cost

    @property
    def first_token(self) -> base.RawTokenModel:
        return self._cost.first_token

    @property
    def last_token(self) -> base.RawTokenModel:
        return self._cost.last_token

    def clone(self, token_store: base.TokenStore, token_transformer: base.TokenTransformer) -> Self:
        return type(self)(
            token_store,
            type(self)._cost.clone(self._cost, token_store, token_transformer),
        )

    def _reattach(self, token_store: base.TokenStore, token_transformer: base.TokenTransformer) -> None:
        self._token_store = token_store
        self._cost = type(self)._cost.reattach(self._cost, token_store, token_transformer)

    def _eq(self, other: base.RawTreeModel) -> bool:
        return (
            isinstance(other, CostSpec)
            and self._cost == other._cost
        )

[docs] @classmethod def from_children( cls, cost: TotalCost | UnitCost, ) -> Self: tokens = [ *cost.detach(), ] token_store = base.TokenStore.from_tokens(tokens) cls._cost.reattach(cost, token_store) return cls(token_store, cost)
[docs] def auto_claim_comments(self) -> None: type(self)._cost.auto_claim_comments(self._cost)
def iter_children_formatted(self) -> Iterator[tuple[base.RawModel, bool]]: yield from type(self)._cost.iter_children_formatted(self._cost, False)