Make some functions public.

This commit is contained in:
Danila Fedorin 2018-08-10 18:39:26 -07:00
parent b0c2eb5a5e
commit 4a058384c1
4 changed files with 32 additions and 13 deletions

View File

@ -216,6 +216,14 @@ void libab_get_true_value(libab* ab, libab_ref* into);
* @param into the reference into which to store the false value.
*/
void libab_get_false_value(libab* ab, libab_ref* into);
/**
* Get the boolean value corresponding to val from this
* libab instance.
* @param ab the instance to get the value from.
* @param val the true or false value to represent.
* @param into the reference into which to store the value.
*/
void libab_get_bool_value(libab* ab, int val, libab_ref* into);
/**
* Executes the given string of code.

View File

@ -178,5 +178,12 @@ void* libab_unwrap_value(libab_ref* ref);
* @return the value at the given index.
*/
void* libab_unwrap_param(libab_ref_vec* vec, size_t index);
/**
* Sanitizes a string to avoid liblex compilation errors.
* @param to the buffer to store the sanitized string to.
* @param from the string to sanitize.
* @param buffer_size the size of the to buffer.
*/
void libab_sanitize(char* to, const char* from, size_t buffer_size);
#endif

View File

@ -84,18 +84,6 @@ libab_result libab_init(libab* ab, void* (*parse_function)(const char*),
return result;
}
void _sanitize(char* to, const char* from, size_t buffer_size) {
size_t index = 0;
while (*from && index < (buffer_size - 2)) {
if (*from == '+' || *from == '*' || *from == '\\' ||
*from == '|' || *from == '[' || *from == ']' || *from == '(' ||
*from == ')')
to[index++] = '\\';
to[index++] = *(from++);
}
to[index] = '\0';
}
void _initialize_behavior(libab_behavior* behavior, libab_ref* type,
libab_function_ptr func) {
behavior->variant = BIMPL_INTERNAL;
@ -120,7 +108,7 @@ libab_result _register_operator(libab* ab, const char* op,
}
if (result == LIBAB_SUCCESS) {
_sanitize(op_buffer, op, 8);
libab_sanitize(op_buffer, op, 8);
result = libab_convert_lex_result(
eval_config_add(&ab->lexer.config, op_buffer, TOKEN_OP));
}
@ -412,6 +400,10 @@ void libab_get_false_value(libab* ab, libab_ref* into) {
libab_interpreter_false_value(&ab->intr, into);
}
void libab_get_bool_value(libab* ab, int val, libab_ref* into) {
val ? libab_get_true_value(ab, into) : libab_get_false_value(ab, into);
}
libab_result _create_tree(libab* ab, const char* string, libab_tree** into) {
libab_result result = LIBAB_SUCCESS;
ll tokens;

View File

@ -416,3 +416,15 @@ void* libab_unwrap_param(libab_ref_vec* vec, size_t index) {
libab_ref_free(&temp);
return data;
}
void libab_sanitize(char* to, const char* from, size_t buffer_size) {
size_t index = 0;
while (*from && index < (buffer_size - 2)) {
if (*from == '+' || *from == '*' || *from == '\\' ||
*from == '|' || *from == '[' || *from == ']' || *from == '(' ||
*from == ')')
to[index++] = '\\';
to[index++] = *(from++);
}
to[index] = '\0';
}