Change the way best match is picked to the one with the "largest" id.

This commit is contained in:
Danila Fedorin 2017-02-05 15:46:43 -08:00
parent 5be88a2856
commit a0f51d441e

View File

@ -1,5 +1,6 @@
#include "eval.h"
#include <stdlib.h>
#include <string.h>
#include <pattern.h>
#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;