Change the way best match is picked to the one with the "largest" id.
This commit is contained in:
parent
5be88a2856
commit
a0f51d441e
18
src/eval.c
18
src/eval.c
|
@ -1,5 +1,6 @@
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <pattern.h>
|
#include <pattern.h>
|
||||||
#include "pattern.h"
|
#include "pattern.h"
|
||||||
#include "pairmap.h"
|
#include "pairmap.h"
|
||||||
|
@ -145,6 +146,17 @@ liblex_result eval_step(eval* eval){
|
||||||
return result;
|
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 eval_word(char* string, int index, eval_config* config, match* mtch){
|
||||||
liblex_result result = LIBLEX_SUCCESS;
|
liblex_result result = LIBLEX_SUCCESS;
|
||||||
eval evl;
|
eval evl;
|
||||||
|
@ -163,10 +175,8 @@ liblex_result eval_word(char* string, int index, eval_config* config, match* mtc
|
||||||
} while(evl.matched);
|
} while(evl.matched);
|
||||||
|
|
||||||
if(evl.matches.tail){
|
if(evl.matches.tail){
|
||||||
match* largest_match = evl.matches.tail->data;
|
int largest_id = -1;
|
||||||
mtch->from = largest_match->from;
|
ll_foreach(&evl.matches, NULL, compare_always, eval_foreach_find_match, &largest_id, mtch);
|
||||||
mtch->to = largest_match->to;
|
|
||||||
mtch->pattern = mtch->pattern;
|
|
||||||
} else {
|
} else {
|
||||||
mtch->from = -1;
|
mtch->from = -1;
|
||||||
mtch->to = -1;
|
mtch->to = -1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user