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
|
`:mdel [macro]` Delete a macro
|
||||||
|
|
||||||
|
`:clearmacros` Delete all macros
|
||||||
|
|
||||||
`:save [filename]`\
|
`: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.
|
`: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):
|
## Todo (pre-release, in this order):
|
||||||
- Fix :save
|
|
||||||
- Cleanup warnings
|
- Cleanup warnings
|
||||||
- Truncate long expressions in warnings
|
- Truncate long expressions in warnings
|
||||||
- Prevent macro-chaining recursion
|
- Prevent macro-chaining recursion
|
||||||
|
|
|
@ -163,20 +163,49 @@ def mdel(command, runner) -> None:
|
||||||
|
|
||||||
del runner.macro_table[target]
|
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(
|
@lamb_command(
|
||||||
help_text = "Show macros"
|
help_text = "Show macros"
|
||||||
)
|
)
|
||||||
def macros(command, runner) -> None:
|
def macros(command, runner) -> None:
|
||||||
printf(FormattedText([
|
if len(runner.macro_table) == 0:
|
||||||
("class:cmd_h", "\nDefined Macros:\n"),
|
printf(FormattedText([
|
||||||
] +
|
("class:warn", "No macros are defined."),
|
||||||
[
|
]),
|
||||||
("class:text", f"\t{name} \t {exp}\n")
|
style = lamb.utils.style
|
||||||
for name, exp in runner.macro_table.items()
|
)
|
||||||
]),
|
else:
|
||||||
style = lamb.utils.style
|
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(
|
@lamb_command(
|
||||||
help_text = "Clear the screen"
|
help_text = "Clear the screen"
|
||||||
|
|
|
@ -494,12 +494,18 @@ def print_node(node: Node, *, export: bool = False) -> str:
|
||||||
|
|
||||||
elif isinstance(n, Func):
|
elif isinstance(n, Func):
|
||||||
if s == Direction.UP:
|
if s == Direction.UP:
|
||||||
|
if isinstance(n.parent, Call):
|
||||||
|
out += "("
|
||||||
|
|
||||||
if isinstance(n.parent, Func):
|
if isinstance(n.parent, Func):
|
||||||
out += n.input.name
|
out += n.input.name
|
||||||
else:
|
else:
|
||||||
out += "λ" + n.input.name
|
out += "λ" + n.input.name
|
||||||
if not isinstance(n.left, Func):
|
if not isinstance(n.left, Func):
|
||||||
out += "."
|
out += "."
|
||||||
|
elif s == Direction.LEFT:
|
||||||
|
if isinstance(n.parent, Call):
|
||||||
|
out += ")"
|
||||||
|
|
||||||
elif isinstance(n, Call):
|
elif isinstance(n, Call):
|
||||||
if s == Direction.UP:
|
if s == Direction.UP:
|
||||||
|
|
Reference in New Issue