From 97933c4ce9d341c691693893178171a57b503095 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 5 Feb 2017 16:29:44 -0800 Subject: [PATCH] Tentatively implement lexing multiple words. --- src/eval.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/eval.c b/src/eval.c index dcc35bf..4685281 100644 --- a/src/eval.c +++ b/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; }