aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-05-25 13:50:26 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-05-25 13:50:26 +0200
commit3929106e5d6312eb2d94d0c1b1f99185cbcdb178 (patch)
tree91cfef24a9d2ce18e946cbad2fcbc8840d535270
parent1f71c5202c3573871f9c37df26d62bd9ed255c0b (diff)
downloadell-3929106e5d6312eb2d94d0c1b1f99185cbcdb178.tar.gz
ell-3929106e5d6312eb2d94d0c1b1f99185cbcdb178.tar.xz
ell-3929106e5d6312eb2d94d0c1b1f99185cbcdb178.zip
Add "parse"
-rw-r--r--ell.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/ell.c b/ell.c
index a73d0a4..8234432 100644
--- a/ell.c
+++ b/ell.c
@@ -1029,6 +1029,21 @@ defn (fn_system) {
return check (ctx, (*result = new_number (system (command->value))));
}
+defn (fn_parse) {
+ struct item *body = args;
+ if (!body || body->type != ITEM_STRING)
+ return set_error (ctx, "first argument must be string");
+
+ struct parser parser;
+ parser_init (&parser, args->value, args->len);
+ const char *e = NULL;
+ bool ok = check (ctx, (*result = new_list (parser_run (&parser, &e))));
+ if (e)
+ ok = set_error (ctx, "%s", e);
+ parser_free (&parser);
+ return ok;
+}
+
defn (fn_plus) {
double res = 0.0;
for (; args; args = args->next) {
@@ -1205,6 +1220,7 @@ init_runtime_library (struct context *ctx) {
&& native_register (ctx, "print", fn_print)
&& native_register (ctx, "..", fn_concatenate)
&& native_register (ctx, "system", fn_system)
+ && native_register (ctx, "parse", fn_parse)
&& native_register (ctx, "+", fn_plus)
&& native_register (ctx, "-", fn_minus)
&& native_register (ctx, "*", fn_multiply)