Tentatively implement lexing multiple words.
This commit is contained in:
parent
8ff435b7b5
commit
97933c4ce9
25
src/eval.c
25
src/eval.c
|
@ -173,7 +173,7 @@ liblex_result eval_word(char* string, int index, eval_config* config, match* mtc
|
|||
ll_foreach(&config->states, NULL, compare_always, _eval_foreach_add_node, evl.set_current);
|
||||
do {
|
||||
_eval_step(&evl);
|
||||
} while(evl.matched);
|
||||
} while(evl.matched && *(evl.string));
|
||||
|
||||
if(evl.matches.tail){
|
||||
int largest_id = -1;
|
||||
|
@ -193,5 +193,28 @@ liblex_result eval_word(char* string, int index, eval_config* config, match* mtc
|
|||
}
|
||||
liblex_result eval_all(char* string, int index, eval_config* config, ll* matches){
|
||||
liblex_result result = LIBLEX_SUCCESS;
|
||||
match* new_match = NULL;
|
||||
int done = 0;
|
||||
|
||||
do {
|
||||
new_match = malloc(sizeof(*new_match));
|
||||
if(new_match){
|
||||
result = eval_word(string, index, config, new_match);
|
||||
if(result == LIBLEX_SUCCESS){
|
||||
if(new_match->pattern < 0){
|
||||
done = 1;
|
||||
free(new_match);
|
||||
} else {
|
||||
result = ll_append(matches, new_match) == LIBDS_SUCCESS ? LIBLEX_SUCCESS : LIBLEX_MALLOC;
|
||||
}
|
||||
}
|
||||
if(result == LIBLEX_SUCCESS){
|
||||
index += new_match->to - new_match->from;
|
||||
}
|
||||
} else {
|
||||
result = LIBLEX_MALLOC;
|
||||
}
|
||||
} while (result == LIBLEX_SUCCESS && done == 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user