Renamed package for pypi
parent
a30bd7b870
commit
45493c1093
10
build_bin.py
10
build_bin.py
|
@ -1,10 +0,0 @@
|
||||||
import PyInstaller.__main__
|
|
||||||
|
|
||||||
# Run this file to build a standalone executable.
|
|
||||||
# pyinstaller does not build cross-platform.
|
|
||||||
|
|
||||||
PyInstaller.__main__.run([
|
|
||||||
"lamb/__main__.py",
|
|
||||||
"--onefile",
|
|
||||||
"--console"
|
|
||||||
])
|
|
|
@ -1,5 +1,5 @@
|
||||||
if __name__ != "__main__":
|
if __name__ != "__main__":
|
||||||
raise ImportError("lamb.__main__ should never be imported. Run it directly.")
|
raise ImportError("lamb_engine.__main__ should never be imported. Run it directly.")
|
||||||
|
|
||||||
from prompt_toolkit import PromptSession
|
from prompt_toolkit import PromptSession
|
||||||
from prompt_toolkit import print_formatted_text as printf
|
from prompt_toolkit import print_formatted_text as printf
|
||||||
|
@ -7,17 +7,17 @@ from prompt_toolkit.formatted_text import FormattedText
|
||||||
from prompt_toolkit.formatted_text import to_plain_text
|
from prompt_toolkit.formatted_text import to_plain_text
|
||||||
from pyparsing import exceptions as ppx
|
from pyparsing import exceptions as ppx
|
||||||
|
|
||||||
import lamb
|
import lamb_engine
|
||||||
|
|
||||||
|
|
||||||
lamb.utils.show_greeting()
|
lamb_engine.utils.show_greeting()
|
||||||
|
|
||||||
|
|
||||||
r = lamb.Runner(
|
r = lamb_engine.Runner(
|
||||||
prompt_session = PromptSession(
|
prompt_session = PromptSession(
|
||||||
style = lamb.utils.style,
|
style = lamb_engine.utils.style,
|
||||||
lexer = lamb.utils.LambdaLexer(),
|
lexer = lamb_engine.utils.LambdaLexer(),
|
||||||
key_bindings = lamb.utils.bindings
|
key_bindings = lamb_engine.utils.bindings
|
||||||
),
|
),
|
||||||
prompt_message = FormattedText([
|
prompt_message = FormattedText([
|
||||||
("class:prompt", "==> ")
|
("class:prompt", "==> ")
|
||||||
|
@ -50,12 +50,12 @@ while True:
|
||||||
("class:err", " "*(e.loc + l) + "^\n"),
|
("class:err", " "*(e.loc + l) + "^\n"),
|
||||||
("class:err", f"Syntax error at char {e.loc}."),
|
("class:err", f"Syntax error at char {e.loc}."),
|
||||||
("class:text", "\n")
|
("class:text", "\n")
|
||||||
]), style = lamb.utils.style)
|
]), style = lamb_engine.utils.style)
|
||||||
continue
|
continue
|
||||||
except lamb.nodes.ReductionError as e:
|
except lamb_engine.nodes.ReductionError as e:
|
||||||
printf(FormattedText([
|
printf(FormattedText([
|
||||||
("class:err", f"{e.msg}\n")
|
("class:err", f"{e.msg}\n")
|
||||||
]), style = lamb.utils.style)
|
]), style = lamb_engine.utils.style)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
printf("")
|
printf("")
|
|
@ -1,5 +1,5 @@
|
||||||
import lamb
|
import lamb_engine
|
||||||
import lamb.nodes as lbn
|
import lamb_engine.nodes as lbn
|
||||||
|
|
||||||
def print_node(node: lbn.Node, *, export: bool = False) -> str:
|
def print_node(node: lbn.Node, *, export: bool = False) -> str:
|
||||||
if not isinstance(node, lbn.Node):
|
if not isinstance(node, lbn.Node):
|
||||||
|
@ -28,7 +28,7 @@ def print_node(node: lbn.Node, *, export: bool = False) -> str:
|
||||||
i = -1
|
i = -1
|
||||||
p = o
|
p = o
|
||||||
while o in bound_subs.values():
|
while o in bound_subs.values():
|
||||||
o = p + lamb.utils.subscript(i := i + 1)
|
o = p + lamb_engine.utils.subscript(i := i + 1)
|
||||||
bound_subs[n.input.identifier] = o
|
bound_subs[n.input.identifier] = o
|
||||||
else:
|
else:
|
||||||
bound_subs[n.input.identifier] = n.input.print_value()
|
bound_subs[n.input.identifier] = n.input.print_value()
|
||||||
|
@ -168,7 +168,7 @@ def prepare(root: lbn.Root, *, ban_macro_name = None) -> list:
|
||||||
warnings += [
|
warnings += [
|
||||||
("class:code", "$"),
|
("class:code", "$"),
|
||||||
("class:warn", " will be expanded to ")
|
("class:warn", " will be expanded to ")
|
||||||
] + lamb.utils.lex_str(str(n.expand()[1]))
|
] + lamb_engine.utils.lex_str(str(n.expand()[1]))
|
||||||
|
|
||||||
# If this expression is part of a macro,
|
# If this expression is part of a macro,
|
||||||
# make sure we don't reference it inside itself.
|
# make sure we don't reference it inside itself.
|
||||||
|
@ -208,7 +208,7 @@ def prepare(root: lbn.Root, *, ban_macro_name = None) -> list:
|
||||||
raise lbn.ReductionError(f"Bound variable name conflict: \"{n.input.name}\"")
|
raise lbn.ReductionError(f"Bound variable name conflict: \"{n.input.name}\"")
|
||||||
else:
|
else:
|
||||||
bound_variables[n.input.name] = lbn.Bound(
|
bound_variables[n.input.name] = lbn.Bound(
|
||||||
lamb.utils.remove_sub(n.input.name),
|
lamb_engine.utils.remove_sub(n.input.name),
|
||||||
macro_name = n.input.name
|
macro_name = n.input.name
|
||||||
)
|
)
|
||||||
n.input = bound_variables[n.input.name]
|
n.input = bound_variables[n.input.name]
|
|
@ -1,5 +1,5 @@
|
||||||
import lamb
|
import lamb_engine
|
||||||
import lamb.nodes as lbn
|
import lamb_engine.nodes as lbn
|
||||||
|
|
||||||
class TreeWalker:
|
class TreeWalker:
|
||||||
"""
|
"""
|
||||||
|
@ -82,7 +82,7 @@ class Node:
|
||||||
|
|
||||||
# The runner this node is attached to.
|
# The runner this node is attached to.
|
||||||
# Set by Node.set_runner()
|
# Set by Node.set_runner()
|
||||||
self.runner: lamb.runner.Runner = None # type: ignore
|
self.runner: lamb_engine.runner.Runner = None # type: ignore
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return TreeWalker(self)
|
return TreeWalker(self)
|
|
@ -7,7 +7,7 @@ from prompt_toolkit import prompt
|
||||||
import os.path
|
import os.path
|
||||||
from pyparsing import exceptions as ppx
|
from pyparsing import exceptions as ppx
|
||||||
|
|
||||||
import lamb
|
import lamb_engine
|
||||||
|
|
||||||
commands = {}
|
commands = {}
|
||||||
help_texts = {}
|
help_texts = {}
|
||||||
|
@ -38,7 +38,7 @@ def cmd_step(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<err>Command <code>:{command.name}</code> takes no more than one argument.</err>"
|
f"<err>Command <code>:{command.name}</code> takes no more than one argument.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ def cmd_step(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<err>Usage: <code>:step [yes|no]</code></err>"
|
f"<err>Usage: <code>:step [yes|no]</code></err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ def cmd_step(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<warn>Enabled step-by-step reduction.</warn>"
|
f"<warn>Enabled step-by-step reduction.</warn>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
runner.step_reduction = True
|
runner.step_reduction = True
|
||||||
else:
|
else:
|
||||||
|
@ -71,7 +71,7 @@ def cmd_step(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<warn>Disabled step-by-step reduction.</warn>"
|
f"<warn>Disabled step-by-step reduction.</warn>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
runner.step_reduction = False
|
runner.step_reduction = False
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ def cmd_expand(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<err>Command <code>:{command.name}</code> takes no more than one argument.</err>"
|
f"<err>Command <code>:{command.name}</code> takes no more than one argument.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ def cmd_expand(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<err>Usage: <code>:expand [yes|no]</code></err>"
|
f"<err>Usage: <code>:expand [yes|no]</code></err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ def cmd_expand(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<warn>Enabled complete expansion.</warn>"
|
f"<warn>Enabled complete expansion.</warn>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
runner.full_expansion = True
|
runner.full_expansion = True
|
||||||
else:
|
else:
|
||||||
|
@ -118,7 +118,7 @@ def cmd_expand(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<warn>Disabled complete expansion.</warn>"
|
f"<warn>Disabled complete expansion.</warn>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
runner.full_expansion = False
|
runner.full_expansion = False
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ def cmd_save(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<err>Command <code>:{command.name}</code> takes exactly one argument.</err>"
|
f"<err>Command <code>:{command.name}</code> takes exactly one argument.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ def cmd_save(command, runner) -> None:
|
||||||
("class:warn", "File exists. Overwrite? "),
|
("class:warn", "File exists. Overwrite? "),
|
||||||
("class:text", "[yes/no]: ")
|
("class:text", "[yes/no]: ")
|
||||||
]),
|
]),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
).lower()
|
).lower()
|
||||||
|
|
||||||
if confirm != "yes":
|
if confirm != "yes":
|
||||||
|
@ -152,7 +152,7 @@ def cmd_save(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
"<err>Cancelled.</err>"
|
"<err>Cancelled.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ def cmd_save(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"Wrote {len(runner.macro_table)} macros to <code>{target}</code>"
|
f"Wrote {len(runner.macro_table)} macros to <code>{target}</code>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ def cmd_load(command, runner):
|
||||||
HTML(
|
HTML(
|
||||||
f"<err>Command <code>:{command.name}</code> takes exactly one argument.</err>"
|
f"<err>Command <code>:{command.name}</code> takes exactly one argument.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ def cmd_load(command, runner):
|
||||||
HTML(
|
HTML(
|
||||||
f"<err>File {target} doesn't exist.</err>"
|
f"<err>File {target} doesn't exist.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -215,18 +215,18 @@ def cmd_load(command, runner):
|
||||||
("class:err", l[e.loc]),
|
("class:err", l[e.loc]),
|
||||||
("class:code", l[e.loc+1:])
|
("class:code", l[e.loc+1:])
|
||||||
]),
|
]),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not isinstance(x, lamb.runner.runner.MacroDef):
|
if not isinstance(x, lamb_engine.runner.runner.MacroDef):
|
||||||
printf(
|
printf(
|
||||||
FormattedText([
|
FormattedText([
|
||||||
("class:warn", f"Skipping line {i+1:02}: "),
|
("class:warn", f"Skipping line {i+1:02}: "),
|
||||||
("class:code", l),
|
("class:code", l),
|
||||||
("class:warn", f" is not a macro definition.")
|
("class:warn", f" is not a macro definition.")
|
||||||
]),
|
]),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -235,8 +235,8 @@ def cmd_load(command, runner):
|
||||||
printf(
|
printf(
|
||||||
FormattedText([
|
FormattedText([
|
||||||
("class:ok", f"Loaded {x.label}: ")
|
("class:ok", f"Loaded {x.label}: ")
|
||||||
] + lamb.utils.lex_str(str(x.expr))),
|
] + lamb_engine.utils.lex_str(str(x.expr))),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ def mdel(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<err>Command <code>:{command.name}</code> takes exactly one argument.</err>"
|
f"<err>Command <code>:{command.name}</code> takes exactly one argument.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ def mdel(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<warn>Macro \"{target}\" is not defined</warn>"
|
f"<warn>Macro \"{target}\" is not defined</warn>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ def delmac(command, runner) -> None:
|
||||||
("class:warn", "Are you sure? "),
|
("class:warn", "Are you sure? "),
|
||||||
("class:text", "[yes/no]: ")
|
("class:text", "[yes/no]: ")
|
||||||
]),
|
]),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
).lower()
|
).lower()
|
||||||
|
|
||||||
if confirm != "yes":
|
if confirm != "yes":
|
||||||
|
@ -282,7 +282,7 @@ def delmac(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
"<err>Cancelled.</err>"
|
"<err>Cancelled.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ def macros(command, runner) -> None:
|
||||||
printf(FormattedText([
|
printf(FormattedText([
|
||||||
("class:warn", "No macros are defined."),
|
("class:warn", "No macros are defined."),
|
||||||
]),
|
]),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
printf(FormattedText([
|
printf(FormattedText([
|
||||||
|
@ -307,7 +307,7 @@ def macros(command, runner) -> None:
|
||||||
("class:text", f"\t{name} \t {exp}\n")
|
("class:text", f"\t{name} \t {exp}\n")
|
||||||
for name, exp in runner.macro_table.items()
|
for name, exp in runner.macro_table.items()
|
||||||
]),
|
]),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
|
|
||||||
@lamb_command(
|
@lamb_command(
|
||||||
|
@ -315,7 +315,7 @@ def macros(command, runner) -> None:
|
||||||
)
|
)
|
||||||
def clear(command, runner) -> None:
|
def clear(command, runner) -> None:
|
||||||
clear_screen()
|
clear_screen()
|
||||||
lamb.utils.show_greeting()
|
lamb_engine.utils.show_greeting()
|
||||||
|
|
||||||
@lamb_command(
|
@lamb_command(
|
||||||
help_text = "Get or set reduction limit"
|
help_text = "Get or set reduction limit"
|
||||||
|
@ -327,14 +327,14 @@ def rlimit(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
"<ok>No reduction limit is set</ok>"
|
"<ok>No reduction limit is set</ok>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
printf(
|
printf(
|
||||||
HTML(
|
HTML(
|
||||||
f"<ok>Reduction limit is {runner.reduction_limit:,}</ok>"
|
f"<ok>Reduction limit is {runner.reduction_limit:,}</ok>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ def rlimit(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<err>Command <code>:{command.name}</code> takes exactly one argument.</err>"
|
f"<err>Command <code>:{command.name}</code> takes exactly one argument.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ def rlimit(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<ok>Removed reduction limit</ok>"
|
f"<ok>Removed reduction limit</ok>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ def rlimit(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
"<err>Reduction limit must be a positive integer or \"none\".</err>"
|
"<err>Reduction limit must be a positive integer or \"none\".</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -374,7 +374,7 @@ def rlimit(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
"<err>Reduction limit must be at least 50.</err>"
|
"<err>Reduction limit must be at least 50.</err>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ def rlimit(command, runner) -> None:
|
||||||
HTML(
|
HTML(
|
||||||
f"<ok>Set reduction limit to {t:,}</ok>"
|
f"<ok>Set reduction limit to {t:,}</ok>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -416,5 +416,5 @@ def help(command, runner) -> None:
|
||||||
"<muted>Detailed documentation can be found on this project's git page.</muted>" +
|
"<muted>Detailed documentation can be found on this project's git page.</muted>" +
|
||||||
"</text>"
|
"</text>"
|
||||||
),
|
),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
|
@ -1,5 +1,5 @@
|
||||||
import enum
|
import enum
|
||||||
import lamb
|
import lamb_engine
|
||||||
|
|
||||||
class StopReason(enum.Enum):
|
class StopReason(enum.Enum):
|
||||||
BETA_NORMAL = ("class:text", "β-normal form")
|
BETA_NORMAL = ("class:text", "β-normal form")
|
||||||
|
@ -16,7 +16,7 @@ class MacroDef:
|
||||||
result[1]
|
result[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, label: str, expr: lamb.nodes.Node):
|
def __init__(self, label: str, expr: lamb_engine.nodes.Node):
|
||||||
self.label = label
|
self.label = label
|
||||||
self.expr = expr
|
self.expr = expr
|
||||||
|
|
|
@ -7,12 +7,12 @@ import collections
|
||||||
import math
|
import math
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import lamb
|
import lamb_engine
|
||||||
|
|
||||||
from lamb.runner.misc import MacroDef
|
from lamb_engine.runner.misc import MacroDef
|
||||||
from lamb.runner.misc import Command
|
from lamb_engine.runner.misc import Command
|
||||||
from lamb.runner.misc import StopReason
|
from lamb_engine.runner.misc import StopReason
|
||||||
from lamb.runner import commands as cmd
|
from lamb_engine.runner import commands as cmd
|
||||||
|
|
||||||
|
|
||||||
# Keybindings for step prompt.
|
# Keybindings for step prompt.
|
||||||
|
@ -32,15 +32,15 @@ class Runner:
|
||||||
self.macro_table = {}
|
self.macro_table = {}
|
||||||
self.prompt_session = prompt_session
|
self.prompt_session = prompt_session
|
||||||
self.prompt_message = prompt_message
|
self.prompt_message = prompt_message
|
||||||
self.parser = lamb.parser.LambdaParser(
|
self.parser = lamb_engine.parser.LambdaParser(
|
||||||
action_func = lamb.nodes.Func.from_parse,
|
action_func = lamb_engine.nodes.Func.from_parse,
|
||||||
action_bound = lamb.nodes.Macro.from_parse,
|
action_bound = lamb_engine.nodes.Macro.from_parse,
|
||||||
action_macro = lamb.nodes.Macro.from_parse,
|
action_macro = lamb_engine.nodes.Macro.from_parse,
|
||||||
action_call = lamb.nodes.Call.from_parse,
|
action_call = lamb_engine.nodes.Call.from_parse,
|
||||||
action_church = lamb.nodes.Church.from_parse,
|
action_church = lamb_engine.nodes.Church.from_parse,
|
||||||
action_macro_def = MacroDef.from_parse,
|
action_macro_def = MacroDef.from_parse,
|
||||||
action_command = Command.from_parse,
|
action_command = Command.from_parse,
|
||||||
action_history = lamb.nodes.History.from_parse
|
action_history = lamb_engine.nodes.History.from_parse
|
||||||
)
|
)
|
||||||
|
|
||||||
# Maximum amount of reductions.
|
# Maximum amount of reductions.
|
||||||
|
@ -74,23 +74,23 @@ class Runner:
|
||||||
message = self.prompt_message
|
message = self.prompt_message
|
||||||
)
|
)
|
||||||
|
|
||||||
def parse(self, line) -> tuple[lamb.nodes.Root | MacroDef | Command, list]:
|
def parse(self, line) -> tuple[lamb_engine.nodes.Root | MacroDef | Command, list]:
|
||||||
e = self.parser.parse_line(line)
|
e = self.parser.parse_line(line)
|
||||||
|
|
||||||
w = []
|
w = []
|
||||||
if isinstance(e, MacroDef):
|
if isinstance(e, MacroDef):
|
||||||
e.expr = lamb.nodes.Root(e.expr)
|
e.expr = lamb_engine.nodes.Root(e.expr)
|
||||||
e.set_runner(self)
|
e.set_runner(self)
|
||||||
w = lamb.nodes.prepare(e.expr, ban_macro_name = e.label)
|
w = lamb_engine.nodes.prepare(e.expr, ban_macro_name = e.label)
|
||||||
elif isinstance(e, lamb.nodes.Node):
|
elif isinstance(e, lamb_engine.nodes.Node):
|
||||||
e = lamb.nodes.Root(e)
|
e = lamb_engine.nodes.Root(e)
|
||||||
e.set_runner(self)
|
e.set_runner(self)
|
||||||
w = lamb.nodes.prepare(e)
|
w = lamb_engine.nodes.prepare(e)
|
||||||
|
|
||||||
return e, w
|
return e, w
|
||||||
|
|
||||||
|
|
||||||
def reduce(self, node: lamb.nodes.Root, *, warnings = []) -> None:
|
def reduce(self, node: lamb_engine.nodes.Root, *, warnings = []) -> None:
|
||||||
|
|
||||||
# Reduction Counter.
|
# Reduction Counter.
|
||||||
# We also count macro (and church) expansions,
|
# We also count macro (and church) expansions,
|
||||||
|
@ -103,16 +103,16 @@ class Runner:
|
||||||
out_text = []
|
out_text = []
|
||||||
|
|
||||||
only_macro = (
|
only_macro = (
|
||||||
isinstance(node.left, lamb.nodes.Macro) or
|
isinstance(node.left, lamb_engine.nodes.Macro) or
|
||||||
isinstance(node.left, lamb.nodes.Church)
|
isinstance(node.left, lamb_engine.nodes.Church)
|
||||||
)
|
)
|
||||||
if only_macro:
|
if only_macro:
|
||||||
stop_reason = StopReason.SHOW_MACRO
|
stop_reason = StopReason.SHOW_MACRO
|
||||||
m, node = lamb.nodes.expand(node, force_all = only_macro)
|
m, node = lamb_engine.nodes.expand(node, force_all = only_macro)
|
||||||
macro_expansions += m
|
macro_expansions += m
|
||||||
|
|
||||||
if len(warnings) != 0:
|
if len(warnings) != 0:
|
||||||
printf(FormattedText(warnings), style = lamb.utils.style)
|
printf(FormattedText(warnings), style = lamb_engine.utils.style)
|
||||||
|
|
||||||
if self.step_reduction:
|
if self.step_reduction:
|
||||||
printf(FormattedText([
|
printf(FormattedText([
|
||||||
|
@ -123,7 +123,7 @@ class Runner:
|
||||||
("class:muted", "Press "),
|
("class:muted", "Press "),
|
||||||
("class:cmd_key", "enter"),
|
("class:cmd_key", "enter"),
|
||||||
("class:muted", " to step.\n"),
|
("class:muted", " to step.\n"),
|
||||||
]), style = lamb.utils.style)
|
]), style = lamb_engine.utils.style)
|
||||||
|
|
||||||
|
|
||||||
skip_to_end = False
|
skip_to_end = False
|
||||||
|
@ -142,20 +142,20 @@ class Runner:
|
||||||
print(f" Reducing... {k:,}", end = "\r")
|
print(f" Reducing... {k:,}", end = "\r")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
red_type, node = lamb.nodes.reduce(node)
|
red_type, node = lamb_engine.nodes.reduce(node)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
stop_reason = StopReason.INTERRUPT
|
stop_reason = StopReason.INTERRUPT
|
||||||
break
|
break
|
||||||
|
|
||||||
# If we can't reduce this expression anymore,
|
# If we can't reduce this expression anymore,
|
||||||
# it's in beta-normal form.
|
# it's in beta-normal form.
|
||||||
if red_type == lamb.nodes.ReductionType.NOTHING:
|
if red_type == lamb_engine.nodes.ReductionType.NOTHING:
|
||||||
stop_reason = StopReason.BETA_NORMAL
|
stop_reason = StopReason.BETA_NORMAL
|
||||||
break
|
break
|
||||||
|
|
||||||
# Count reductions
|
# Count reductions
|
||||||
k += 1
|
k += 1
|
||||||
if red_type == lamb.nodes.ReductionType.FUNCTION_APPLY:
|
if red_type == lamb_engine.nodes.ReductionType.FUNCTION_APPLY:
|
||||||
macro_expansions += 1
|
macro_expansions += 1
|
||||||
|
|
||||||
# Pause after step if necessary
|
# Pause after step if necessary
|
||||||
|
@ -163,17 +163,17 @@ class Runner:
|
||||||
try:
|
try:
|
||||||
s = prompt(
|
s = prompt(
|
||||||
message = FormattedText([
|
message = FormattedText([
|
||||||
("class:prompt", lamb.nodes.reduction_text[red_type]),
|
("class:prompt", lamb_engine.nodes.reduction_text[red_type]),
|
||||||
("class:prompt", f":{k:03} ")
|
("class:prompt", f":{k:03} ")
|
||||||
] + lamb.utils.lex_str(str(node))),
|
] + lamb_engine.utils.lex_str(str(node))),
|
||||||
style = lamb.utils.style,
|
style = lamb_engine.utils.style,
|
||||||
key_bindings = step_bindings
|
key_bindings = step_bindings
|
||||||
)
|
)
|
||||||
except KeyboardInterrupt or EOFError:
|
except KeyboardInterrupt or EOFError:
|
||||||
skip_to_end = True
|
skip_to_end = True
|
||||||
printf(FormattedText([
|
printf(FormattedText([
|
||||||
("class:warn", "Skipping to end."),
|
("class:warn", "Skipping to end."),
|
||||||
]), style = lamb.utils.style)
|
]), style = lamb_engine.utils.style)
|
||||||
|
|
||||||
# Print a space between step messages
|
# Print a space between step messages
|
||||||
if self.step_reduction:
|
if self.step_reduction:
|
||||||
|
@ -185,7 +185,7 @@ class Runner:
|
||||||
|
|
||||||
# Expand fully if necessary
|
# Expand fully if necessary
|
||||||
if self.full_expansion:
|
if self.full_expansion:
|
||||||
o, node = lamb.nodes.expand(node, force_all = True)
|
o, node = lamb_engine.nodes.expand(node, force_all = True)
|
||||||
macro_expansions += o
|
macro_expansions += o
|
||||||
|
|
||||||
if only_macro:
|
if only_macro:
|
||||||
|
@ -221,18 +221,18 @@ class Runner:
|
||||||
):
|
):
|
||||||
out_text += [
|
out_text += [
|
||||||
("class:ok", "\n\n => ")
|
("class:ok", "\n\n => ")
|
||||||
] + lamb.utils.lex_str(str(node))
|
] + lamb_engine.utils.lex_str(str(node))
|
||||||
|
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
FormattedText(out_text),
|
FormattedText(out_text),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
|
|
||||||
# Save to history
|
# Save to history
|
||||||
# Do this at the end so we don't always fully expand.
|
# Do this at the end so we don't always fully expand.
|
||||||
self.history.appendleft(
|
self.history.appendleft(
|
||||||
lamb.nodes.expand( # type: ignore
|
lamb_engine.nodes.expand( # type: ignore
|
||||||
node,
|
node,
|
||||||
force_all = True
|
force_all = True
|
||||||
)[1]
|
)[1]
|
||||||
|
@ -253,7 +253,7 @@ class Runner:
|
||||||
("class:code", macro.label),
|
("class:code", macro.label),
|
||||||
("class:text", " to "),
|
("class:text", " to "),
|
||||||
("class:code", str(macro.expr))
|
("class:code", str(macro.expr))
|
||||||
]), style = lamb.utils.style)
|
]), style = lamb_engine.utils.style)
|
||||||
|
|
||||||
# Apply a list of definitions
|
# Apply a list of definitions
|
||||||
def run(
|
def run(
|
||||||
|
@ -275,13 +275,13 @@ class Runner:
|
||||||
FormattedText([
|
FormattedText([
|
||||||
("class:warn", f"Unknown command \"{e.name}\"")
|
("class:warn", f"Unknown command \"{e.name}\"")
|
||||||
]),
|
]),
|
||||||
style = lamb.utils.style
|
style = lamb_engine.utils.style
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
cmd.commands[e.name](e, self)
|
cmd.commands[e.name](e, self)
|
||||||
|
|
||||||
# If this line is a plain expression, reduce it.
|
# If this line is a plain expression, reduce it.
|
||||||
elif isinstance(e, lamb.nodes.Node):
|
elif isinstance(e, lamb_engine.nodes.Node):
|
||||||
self.reduce(e, warnings = w)
|
self.reduce(e, warnings = w)
|
||||||
|
|
||||||
# We shouldn't ever get here.
|
# We shouldn't ever get here.
|
|
@ -45,10 +45,6 @@ requires = [ "setuptools>=61.0" ]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[tool.setuptools.packages.find]
|
||||||
where = ["lamb"]
|
where = ["lamb_engine"]
|
||||||
include = ["lamb*"]
|
include = ["lamb_engine*"]
|
||||||
namespaces = false
|
namespaces = false
|
||||||
|
|
||||||
[project.optional-dependencies]
|
|
||||||
# Used to build a standalone executable
|
|
||||||
pyinstaller = [ "pyinstaller==5.5" ]
|
|
Reference in New Issue