Fixed :save & added new commands
parent
cf2d82acc6
commit
ab682ef700
|
@ -57,6 +57,8 @@ Lamb comes with a few commands. Prefix them with a `:`
|
|||
|
||||
`:mdel [macro]` Delete a macro
|
||||
|
||||
`:clearmacros` Delete all macros
|
||||
|
||||
`:save [filename]`\
|
||||
`:load [filename]` Save or load the current environment to a file. The lines in a file look exactly the same as regular entries in the prompt, but must only contain macro definitions.
|
||||
|
||||
|
@ -75,7 +77,6 @@ Lamb treats each λ expression as a binary tree. Variable binding and reduction
|
|||
|
||||
|
||||
## Todo (pre-release, in this order):
|
||||
- Fix :save
|
||||
- Cleanup warnings
|
||||
- Truncate long expressions in warnings
|
||||
- Prevent macro-chaining recursion
|
||||
|
|
|
@ -163,20 +163,49 @@ def mdel(command, runner) -> None:
|
|||
|
||||
del runner.macro_table[target]
|
||||
|
||||
@lamb_command(
|
||||
help_text = "Delete all macros"
|
||||
)
|
||||
def clearmacros(command, runner) -> None:
|
||||
confirm = runner.prompt_session.prompt(
|
||||
message = FormattedText([
|
||||
("class:warn", "Are you sure? "),
|
||||
("class:text", "[yes/no]: ")
|
||||
])
|
||||
).lower()
|
||||
|
||||
if confirm != "yes":
|
||||
printf(
|
||||
HTML(
|
||||
"<err>Cancelled.</err>"
|
||||
),
|
||||
style = lamb.utils.style
|
||||
)
|
||||
return
|
||||
|
||||
runner.macro_table = {}
|
||||
|
||||
|
||||
@lamb_command(
|
||||
help_text = "Show macros"
|
||||
)
|
||||
def macros(command, runner) -> None:
|
||||
printf(FormattedText([
|
||||
("class:cmd_h", "\nDefined Macros:\n"),
|
||||
] +
|
||||
[
|
||||
("class:text", f"\t{name} \t {exp}\n")
|
||||
for name, exp in runner.macro_table.items()
|
||||
]),
|
||||
style = lamb.utils.style
|
||||
)
|
||||
if len(runner.macro_table) == 0:
|
||||
printf(FormattedText([
|
||||
("class:warn", "No macros are defined."),
|
||||
]),
|
||||
style = lamb.utils.style
|
||||
)
|
||||
else:
|
||||
printf(FormattedText([
|
||||
("class:cmd_h", "\nDefined Macros:\n"),
|
||||
] +
|
||||
[
|
||||
("class:text", f"\t{name} \t {exp}\n")
|
||||
for name, exp in runner.macro_table.items()
|
||||
]),
|
||||
style = lamb.utils.style
|
||||
)
|
||||
|
||||
@lamb_command(
|
||||
help_text = "Clear the screen"
|
||||
|
|
|
@ -494,12 +494,18 @@ def print_node(node: Node, *, export: bool = False) -> str:
|
|||
|
||||
elif isinstance(n, Func):
|
||||
if s == Direction.UP:
|
||||
if isinstance(n.parent, Call):
|
||||
out += "("
|
||||
|
||||
if isinstance(n.parent, Func):
|
||||
out += n.input.name
|
||||
else:
|
||||
out += "λ" + n.input.name
|
||||
if not isinstance(n.left, Func):
|
||||
out += "."
|
||||
elif s == Direction.LEFT:
|
||||
if isinstance(n.parent, Call):
|
||||
out += ")"
|
||||
|
||||
elif isinstance(n, Call):
|
||||
if s == Direction.UP:
|
||||
|
|
Reference in New Issue