Crates.io | gameshell |
lib.rs | gameshell |
version | 0.4.1 |
source | src |
created_at | 2019-09-15 13:48:50.123246 |
updated_at | 2023-02-25 23:10:04.9902 |
description | Simple lisp/bash-like shell to integrate into programs |
homepage | https://docs.rs/gameshell |
repository | https://github.com/Omen-of-Aecio/gameshell |
max_upload_size | |
id | 164902 |
size | 64,103 |
GameShell is a fast interpreter for integration into Rust applications. It combines the features of lisp and bash so it can be practical.
GameShell is a language that is very simple, its basic form is the following:
command argument-1 argument-2 ...
It splits all commands by line and all arguments by whitespace.
We can nest commands by using parentheses:
command-1 (command-2 argument-1 argument-2) argument-3
If we want, we can also run these on multiple lines
command-1 (
command-2 argument-1 argument-2
) argument-3
When there are no more ()-nestings, the next newline will complete a command.
Literal strings are made by using the built-in #
command:
print (#This is a literal string)
A command is a function that looks like this:
fn handler(context: &mut Context, args: &[Type]) -> Result<String, String> {
...
}
You provide the context and GameShell will provide the args
list. You can then do whatever you want inside the handler. If the handler returns Ok
, that result can be used as an argument to another command, if it returns Err
, any nested computation is cancelled.
Commands are tied to a Command Matcher (cmdmat
for short). You register a command matcher to a handler:
eval.register((&[("command", None)], handler)).unwrap();
This matches the command command
with 0 arguments. The None
is a so-called Decider
, it will parse any arguments given to command
, and decide whether the invocation is valid or not.
Please see the predicates module documentation for more details and examples.
?
as a command, returns a list of registered commands that match a regex#
pseudo-command.a (b (c d))