|
|
@ -258,9 +258,11 @@ get_eta_node(automaton* a, esctrie* phi, unsigned successor){
|
|
|
|
static inline void
|
|
|
|
static inline void
|
|
|
|
add_phi_and_eta_chain(const automaton *a, esctrie* e, unsigned phi,
|
|
|
|
add_phi_and_eta_chain(const automaton *a, esctrie* e, unsigned phi,
|
|
|
|
unsigned follow, unsigned eta){
|
|
|
|
unsigned follow, unsigned eta){
|
|
|
|
|
|
|
|
//logtrace("working with %u phi: %u follow: %u eta: %u\n", esctrie_idx(a, e), phi, follow, eta);
|
|
|
|
for(int i = '0' ; i <= '9' ; ++i){
|
|
|
|
for(int i = '0' ; i <= '9' ; ++i){
|
|
|
|
esctrie* chain = esctrie_from_idx(a, e->trie[i]);
|
|
|
|
esctrie* chain = esctrie_from_idx(a, e->trie[i]);
|
|
|
|
if(chain == NULL){
|
|
|
|
if(chain == NULL){
|
|
|
|
|
|
|
|
//logdebug("linking %u[%d] to %u\n", esctrie_idx(a, e), i, phi);
|
|
|
|
e->trie[i] = phi;
|
|
|
|
e->trie[i] = phi;
|
|
|
|
}else if(chain->ntype == NODE_SPECIAL){
|
|
|
|
}else if(chain->ntype == NODE_SPECIAL){
|
|
|
|
//logdebug("propagating along %u[%c]\n", e->trie[i], i);
|
|
|
|
//logdebug("propagating along %u[%c]\n", e->trie[i], i);
|
|
|
@ -268,6 +270,7 @@ add_phi_and_eta_chain(const automaton *a, esctrie* e, unsigned phi,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(e->trie[follow] == 0){
|
|
|
|
if(e->trie[follow] == 0){
|
|
|
|
|
|
|
|
//logdebug("linking %u[%u] to %u\n", esctrie_idx(a, e), follow, eta);
|
|
|
|
e->trie[follow] = eta;
|
|
|
|
e->trie[follow] = eta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -280,7 +283,7 @@ add_phi_and_eta_chain(const automaton *a, esctrie* e, unsigned phi,
|
|
|
|
static inline void
|
|
|
|
static inline void
|
|
|
|
add_phi_and_eta_recurse(automaton* a, esctrie* e, const char* prefix,
|
|
|
|
add_phi_and_eta_recurse(automaton* a, esctrie* e, const char* prefix,
|
|
|
|
int pfxlen, esctrie* phi, unsigned follow,
|
|
|
|
int pfxlen, esctrie* phi, unsigned follow,
|
|
|
|
esctrie* eta){
|
|
|
|
esctrie* eta, unsigned inphi){
|
|
|
|
//logtrace("working with %u %d prefix [%*.*s]\n", esctrie_idx(a, e), pfxlen, pfxlen, pfxlen, prefix);
|
|
|
|
//logtrace("working with %u %d prefix [%*.*s]\n", esctrie_idx(a, e), pfxlen, pfxlen, pfxlen, prefix);
|
|
|
|
// if pfxlen == 0, we found a match for our fixed prefix. start adding phi
|
|
|
|
// if pfxlen == 0, we found a match for our fixed prefix. start adding phi
|
|
|
|
// links whereever we can. where we find chained numerics, add an eta link.
|
|
|
|
// links whereever we can. where we find chained numerics, add an eta link.
|
|
|
@ -288,10 +291,10 @@ add_phi_and_eta_recurse(automaton* a, esctrie* e, const char* prefix,
|
|
|
|
add_phi_and_eta_chain(a, e, esctrie_idx(a, phi), follow, esctrie_idx(a, eta));
|
|
|
|
add_phi_and_eta_chain(a, e, esctrie_idx(a, phi), follow, esctrie_idx(a, eta));
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--pfxlen;
|
|
|
|
|
|
|
|
unsigned char p = *prefix++;
|
|
|
|
|
|
|
|
// when we hit a \N in the prefix, we must recurse along all digit links
|
|
|
|
// when we hit a \N in the prefix, we must recurse along all digit links
|
|
|
|
if(p == '\\'){
|
|
|
|
if(*prefix == '\\'){
|
|
|
|
|
|
|
|
++prefix;
|
|
|
|
|
|
|
|
--pfxlen;
|
|
|
|
if(*prefix != 'N'){
|
|
|
|
if(*prefix != 'N'){
|
|
|
|
logerror("illegal wildcard in prefix %c\n", *prefix);
|
|
|
|
logerror("illegal wildcard in prefix %c\n", *prefix);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -300,16 +303,29 @@ add_phi_and_eta_recurse(automaton* a, esctrie* e, const char* prefix,
|
|
|
|
--pfxlen;
|
|
|
|
--pfxlen;
|
|
|
|
for(int i = '0' ; i <= '9' ; ++i){
|
|
|
|
for(int i = '0' ; i <= '9' ; ++i){
|
|
|
|
if(e->trie[i] == 0){
|
|
|
|
if(e->trie[i] == 0){
|
|
|
|
|
|
|
|
//logdebug("linking %u[%d] to %u\n", esctrie_idx(a, e), i, esctrie_idx(a, phi));
|
|
|
|
e->trie[i] = esctrie_idx(a, phi);
|
|
|
|
e->trie[i] = esctrie_idx(a, phi);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
add_phi_and_eta_recurse(a, esctrie_from_idx(a, e->trie[i]),
|
|
|
|
add_phi_and_eta_recurse(a, esctrie_from_idx(a, e->trie[i]),
|
|
|
|
prefix, pfxlen, phi, follow, eta);
|
|
|
|
prefix, pfxlen, phi, follow, eta, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
|
|
|
|
if(inphi){
|
|
|
|
|
|
|
|
for(int i = '0' ; i <= '9' ; ++i){
|
|
|
|
|
|
|
|
if(e->trie[i] == 0){
|
|
|
|
|
|
|
|
//logdebug("linking %u[%d] to %u\n", esctrie_idx(a, e), i, esctrie_idx(a, phi));
|
|
|
|
|
|
|
|
e->trie[i] = esctrie_idx(a, phi);
|
|
|
|
|
|
|
|
}else if(e->trie[i] != esctrie_idx(a, e)){
|
|
|
|
|
|
|
|
add_phi_and_eta_recurse(a, esctrie_from_idx(a, e->trie[i]),
|
|
|
|
|
|
|
|
prefix, pfxlen, phi, follow, eta, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char p = *prefix;
|
|
|
|
if(e->trie[p]){
|
|
|
|
if(e->trie[p]){
|
|
|
|
add_phi_and_eta_recurse(a, esctrie_from_idx(a, e->trie[p]),
|
|
|
|
add_phi_and_eta_recurse(a, esctrie_from_idx(a, e->trie[p]),
|
|
|
|
prefix, pfxlen, phi, follow, eta);
|
|
|
|
prefix + 1, pfxlen - 1, phi, follow, eta, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -322,7 +338,7 @@ add_phi_and_eta(automaton* a, const char* prefix, size_t pfxlen,
|
|
|
|
if(esc == NULL){
|
|
|
|
if(esc == NULL){
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_phi_and_eta_recurse(a, esc, prefix, pfxlen, phi, follow, eta);
|
|
|
|
add_phi_and_eta_recurse(a, esc, prefix, pfxlen, phi, follow, eta, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// accept any digit and transition to a numeric node. |e| is the culmination of
|
|
|
|
// accept any digit and transition to a numeric node. |e| is the culmination of
|
|
|
|