Skip to content

Commit

Permalink
fixes to semtrex fsa debuging code
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed May 27, 2016
1 parent ccf1abf commit 478904b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 61 deletions.
58 changes: 0 additions & 58 deletions spec/semtrex_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,64 +64,6 @@ T *_makeTestSemtrex1() {
return s;
}

static int dump_id = 99;

void __stx_dump(SState *s) {
T *v;
if (s->_did == dump_id) {printf("X");return;}
s->_did = dump_id;
switch (s->type) {
case StateMatch:
printf("(M)");
break;
case StateGroupOpen:
printf("{%d:%s",s->data.groupo.uid,_sem_get_name(G_sem,s->data.groupo.symbol));
break;
case StateGroupClose:
printf("%d:%s}",s->data.groupc.openP->data.groupo.uid,_sem_get_name(G_sem,s->data.groupc.openP->data.groupo.symbol));
break;
case StateSymbol:
printf("(%s%s:%d)",(s->data.symbol.flags & LITERAL_NOT) ? "!" : "",
_sem_get_name(G_sem,_t_symbol(_t_child(_t_child(s->data.symbol.symbols,1),1))),s->transition);
break;
case StateValue:
printf("(%s%s=:%d)",_sem_get_name(G_sem,_t_symbol(_t_child(_t_child(s->data.value.values,1),1))),(s->data.value.flags & LITERAL_NOT) ? "!" : "",s->transition);
break;
case StateAny:
printf("(.:%d)",s->transition);
break;
case StateDescend:
printf("(/)");
break;
case StateNot:
printf("(~)");
break;
case StateSplit:
printf("S");
break;
case StateWalk:
printf("(%%)");
break;
default:
printf("(\?\?)");
}
if (s->out) {printf("->");__stx_dump(s->out);}
if (s->out1) {printf("[->");__stx_dump(s->out1);printf("]");}
// printf("\n");
}

void _stx_dump(SState *s) {
++dump_id;
__stx_dump(s);
}

void stx_dump(T *s) {
int l;

SState *f = _stx_makeFA(s,&l); _stx_dump(f);
_stx_freeFA(f);
}

#define spec_state_equal(sa,st,tt,s) \
spec_is_equal(sa->type,st);\
spec_is_equal(sa->transition,tt);\
Expand Down
77 changes: 74 additions & 3 deletions src/semtrex.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ char * __stx_makeFA(T *t,SState **in,Ptrlist **out,int level,int *statesP) {
return 0;
}

void _stx_dump(SState *s);

/**
* wrapper function for building the finite state automata recursively and patching it to the final match state
*/
Expand Down Expand Up @@ -333,7 +331,7 @@ T *G_ts,*G_te;
#define DEBUG_MATCH
#ifdef DEBUG_MATCH
#define MATCH_DEBUGG(s,x) debug(D_STX_MATCH,"IN:" #s " for %s\n",x);debug(D_STX_MATCH," cursor:%s\n",_t2s(G_sem,t));
#define MATCH_DEBUG(s) debug(D_STX_MATCH,"IN:" #s "\n");debug(D_STX_MATCH," cursor:%s\n",!t ? "NULL" : _t2s(G_sem,t));
#define MATCH_DEBUG(_s) debug(D_STX_MATCH,"IN:" #_s "\n");debug(D_STX_MATCH," cursor:%s\n",!t ? "NULL" : _t2s(G_sem,t));G_cur_stx_state=s;debug(D_STX_MATCH,"%s\n",_stx_dump(fa,G_stx_dump_buf));

#else
#define MATCH_DEBUG(s)
Expand Down Expand Up @@ -1929,4 +1927,77 @@ T *_stx_results2sem_map(SemTable *sem,T *match_results,T *match_tree) {
return sem_map;
}


// debugging code to dump out an ascii representation of the stx fsa

static int dump_id = 99;
SState *G_cur_stx_state = NULL;
char G_stx_dump_buf[10000];
#define pbuf(...) sprintf(buf+strlen(buf),__VA_ARGS__)
void __stx_dump(SState *s,char *buf) {
T *x;
Symbol sym;
if (s->_did == dump_id) {pbuf("X");return;}
s->_did = dump_id;
if (s == G_cur_stx_state)
pbuf("^*^");
switch (s->type) {
case StateMatch:
pbuf("(M)");
break;
case StateGroupOpen:
pbuf("{%d:%s",s->data.groupo.uid,_sem_get_name(G_sem,s->data.groupo.symbol));
break;
case StateGroupClose:
pbuf("%d:%s}",s->data.groupc.openP->data.groupo.uid,_sem_get_name(G_sem,s->data.groupc.openP->data.groupo.symbol));
break;
case StateSymbol:
x = s->data.symbol.symbols;
if (semeq(_t_symbol(x),SEMTREX_SYMBOL))
sym = *(Symbol *)_t_surface(x);
else raise_error("unimplemented state data type in stx_dump\n");
pbuf("(%s%s:%d)",(s->data.symbol.flags & LITERAL_NOT) ? "!" : "",
_sem_get_name(G_sem,sym),s->transition);
break;
case StateValue:
pbuf("(%s%s=:%d)",_sem_get_name(G_sem,_t_symbol(_t_child(_t_child(s->data.value.values,1),1))),(s->data.value.flags & LITERAL_NOT) ? "!" : "",s->transition);
break;
case StateAny:
pbuf("(.:%d)",s->transition);
break;
case StateDescend:
printf("(/)");
break;
case StateNot:
pbuf("(~)");
break;
case StateSplit:
pbuf("S");
break;
case StateWalk:
pbuf("(%%)");
break;
default:
pbuf("(\?\?)");
}
if (s->out) {pbuf("->");__stx_dump(s->out,buf);}
if (s->out1) {pbuf("[->");__stx_dump(s->out1,buf);pbuf("]");}
// printf("\n");
}

char * _stx_dump(SState *s,char *buf) {
++dump_id;
buf[0] = 0;
__stx_dump(s,buf);
return buf;
}

void stx_dump(T *s) {
int l;

SState *f = _stx_makeFA(s,&l); _stx_dump(f,G_stx_dump_buf);
puts(G_stx_dump_buf);
_stx_freeFA(f);
}

/**@}*/
5 changes: 5 additions & 0 deletions src/semtrex.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct SState {
int _did; ///< used to hold a mark when freeing and printing out FSA to prevent looping.
STypeData data; ///< a union to hold the data for which ever type of SState this is
};
SState *G_cur_stx_state;

SState * _stx_makeFA(T *s,int *statesP);
void _stx_freeFA(SState *s);
Expand Down Expand Up @@ -127,4 +128,8 @@ T *__sl(T *p, bool not,int count, ...);

#endif

void __stx_dump(SState *s,char *buf);
char * _stx_dump(SState *s,char *buf);
void stx_dump(T *s);
char G_stx_dump_buf[10000];
/** @}*/

0 comments on commit 478904b

Please sign in to comment.