Fix code to stick to proper naming convention.
This commit is contained in:
parent
732ff47f44
commit
e5351c17a2
|
@ -9,7 +9,7 @@
|
|||
* a string and converting it into
|
||||
* tokens.
|
||||
*/
|
||||
struct lexer {
|
||||
struct libab_lexer_s {
|
||||
/**
|
||||
* The liblex configuration used
|
||||
* to convert the string into tokens.
|
||||
|
@ -20,7 +20,7 @@ struct lexer {
|
|||
/**
|
||||
* A token that is produced by the lexer.
|
||||
*/
|
||||
struct lexer_match {
|
||||
struct libab_lexer_match_s {
|
||||
/**
|
||||
* The line that this token was found on.
|
||||
*/
|
||||
|
@ -51,7 +51,7 @@ struct lexer_match {
|
|||
* in order to tag meaningful sequences
|
||||
* of characters.
|
||||
*/
|
||||
enum lexer_token {
|
||||
enum libab_lexer_token_e {
|
||||
TOKEN_CHAR = 0,
|
||||
TOKEN_ID,
|
||||
TOKEN_TRUE,
|
||||
|
@ -72,9 +72,9 @@ enum lexer_token {
|
|||
TOKEN_LAST
|
||||
};
|
||||
|
||||
typedef struct lexer lexer;
|
||||
typedef enum lexer_token lexer_token;
|
||||
typedef struct lexer_match lexer_match;
|
||||
typedef struct libab_lexer_s libab_lexer;
|
||||
typedef enum libab_lexer_token_e libab_lexer_token;
|
||||
typedef struct libab_lexer_match_s libab_lexer_match;
|
||||
|
||||
/**
|
||||
* Initializes the given lexer,
|
||||
|
@ -82,7 +82,7 @@ typedef struct lexer_match lexer_match;
|
|||
* @param lexer the lexer to intiailize.
|
||||
* @return the result of the operation (can be MALLOC on failed allocation.)
|
||||
*/
|
||||
libab_result lexer_init(lexer* lexer);
|
||||
libab_result libab_lexer_init(libab_lexer* lexer);
|
||||
/**
|
||||
* Turns the given input string into tokens.
|
||||
* @param lexer the lexer to use to turn the string into tokens.
|
||||
|
@ -90,19 +90,19 @@ libab_result lexer_init(lexer* lexer);
|
|||
* @param lex_into the list which should be populated with matches.
|
||||
* @return the result of the operation.
|
||||
*/
|
||||
libab_result lexer_lex(lexer* lexer, const char* string, ll* lext_into);
|
||||
libab_result libab_lexer_lex(libab_lexer* lexer, const char* string, ll* lext_into);
|
||||
/**
|
||||
* Releases the memory associated with the given lexer,
|
||||
* removing all registered patterns from it.
|
||||
* @param lexer the lexer to free.
|
||||
* @return the result of the operation.
|
||||
*/
|
||||
libab_result lexer_free(lexer* lexer);
|
||||
libab_result libab_lexer_free(libab_lexer* lexer);
|
||||
/**
|
||||
* Function intended to be passed to "foreach" calls
|
||||
* in libds. lexer_lex allocates matches, and passing this function
|
||||
* to foreach will free the memory allocated for the matches.
|
||||
*/
|
||||
int lexer_foreach_match_free(void* data, va_list args);
|
||||
int libab_lexer_foreach_match_free(void* data, va_list args);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* An enum that represents the outcomes of
|
||||
* libabacus functions that can fail.
|
||||
*/
|
||||
enum libab_result {
|
||||
enum libab_result_e {
|
||||
LIBAB_SUCCESS,
|
||||
LIBAB_MALLOC,
|
||||
LIBAB_BAD_PATTERN,
|
||||
|
@ -14,6 +14,6 @@ enum libab_result {
|
|||
LIBAB_UNEXPECTED
|
||||
};
|
||||
|
||||
typedef enum libab_result libab_result;
|
||||
typedef enum libab_result_e libab_result;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
* @param to_convert the code to convert.
|
||||
* @return the libabacus equivalent of the error code.
|
||||
*/
|
||||
libab_result convert_lex_result(liblex_result to_convert);
|
||||
libab_result libab_convert_lex_result(liblex_result to_convert);
|
||||
/**
|
||||
* Converts a result code from libds to libabacus.
|
||||
* @param to_convert the code to convert.
|
||||
* @return the libabacus equivalent of the error code.
|
||||
*/
|
||||
libab_result convert_ds_result(libds_result to_convert);
|
||||
libab_result libab_convert_ds_result(libds_result to_convert);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
* @param string the string to use for determining token values.
|
||||
* @param store_into tree pointer to store the new data into.
|
||||
*/
|
||||
libab_result parse_tokens(ll* tokens, const char* string, tree** store_into);
|
||||
libab_result libab_parse_tokens(ll* tokens, const char* string, libab_tree** store_into);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
* as types, functions, and variables in an
|
||||
* environment with scopes.
|
||||
*/
|
||||
struct table {
|
||||
struct libab_table_s {
|
||||
/**
|
||||
* The "parent" scope of this table.
|
||||
*/
|
||||
struct table* parent;
|
||||
struct libab_table_s* parent;
|
||||
/**
|
||||
* The hash table used to store the data.
|
||||
*/
|
||||
|
@ -26,7 +26,7 @@ struct table {
|
|||
* Enum that represents the type of a table
|
||||
* entry.
|
||||
*/
|
||||
enum table_entry_variant {
|
||||
enum libab_table_entry_variant_e {
|
||||
ENTRY_VALUE,
|
||||
ENTRY_TYPE,
|
||||
ENTRY_FUNCTION
|
||||
|
@ -35,34 +35,34 @@ enum table_entry_variant {
|
|||
/**
|
||||
* An entry in the table.
|
||||
*/
|
||||
struct table_entry {
|
||||
struct libab_table_entry_s {
|
||||
/**
|
||||
* The type of this entry.
|
||||
*/
|
||||
enum table_entry_variant variant;
|
||||
enum libab_table_entry_variant_e variant;
|
||||
};
|
||||
|
||||
typedef struct table table;
|
||||
typedef enum table_entry_variant table_entry_variant;
|
||||
typedef struct table_entry table_entry;
|
||||
typedef struct libab_table_s libab_table;
|
||||
typedef enum libab_table_entry_variant_e libab_table_entry_variant;
|
||||
typedef struct libab_table_entry_s libab_table_entry;
|
||||
|
||||
/**
|
||||
* Initializes the given table.
|
||||
* @param table the table to initialize.
|
||||
*/
|
||||
void table_init(table* table);
|
||||
void libab_table_init(libab_table* table);
|
||||
/**
|
||||
* Searches for the given string in the table.
|
||||
* @param table the table to search.
|
||||
* @param string the string to search for.
|
||||
* @return the table entry, or NULL if an entry was not found.
|
||||
*/
|
||||
table_entry* table_search(table* table, const char* string);
|
||||
libab_table_entry* libab_table_search(libab_table* table, const char* string);
|
||||
/**
|
||||
* Frees the resources allocated by the
|
||||
* given table.
|
||||
* @param table the table to free.
|
||||
*/
|
||||
void table_free(table* table);
|
||||
void libab_table_free(libab_table* table);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
/**
|
||||
* Enum to represent the variant of a tree node.
|
||||
*/
|
||||
enum tree_variant {
|
||||
enum libab_tree_variant_e {
|
||||
NONE,
|
||||
BASE,
|
||||
ID,
|
||||
|
@ -31,11 +31,11 @@ enum tree_variant {
|
|||
/**
|
||||
* A tree node that has been parsed from the input tokens.
|
||||
*/
|
||||
struct tree {
|
||||
struct libab_tree_s {
|
||||
/**
|
||||
* The variant of tree node.
|
||||
*/
|
||||
enum tree_variant variant;
|
||||
enum libab_tree_variant_e variant;
|
||||
/**
|
||||
* The string value of this tree, if applicable.
|
||||
*/
|
||||
|
@ -70,7 +70,7 @@ struct tree {
|
|||
size_t to;
|
||||
};
|
||||
|
||||
typedef enum tree_variant tree_variant;
|
||||
typedef struct tree tree;
|
||||
typedef enum libab_tree_variant_e libab_tree_variant;
|
||||
typedef struct libab_tree_s libab_tree;
|
||||
|
||||
#endif
|
||||
|
|
26
src/lexer.c
26
src/lexer.c
|
@ -4,7 +4,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
libab_result lexer_init(lexer* lexer) {
|
||||
libab_result libab_lexer_init(libab_lexer* lexer) {
|
||||
size_t i;
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
const char* words[] = {
|
||||
|
@ -23,7 +23,7 @@ libab_result lexer_init(lexer* lexer) {
|
|||
"for",
|
||||
"return"
|
||||
};
|
||||
lexer_token tokens[] = {
|
||||
libab_lexer_token tokens[] = {
|
||||
TOKEN_CHAR,
|
||||
TOKEN_ID,
|
||||
TOKEN_TRUE,
|
||||
|
@ -39,11 +39,11 @@ libab_result lexer_init(lexer* lexer) {
|
|||
TOKEN_KW_FOR,
|
||||
TOKEN_KW_RETURN
|
||||
};
|
||||
const size_t count = sizeof(tokens)/sizeof(lexer_token);
|
||||
const size_t count = sizeof(tokens)/sizeof(libab_lexer_token);
|
||||
|
||||
eval_config_init(&lexer->config);
|
||||
for(i = 0; i < count && result == LIBAB_SUCCESS; i++) {
|
||||
result = convert_lex_result(
|
||||
result = libab_convert_lex_result(
|
||||
eval_config_add(&lexer->config, words[i], tokens[i]));
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ struct lexer_state {
|
|||
};
|
||||
int _lexer_foreach_convert_match(void* data, va_list args) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
lexer_match* new_match;
|
||||
libab_lexer_match* new_match;
|
||||
match* match = data;
|
||||
struct lexer_state* state = va_arg(args, struct lexer_state*);
|
||||
char first_char = state->source[match->from];
|
||||
|
@ -73,7 +73,7 @@ int _lexer_foreach_convert_match(void* data, va_list args) {
|
|||
new_match->to = match->to;
|
||||
new_match->line_from = state->line_from;
|
||||
new_match->line = state->line;
|
||||
result = convert_ds_result(ll_append(state->matches, new_match));
|
||||
result = libab_convert_ds_result(ll_append(state->matches, new_match));
|
||||
if(result != LIBAB_SUCCESS) {
|
||||
free(new_match);
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ int _lexer_foreach_convert_match(void* data, va_list args) {
|
|||
return result;
|
||||
}
|
||||
|
||||
libab_result lexer_lex(lexer* lexer, const char* string, ll* lex_into) {
|
||||
libab_result libab_lexer_lex(libab_lexer* lexer, const char* string, ll* lex_into) {
|
||||
libab_result result;
|
||||
ll raw_matches;
|
||||
struct lexer_state state;
|
||||
|
@ -95,7 +95,7 @@ libab_result lexer_lex(lexer* lexer, const char* string, ll* lex_into) {
|
|||
state.matches = lex_into;
|
||||
state.source = string;
|
||||
|
||||
result = convert_lex_result(
|
||||
result = libab_convert_lex_result(
|
||||
eval_all(string, 0, &lexer->config, &raw_matches));
|
||||
|
||||
if(result == LIBAB_SUCCESS) {
|
||||
|
@ -104,7 +104,7 @@ libab_result lexer_lex(lexer* lexer, const char* string, ll* lex_into) {
|
|||
}
|
||||
|
||||
if(result != LIBAB_SUCCESS) {
|
||||
ll_foreach(lex_into, NULL, compare_always, lexer_foreach_match_free);
|
||||
ll_foreach(lex_into, NULL, compare_always, libab_lexer_foreach_match_free);
|
||||
}
|
||||
|
||||
ll_foreach(&raw_matches, NULL, compare_always, eval_foreach_match_free);
|
||||
|
@ -112,10 +112,10 @@ libab_result lexer_lex(lexer* lexer, const char* string, ll* lex_into) {
|
|||
|
||||
return result;
|
||||
}
|
||||
libab_result lexer_free(lexer* lexer) {
|
||||
return convert_lex_result(eval_config_free(&lexer->config));
|
||||
libab_result libab_lexer_free(libab_lexer* lexer) {
|
||||
return libab_convert_lex_result(eval_config_free(&lexer->config));
|
||||
}
|
||||
int lexer_foreach_match_free(void* data, va_list args) {
|
||||
free((lexer_match*) data);
|
||||
int libab_lexer_foreach_match_free(void* data, va_list args) {
|
||||
free((libab_lexer_match*) data);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "libabacus_util.h"
|
||||
|
||||
libab_result convert_lex_result(liblex_result to_convert) {
|
||||
libab_result libab_convert_lex_result(liblex_result to_convert) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
if(to_convert == LIBLEX_MALLOC) {
|
||||
result = LIBAB_MALLOC;
|
||||
|
@ -11,7 +11,7 @@ libab_result convert_lex_result(liblex_result to_convert) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
libab_result convert_ds_result(libds_result to_convert) {
|
||||
libab_result libab_convert_ds_result(libds_result to_convert) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
if(to_convert == LIBDS_MALLOC) {
|
||||
result = LIBAB_MALLOC;
|
||||
|
|
16
src/parser.c
16
src/parser.c
|
@ -7,7 +7,7 @@
|
|||
|
||||
struct parser_state {
|
||||
ll_node* current_node;
|
||||
lexer_match* current_match;
|
||||
libab_lexer_match* current_match;
|
||||
const char* string;
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,7 @@ int _parser_is_char(struct parser_state* state, char to_expect) {
|
|||
state->string[state->current_match->from] == to_expect);
|
||||
}
|
||||
|
||||
int _parser_is_type(struct parser_state* state, lexer_token to_expect) {
|
||||
int _parser_is_type(struct parser_state* state, libab_lexer_token to_expect) {
|
||||
return (state->current_match && state->current_match->type == to_expect);
|
||||
}
|
||||
|
||||
|
@ -54,9 +54,9 @@ libab_result _parser_consume_char(struct parser_state* state, char to_consume) {
|
|||
return result;
|
||||
}
|
||||
|
||||
libab_result _parse_block(struct parser_state*, tree**, int);
|
||||
libab_result _parse_block(struct parser_state*, libab_tree**, int);
|
||||
|
||||
libab_result _parser_extract_token(struct parser_state* state, char** into, lexer_match* match) {
|
||||
libab_result _parser_extract_token(struct parser_state* state, char** into, libab_lexer_match* match) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
size_t string_size = match->to - match->from;
|
||||
if((*into = malloc(string_size + 1))) {
|
||||
|
@ -68,12 +68,12 @@ libab_result _parser_extract_token(struct parser_state* state, char** into, lexe
|
|||
return result;
|
||||
}
|
||||
|
||||
libab_result _parse_expression(struct parser_state* state, tree** store_into) {
|
||||
libab_result _parse_expression(struct parser_state* state, libab_tree** store_into) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
return result;
|
||||
}
|
||||
|
||||
libab_result _parse_statement(struct parser_state* state, tree** store_into) {
|
||||
libab_result _parse_statement(struct parser_state* state, libab_tree** store_into) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
|
||||
if(_parser_is_char(state, '{')) result = _parse_block(state, store_into, 1);
|
||||
|
@ -93,7 +93,7 @@ libab_result _parse_statement(struct parser_state* state, tree** store_into) {
|
|||
}
|
||||
|
||||
libab_result _parse_block(struct parser_state* state,
|
||||
tree** store_into, int expect_braces) {
|
||||
libab_tree** store_into, int expect_braces) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
if((*store_into = malloc(sizeof(**store_into))) == NULL) result = LIBAB_MALLOC;
|
||||
|
||||
|
@ -109,7 +109,7 @@ libab_result _parse_block(struct parser_state* state,
|
|||
return result;
|
||||
}
|
||||
|
||||
libab_result parse_tokens(ll* tokens, const char* string, tree** store_into) {
|
||||
libab_result libab_parse_tokens(ll* tokens, const char* string, libab_tree** store_into) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
struct parser_state state;
|
||||
_parser_state_init(&state, tokens, string);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "table.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void table_init(table* table) {
|
||||
void table_init(libab_table* table) {
|
||||
ht_init(&table->table);
|
||||
table->parent = NULL;
|
||||
}
|
||||
table_entry* table_search(table* table, const char* string) {
|
||||
libab_table_entry* table_search(libab_table* table, const char* string) {
|
||||
void* to_return = NULL;
|
||||
do {
|
||||
to_return = ht_get(&table->table, string);
|
||||
|
@ -13,6 +13,6 @@ table_entry* table_search(table* table, const char* string) {
|
|||
} while(table && to_return == NULL);
|
||||
return to_return;
|
||||
}
|
||||
void table_free(table* table) {
|
||||
void table_free(libab_table* table) {
|
||||
ht_free(&table->table);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user