From a0f51d441e3a0fd70dcb6c769ad8acb56d2bb85d Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 5 Feb 2017 15:46:43 -0800 Subject: [PATCH] Change the way best match is picked to the one with the "largest" id. --- src/eval.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/eval.c b/src/eval.c index ec08fcd..efcfc54 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1,5 +1,6 @@ #include "eval.h" #include +#include #include #include "pattern.h" #include "pairmap.h" @@ -145,6 +146,17 @@ liblex_result eval_step(eval* eval){ return result; } +int eval_foreach_find_match(void* data, va_list args){ + match* current_match = data; + int* max_match_id = va_arg(args, int*); + match* fill_match = va_arg(args, match*); + if(*max_match_id < current_match->pattern){ + *max_match_id = current_match->pattern; + memcpy(fill_match, current_match, sizeof(*current_match)); + } + return 0; +} + liblex_result eval_word(char* string, int index, eval_config* config, match* mtch){ liblex_result result = LIBLEX_SUCCESS; eval evl; @@ -163,10 +175,8 @@ liblex_result eval_word(char* string, int index, eval_config* config, match* mtc } while(evl.matched); if(evl.matches.tail){ - match* largest_match = evl.matches.tail->data; - mtch->from = largest_match->from; - mtch->to = largest_match->to; - mtch->pattern = mtch->pattern; + int largest_id = -1; + ll_foreach(&evl.matches, NULL, compare_always, eval_foreach_find_match, &largest_id, mtch); } else { mtch->from = -1; mtch->to = -1;