diff --git a/include/table.h b/include/table.h index aae5415..780c0d3 100644 --- a/include/table.h +++ b/include/table.h @@ -68,6 +68,22 @@ void libab_table_init(libab_table* table); * @return the table entry, or NULL if an entry was not found. */ libab_table_entry* libab_table_search(libab_table* table, const char* string); +/** + * Searches for the given string in the table, returning a value only + * if it is an operator. + * @param table the table to search. + * @param string the string to search for. + * @return the found operator, or NULL if it was not found. + */ +libab_operator* libab_table_search_operator(libab_table* table, const char* string); +/** + * Searches for the given string in the table, returning a value only + * if it is a function. + * @param table the table to search. + * @param string the string to search for. + * @return the found function, or NULL if it was not found. + */ +libab_function* libab_table_search_function(libab_table* table, const char* string); /** * Stores the given entry in the table under the given key. * @param table the table to store the entry into. diff --git a/src/table.c b/src/table.c index eb9181f..23af601 100644 --- a/src/table.c +++ b/src/table.c @@ -14,6 +14,22 @@ libab_table_entry* table_search(libab_table* table, const char* string) { } while(table && to_return == NULL); return to_return; } +libab_operator* libab_table_search_operator(libab_table* table, const char* string) { + libab_table_entry* entry = table_search(table, string); + libab_operator* to_return = NULL; + if(entry && entry->variant == ENTRY_OPERATOR) { + to_return = &entry->data_u.op; + } + return to_return; +} +libab_function* libab_table_search_function(libab_table* table, const char* string) { + libab_table_entry* entry = table_search(table, string); + libab_function* to_return = NULL; + if(entry && entry->variant == ENTRY_FUNCTION) { + to_return = &entry->data_u.function; + } + return to_return; +} libab_result libab_table_put(libab_table* table, const char* string, libab_table_entry* entry) { return libab_convert_ds_result(ht_put(&table->table, string, entry)); }