pyk.kast.inner module¶
- final class KApply(label: str | KLabel, args: Iterable[KInner])[source]¶
- final class KApply(label: str | KLabel, *args: KInner)
Bases:
KInner
Represent the application of a KLabel in a K AST to arguments.
- property arity: int¶
Return the count of the arguments.
- property is_cell: bool¶
Return whether this is a cell-label application (based on heuristic about label names).
- final class KAs(pattern: KInner, alias: KInner)[source]¶
Bases:
KInner
Represent a K #as pattern in the K AST format, with the original pattern and the variabl alias.
- class KInner[source]¶
Bases:
KAst
Represent the AST of a given K inner term.
This class represents the AST of a given term. The nodes in the AST should be coming from a given KDefinition, so that they can be checked for well-typedness.
- static from_dict(dct: Mapping[str, Any]) KInner [source]¶
Deserialize a given KInner into a more specific type from a dictionary.
- final map_inner(f: Callable[[KInner], KInner]) KI [source]¶
Apply a transformation to all children of this given KInner.
- final class KLabel(name: str, params: Iterable[str | KSort])[source]¶
- final class KLabel(name: str, *params: str | KSort)
Bases:
KAst
Represents a symbol that can be applied in a K AST, potentially with sort parameters.
- apply(args: Iterable[KInner]) KApply [source]¶
- apply(*args: KInner) KApply
Construct a KApply with this KLabel as the AST head and the supplied parameters as the arguments.
- let(*, name: str | None = None, params: Iterable[str | KSort] | None = None) KLabel [source]¶
Return a copy of this KLabel with potentially the name or sort parameters updated.
- name: str¶
- final class KRewrite(lhs: KInner, rhs: KInner)[source]¶
Bases:
KInner
Represent a K rewrite in the K AST.
- apply(term: KInner) KInner [source]¶
Attempt rewriting once at every position in a term bottom-up.
- Parameters:
term – Term to rewrite.
- Returns:
The term with rewrites applied at every node once starting from the bottom.
- apply_top(term: KInner) KInner [source]¶
Rewrite a given term at the top
- Parameters:
term – Term to rewrite.
- Returns:
The term with the rewrite applied once at the top.
- let(*, lhs: KInner | None = None, rhs: KInner | None = None) KRewrite [source]¶
Return a copy of this KRewrite with potentially the LHS or RHS updated.
- replace(term: KInner) KInner [source]¶
Similar to apply but using exact syntactic matching instead of pattern matching.
- final class KSequence(items: Iterable[KInner])[source]¶
- final class KSequence(*items: KInner)
Bases:
KInner
,Sequence
[KInner
]Represent a associative list of K as a cons-list of KItem for sequencing computation in K AST format.
- property arity: int¶
Return the count of KSequence items.
- final class KSort(name: str)[source]¶
Bases:
KAst
Store a simple sort name.
- let(*, name: str | None = None) KSort [source]¶
Return a new KSort with the name potentially updated.
- name: str¶
- final class KToken(token: str, sort: str | KSort)[source]¶
Bases:
KInner
Represent a domain-value in K AST.
- let(*, token: str | None = None, sort: str | KSort | None = None) KToken [source]¶
Return a copy of the KToken with the token or sort potentially updated.
- property terms: tuple[()]¶
- token: str¶
- final class KVariable(name: str, sort: str | KSort | None = None)[source]¶
Bases:
KInner
Represent a logical variable in a K AST, with a name and optionally a sort.
- let(*, name: str | None = None, sort: str | KSort | None = None) KVariable [source]¶
Return a copy of this KVariable with potentially the name or sort updated.
- let_sort(sort: KSort | None) KVariable [source]¶
Return a copy of this KVariable with just the sort updated.
- name: str¶
- property terms: tuple[()]¶
- class Subst(subst: Mapping[str, KInner] = FrozenDict({}))[source]¶
Bases:
Mapping
[str
,KInner
]Represents a substitution, which is a binding of variables to values of KInner.
- apply(term: KInner) KInner [source]¶
Apply the given substitution to KInner, replacing free variable occurances with their valuations defined in this Subst.
- compose(other: Subst) Subst [source]¶
Union two substitutions together, preferring the assignments in self if present in both.
- static from_dict(d: Mapping[str, Any]) Subst [source]¶
Deserialize a Subst from a given dictionary representing it.
- static from_pred(pred: KInner) Subst [source]¶
Given a generic matching logic predicate, attempt to extract a Subst from it.
- property is_identity: bool¶
- property ml_pred: KInner¶
Turn this Subst into a matching logic predicate using {_#Equals_} operator.
- bottom_up(f: Callable[[KInner], KInner], kinner: KInner) KInner [source]¶
Traverse a term from the bottom moving upward, updating it using a given transformation.
- Parameters:
f – Transformation to apply at each node in the term.
kinner – Original term to transform.
- Returns:
The transformed term.
- bottom_up_with_summary(f: Callable[[KInner, list[A]], tuple[KInner, A]], kinner: KInner) tuple[KInner, A] [source]¶
Traverse a term from the bottom moving upward, potentially both transforming it and collecting information about it.
- Parameters:
f – Function to apply at each AST node to transform it and collect summary.
kinner – KInner to apply this transformation to.
- Returns:
A tuple of the transformed term and the summarized results.
- build_assoc(unit: KInner, label: str | KLabel, terms: Iterable[KInner]) KInner [source]¶
Build an associative list.
- Parameters:
unit – The empty variant of the given list type.
label – The associative list join operator.
terms – List (potentially empty) of terms to join in an associative list.
- Returns:
The list of terms joined using the supplied label, or the unit element in the case of no terms.
- build_cons(unit: KInner, label: str | KLabel, terms: Iterable[KInner]) KInner [source]¶
Build a cons list.
- Parameters:
unit – The empty variant of the given list type.
label – The associative list join operator.
terms – List (potentially empty) of terms to join in an associative list.
- Returns:
The list of terms joined using the supplied label, terminated with the unit element.
- collect(callback: Callable[[KInner], None], kinner: KInner) None [source]¶
Collect information about a given term when traversing it bottom up using a side-effect function.
- Parameters:
callback – Function supplied by user which has side-effect of collecting desired information at each AST node.