Implement reserved operators.

This commit is contained in:
2018-06-21 19:00:45 -07:00
parent a5429ae2c8
commit 48300cd86e
3 changed files with 41 additions and 1 deletions

View File

@@ -2,11 +2,38 @@
#include "string.h"
#include "util.h"
libab_result _behavior_assign(libab* ab, libab_ref* scope,
libab_tree* left, libab_tree* right,
libab_ref* into) {
libab_result result = LIBAB_SUCCESS;
if(left->variant == TREE_ID) {
result = libab_run_tree_scoped(ab, right, scope, into);
if(result == LIBAB_SUCCESS) {
result = libab_put_table_value(libab_ref_get(scope), left->string_value, into);
}
if(result != LIBAB_SUCCESS) {
libab_ref_free(into);
}
} else {
result = LIBAB_UNEXPECTED;
}
if(result != LIBAB_SUCCESS) {
libab_ref_null(into);
}
return result;
}
static const libab_reserved_operator libab_reserved_operators[] = {{
"=", /* Assignment */
0, /* Lowest precedence */
1 /* Right associative, a = b = 6 should be a = (b = 6) */
1, /* Right associative, a = b = 6 should be a = (b = 6) */
_behavior_assign
}};
static const size_t element_count =
sizeof(libab_reserved_operators) / sizeof(libab_reserved_operator);