Module refinery.lib.scripts.xlm.trace
The trace the emulator produces: one step per executed cell, with the status of the cell and the output level that decides which steps a trace shows.
Expand source code Browse git
"""
The trace the emulator produces: one step per executed cell, with the status of the cell and
the output level that decides which steps a trace shows.
"""
from __future__ import annotations
import enum
import re
from typing import NamedTuple
from refinery.lib.scripts.xlm.commands import XlmSeverity
class XlmStatus(enum.Enum):
"""
The state one executed cell left the program in.
"""
FullEvaluation = enum.auto()
PartialEvaluation = enum.auto()
Error = enum.auto()
NotImplemented = enum.auto()
End = enum.auto()
Branching = enum.auto()
FullBranching = enum.auto()
IGNORED = enum.auto()
class XlmStep(NamedTuple):
"""
One executed cell of a run: the sheet it sits on with its one-based row and column, the
status the run left it in, the text the trace prints for it, its indentation inside a
branch, and the output level it prints at — the level of its command, or the lowest level
when the cell is no command call at all.
"""
sheet: str
row: int
col: int
status: XlmStatus
text: str
indent: int
severity: XlmSeverity
_QUOTED_TEXT = re.compile(R'"([^"]|"")*"')
def visible_steps(steps, level: int):
"""
The steps a trace at the given output level shows: a step the interpreter ignored never
shows, at the string-extraction level only the triage commands show and only the quoted
string literals their text carries, and otherwise a step shows when its own level
reaches the requested one.
"""
for step in steps:
if step.status is XlmStatus.IGNORED:
continue
if level >= 3 and step.severity is XlmSeverity.IMPORTANT:
strings = [match.group(0) for match in _QUOTED_TEXT.finditer(step.text)]
if strings:
yield step._replace(text='\n'.join(strings))
elif step.severity.value >= level:
yield step
Functions
def visible_steps(steps, level)-
The steps a trace at the given output level shows: a step the interpreter ignored never shows, at the string-extraction level only the triage commands show and only the quoted string literals their text carries, and otherwise a step shows when its own level reaches the requested one.
Expand source code Browse git
def visible_steps(steps, level: int): """ The steps a trace at the given output level shows: a step the interpreter ignored never shows, at the string-extraction level only the triage commands show and only the quoted string literals their text carries, and otherwise a step shows when its own level reaches the requested one. """ for step in steps: if step.status is XlmStatus.IGNORED: continue if level >= 3 and step.severity is XlmSeverity.IMPORTANT: strings = [match.group(0) for match in _QUOTED_TEXT.finditer(step.text)] if strings: yield step._replace(text='\n'.join(strings)) elif step.severity.value >= level: yield step
Classes
class XlmStatus (*args, **kwds)-
The state one executed cell left the program in.
Expand source code Browse git
class XlmStatus(enum.Enum): """ The state one executed cell left the program in. """ FullEvaluation = enum.auto() PartialEvaluation = enum.auto() Error = enum.auto() NotImplemented = enum.auto() End = enum.auto() Branching = enum.auto() FullBranching = enum.auto() IGNORED = enum.auto()Ancestors
- enum.Enum
Class variables
var FullEvaluation-
The type of the None singleton.
var PartialEvaluation-
The type of the None singleton.
var Error-
The type of the None singleton.
var NotImplemented-
The type of the None singleton.
var End-
The type of the None singleton.
var Branching-
The type of the None singleton.
var FullBranching-
The type of the None singleton.
var IGNORED-
The type of the None singleton.
class XlmStep (sheet, row, col, status, text, indent, severity)-
One executed cell of a run: the sheet it sits on with its one-based row and column, the status the run left it in, the text the trace prints for it, its indentation inside a branch, and the output level it prints at — the level of its command, or the lowest level when the cell is no command call at all.
Expand source code Browse git
class XlmStep(NamedTuple): """ One executed cell of a run: the sheet it sits on with its one-based row and column, the status the run left it in, the text the trace prints for it, its indentation inside a branch, and the output level it prints at — the level of its command, or the lowest level when the cell is no command call at all. """ sheet: str row: int col: int status: XlmStatus text: str indent: int severity: XlmSeverityAncestors
- builtins.tuple
Instance variables
var sheet-
Alias for field number 0
Expand source code Browse git
class XlmStep(NamedTuple): """ One executed cell of a run: the sheet it sits on with its one-based row and column, the status the run left it in, the text the trace prints for it, its indentation inside a branch, and the output level it prints at — the level of its command, or the lowest level when the cell is no command call at all. """ sheet: str row: int col: int status: XlmStatus text: str indent: int severity: XlmSeverity var row-
Alias for field number 1
Expand source code Browse git
class XlmStep(NamedTuple): """ One executed cell of a run: the sheet it sits on with its one-based row and column, the status the run left it in, the text the trace prints for it, its indentation inside a branch, and the output level it prints at — the level of its command, or the lowest level when the cell is no command call at all. """ sheet: str row: int col: int status: XlmStatus text: str indent: int severity: XlmSeverity var col-
Alias for field number 2
Expand source code Browse git
class XlmStep(NamedTuple): """ One executed cell of a run: the sheet it sits on with its one-based row and column, the status the run left it in, the text the trace prints for it, its indentation inside a branch, and the output level it prints at — the level of its command, or the lowest level when the cell is no command call at all. """ sheet: str row: int col: int status: XlmStatus text: str indent: int severity: XlmSeverity var status-
Alias for field number 3
Expand source code Browse git
class XlmStep(NamedTuple): """ One executed cell of a run: the sheet it sits on with its one-based row and column, the status the run left it in, the text the trace prints for it, its indentation inside a branch, and the output level it prints at — the level of its command, or the lowest level when the cell is no command call at all. """ sheet: str row: int col: int status: XlmStatus text: str indent: int severity: XlmSeverity var text-
Alias for field number 4
Expand source code Browse git
class XlmStep(NamedTuple): """ One executed cell of a run: the sheet it sits on with its one-based row and column, the status the run left it in, the text the trace prints for it, its indentation inside a branch, and the output level it prints at — the level of its command, or the lowest level when the cell is no command call at all. """ sheet: str row: int col: int status: XlmStatus text: str indent: int severity: XlmSeverity var indent-
Alias for field number 5
Expand source code Browse git
class XlmStep(NamedTuple): """ One executed cell of a run: the sheet it sits on with its one-based row and column, the status the run left it in, the text the trace prints for it, its indentation inside a branch, and the output level it prints at — the level of its command, or the lowest level when the cell is no command call at all. """ sheet: str row: int col: int status: XlmStatus text: str indent: int severity: XlmSeverity var severity-
Alias for field number 6
Expand source code Browse git
class XlmStep(NamedTuple): """ One executed cell of a run: the sheet it sits on with its one-based row and column, the status the run left it in, the text the trace prints for it, its indentation inside a branch, and the output level it prints at — the level of its command, or the lowest level when the cell is no command call at all. """ sheet: str row: int col: int status: XlmStatus text: str indent: int severity: XlmSeverity