diff options
| author | Mistivia <i@mistivia.com> | 2025-06-17 09:12:35 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-06-17 09:12:35 +0800 |
| commit | 6f1cfbda4a519ad8a232d126539a2732ab43c671 (patch) | |
| tree | fe33602e4dd8419b216ca755ea91c63c72ffa65b /src/parser.c | |
init
Diffstat (limited to 'src/parser.c')
| -rw-r--r-- | src/parser.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..d164186 --- /dev/null +++ b/src/parser.c @@ -0,0 +1,38 @@ +#include "parser.h" + +#include <ctype.h> +#include <stdlib.h> + +static void skip_spaces(Parser *ctx) { + while (isspace(parser_peek(ctx))) { + parser_getchar(ctx); + } +} + +ParseResult ParseOk(SExpRef ref) { + return (ParseResult){ .val = ref, .errmsg = NULL }; +} + +ParseResult ParseErr(const char *msg) { + return (ParseResult){ .val = {-1}, .errmsg = msg }; +} + +ParseResult parse_sexp(Parser *ctx) { + skip_spaces(ctx); + int next = parser_peek(ctx); + if (next == '(') { + return parse_list(ctx); + } else if (next == ',') { + parser_getchar(ctx); + if (parser_peek(ctx) == '@') { + return parse_slicing_unquote(ctx); + } + return parse_unquote(ctx); + } else if (next == '`') { + return parse_quasi(ctx); + } else if (next == '\'') { + return parse_quote(ctx); + } + return parse_atom(ctx); +} + |
