From e8bd6997b9f5a62bd55ca0e6f7eeb9d20e7ad0aa Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 11 Nov 2022 18:31:37 -0800 Subject: [PATCH] Added support for arguments --- README.md | 16 ++++++++++------ lamb_engine/__main__.py | 17 +++++++++++++++++ pyproject.toml | 2 +- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8f2e59b..33e53e8 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,12 @@ There are many useful macros in [macros.lamb](./macros.lamb). Download the file, ==> :load macros.lamb ``` -You may use up/down arrows to recall history. +You can also pass files to lamb directly to have them loaded at startup: +``` +lamb file1 file2 +``` + +Use your up/down arrows to recall history. Have fun! @@ -61,16 +66,18 @@ Have fun! Lamb understands many commands. Prefix them with a `:` in the prompt. -`:help` Prints a help message +`:help` Print a help message `:clear` Clear the screen `:rlimit [int | None]` Set maximum reduction limit. `:rlimit none` sets no limit. -`:macros` List macros in the current environment. +`:macros` List macros. `:mdel [macro]` Delete a macro +`:delmac` Delete all macros + `:step [yes | no]` Enable or disable step-by-step reduction. Toggle if no argument is given. When reducing by steps, the prompt tells you what kind of reduction was done last: - `M`: Macro expansion @@ -80,8 +87,6 @@ Lamb understands many commands. Prefix them with a `:` in the prompt. `:expand [yes | no]` Enable or disable full expansion. Toggle if no argument is given. If full expansion is enabled, ALL macros will be expanded when printing output. -`:delmac` Delete all macros - `:save [filename]` \ `:load [filename]` \ Save or load macros from a file. @@ -95,7 +100,6 @@ The lines in a file look exactly the same as regular entries in the prompt, but - Truncate long expressions in warnings - Loop detection - α-equivalence check - - Command-line options (load a file) - Unchurch command: make church numerals human-readable - Better Syntax highlighting - Complete file names and commands diff --git a/lamb_engine/__main__.py b/lamb_engine/__main__.py index d386dbc..b863849 100755 --- a/lamb_engine/__main__.py +++ b/lamb_engine/__main__.py @@ -3,6 +3,7 @@ from prompt_toolkit import print_formatted_text as printf from prompt_toolkit.formatted_text import FormattedText from prompt_toolkit.formatted_text import to_plain_text from pyparsing import exceptions as ppx +import sys import lamb_engine @@ -22,6 +23,22 @@ def main(): ]) ) + # Load files passed as arguments + if len(sys.argv) > 1: + for i in range(1, len(sys.argv)): + try: + printf(FormattedText([ + ("class:warn", "\nLoading file "), + ("class:code", sys.argv[i]), + ]), style = lamb_engine.utils.style) + r.run(":load " + sys.argv[i]) + except: + printf(FormattedText([ + ("class:err", "Error. Does this file exist?"), + ]), style = lamb_engine.utils.style) + + print("") + while True: try: i = r.prompt() diff --git a/pyproject.toml b/pyproject.toml index 1a6d33d..759aba2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ lamb = "lamb_engine:main" [project] name = "lamb_engine" description = "A lambda calculus engine" -version = "1.1.5" +version = "1.1.6" dependencies = [ "prompt-toolkit==3.0.31", "pyparsing==3.0.9"