From 79a2d0999581cc9502d0c18bb87f9bc43e13ad13 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Tue, 29 Mar 2022 15:30:21 -0400 Subject: [PATCH] Adjust repl to allow dropping the parens around `?` `?` with no arg also returns its own help text. Improve web help texts. --- src/env.c | 15 ++++++++++----- src/pebblisp.c | 6 ++++++ src/web.h | 15 ++++++++------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/env.c b/src/env.c index ea4d16f..c4df943 100644 --- a/src/env.c +++ b/src/env.c @@ -283,12 +283,16 @@ void printColored(const char* code) } fn(help, - "Displays help text for the given function.\n" - "Currently requires the function name as a string, but future syntactic sugar may\n" - "loosen this requirement.\n" - "(? \"+\") => \"(+ 1 2) => 3\"" + "Gets a string with help text for the given function.\n" + "For example:\n" + " (? islist) => \"(islist (1 2 3)) => T\"" ) { - const char* symbol = params[0].string; + const char* symbol; + if (!length || !params[0].string || params[0].string[0] == '\0') { + symbol = "?"; + } else { + symbol = params[0].string; + } for (int i = 0; i < currentHelp; i++) { struct helpText h = helpTexts[i]; if (strcmp(symbol, h.symbol) == 0) { @@ -308,6 +312,7 @@ fn(help, return text; } } + return nullTerminated("Help not found!"); } diff --git a/src/pebblisp.c b/src/pebblisp.c index 2934e99..a01464a 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -606,6 +606,12 @@ void repl(struct Environment* env) break; } add_history(buf); + if (buf[0] == '?' && (buf[1] == ' ' || buf[1] == '\0')) { + char* oldBuf = buf; + buf = malloc(sizeof(char) * strlen(buf + 3)); + sprintf(buf, "(%s)", oldBuf); + free(oldBuf); + } Object o = parseEval(buf, env); size_t length; char *output = stringObj(&o, &length); diff --git a/src/web.h b/src/web.h index 9c539d7..6bd243f 100644 --- a/src/web.h +++ b/src/web.h @@ -9,16 +9,17 @@ fn(startServer, ); fn(addGetRoute, - "Note: Implementation bugs currently prevent using an inline lambda.\n" - " (def homepage (fn () (\"Hello, world!\")))\n" - " (get \"/\" homepage)\n" - " (def queryPage (fn (req) (req's queryParams)))\n" - " (get \"/x\" queryPage)\n" + "Adds a GET route at the given path with the given function.\n" + " (get \"/\" (fn () (\"Hello, world!\")))\n" + " (get \"/parampath\" (fn (req) (req's queryParams)))\n" " (serve)\n" + "Also see: (serve)\n" ); fn(addPostRoute, - "Note: Implementation bugs currently prevent using an inline lambda.\n" - " (def homepage (fn () (\"Hello, world!\")));(post \"/\" homepage)\n" + "Adds a POST route at the given path with the given function.\n" + "Note: Can't do anything with POSTed data yet.\n" + " (post \"/\" (fn () (\"Hello, world!\")))\n" " (serve)\n" + "Also see: (serve)\n" );