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.
- __init__(label: str | KLabel, args: Iterable[KInner])[source]
- __init__(label: str | KLabel, *args: KInner)
Construct a new KApply given the input KLabel or str, applied 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.
- __init__(pattern: KInner, alias: KInner)[source]
Construct a new KAs given the original pattern and the 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.
- __init__(name: str, params: Iterable[str | KSort])[source]
- __init__(name: str, *params: str | KSort)
Construct a new KLabel, with optional sort parameters.
- __iter__() Iterator[str | KSort] [source]
Return this symbol as iterator with the name as the head and the parameters as the tail.
- 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.
- __init__(lhs: KInner, rhs: KInner)[source]
Construct a KRewrite given the LHS (left-hand-side) and RHS (right-hand-side) to use.
- __iter__() Iterator[KInner] [source]
Return a two-element iterator with the LHS first and RHS second.
- 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.
- __init__(items: Iterable[KInner])[source]
- __init__(*items: KInner)
Construct a new KSequence given the arguments.
- 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.
- __init__(token: str, sort: str | KSort)[source]
Construct a new KToken with a given string representation in the supplied sort.
- 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.
- __init__(name: str, sort: str | KSort | None = None)[source]
Construct a new KVariable with a given name and optional 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.
- __getitem__(key: str) KInner [source]
Get the KInner associated with the given variable name from the underlying Subst mapping.
- __init__(subst: Mapping[str, KInner] = FrozenDict({}))[source]
Construct a new Subst given a mapping fo variable names to 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
- bottom_up(f: Callable[[KInner], KInner], kinner: KInner) KInner [source]
Transform a term from the bottom moving upward.
- Parameters:
f – Function to apply to 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, collecting information about it.
- Parameters:
f – Function to apply at each AST node to transform it and collect summary.
kinner – Term 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 traversing it top-down using a function with side effects.
- Parameters:
callback – Function with the side effect of collecting desired information at each AST node.
kinner – The term to traverse.
- flatten_label(label: str, kast: KInner) list[KInner] [source]
Given a cons list, return a flat Python list of the elements.
- Parameters:
label – The cons operator.
kast – The cons list to flatten.
- Returns:
Items of cons list.