Adjust repl to allow dropping the parens around `?`
`?` with no arg also returns its own help text. Improve web help texts.
This commit is contained in:
parent
803935c637
commit
79a2d09995
15
src/env.c
15
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!");
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
15
src/web.h
15
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"
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue