diff --git a/lamb/commands.py b/lamb/commands.py index 08acd70..89db20b 100644 --- a/lamb/commands.py +++ b/lamb/commands.py @@ -36,7 +36,7 @@ def cmd_save(command, runner) -> None: if len(command.args) != 1: printf( HTML( - "Command :{command.name} takes exactly one argument." + f"Command :{command.name} takes exactly one argument." ), style = lamb.utils.style ) @@ -81,7 +81,7 @@ def cmd_load(command, runner): if len(command.args) != 1: printf( HTML( - "Command :{command.name} takes exactly one argument." + f"Command :{command.name} takes exactly one argument." ), style = lamb.utils.style ) @@ -145,7 +145,7 @@ def mdel(command, runner) -> None: if len(command.args) != 1: printf( HTML( - "Command :{command.name} takes exactly one argument." + f"Command :{command.name} takes exactly one argument." ), style = lamb.utils.style ) @@ -185,6 +185,76 @@ def clear(command, runner) -> None: clear_screen() lamb.utils.show_greeting() +@lamb_command( + help_text = "Get or set reduction limit" +) +def rlimit(command, runner) -> None: + if len(command.args) == 0: + if runner.reduction_limit is None: + printf( + HTML( + "No reduction limit is set" + ), + style = lamb.utils.style + ) + else: + printf( + HTML( + f"Reduction limit is {runner.reduction_limit:,}" + ), + style = lamb.utils.style + ) + return + + elif len(command.args) != 1: + printf( + HTML( + f"Command :{command.name} takes exactly one argument." + ), + style = lamb.utils.style + ) + return + + t = command.args[0] + if t.lower() == "none": + runner.reduction_limit = None + printf( + HTML( + f"Removed reduction limit" + ), + style = lamb.utils.style + ) + return + + try: + t = int(t) + except ValueError: + printf( + HTML( + "Reduction limit must be a positive integer or \"none\"." + ), + style = lamb.utils.style + ) + return + + if 50 > t: + printf( + HTML( + "Reduction limit must be at least 50." + ), + style = lamb.utils.style + ) + return + + runner.reduction_limit = t + printf( + HTML( + f"Set reduction limit to {t:,}" + ), + style = lamb.utils.style + ) + + @lamb_command( help_text = "Print this help" diff --git a/lamb/parser.py b/lamb/parser.py index 158a1cf..ac5da20 100755 --- a/lamb/parser.py +++ b/lamb/parser.py @@ -54,7 +54,7 @@ class LambdaParser: (self.lp + self.pp_call + self.rp) ) - self.pp_command = pp.Suppress(":") + pp.Word(pp.alphas + "_") + pp.Word(pp.alphas + "_")[0, ...] + self.pp_command = pp.Suppress(":") + pp.Word(pp.alphas + "_") + pp.Word(pp.alphas + pp.nums + "_")[0, ...] self.pp_all = ( diff --git a/lamb/runner.py b/lamb/runner.py index a5cc3a0..f9b16f1 100644 --- a/lamb/runner.py +++ b/lamb/runner.py @@ -1,7 +1,6 @@ from prompt_toolkit import PromptSession from prompt_toolkit.formatted_text import FormattedText from prompt_toolkit import print_formatted_text as printf -from prompt_toolkit.shortcuts import clear as clear_screen import enum import math import time @@ -86,7 +85,9 @@ class Runner: self.iter_update = 231 def prompt(self): - return self.prompt_session.prompt(message = self.prompt_message) + return self.prompt_session.prompt( + message = self.prompt_message + ) def parse(self, line): e = self.parser.parse_line(line) @@ -151,7 +152,8 @@ class Runner: ("class:text", str(macro_expansions)), ("class:result_header", f"\nReductions: "), - ("class:text", str(i)) + ("class:text", f"{i} "), + ("class:muted", f"(Limit: {self.reduction_limit:,})") ] if (stop_reason == StopReason.BETA_NORMAL or stop_reason == StopReason.LOOP_DETECTED): diff --git a/lamb/utils.py b/lamb/utils.py index 276070d..88049b4 100644 --- a/lamb/utils.py +++ b/lamb/utils.py @@ -11,6 +11,7 @@ style = Style.from_dict({ # type: ignore "err": "#FF0000", "prompt": "#00FFFF", "ok": "#B4EC85", + "muted": "#AAAAAA", # Syntax "syn_macro": "#FF00FF",