7 #include "../src/ceptr.h"
8 #include "../src/hashfn.h"
9 #include "../src/semtrex.h"
10 #include "../src/receptor.h"
37 sYt(TEST_GROUP_SYMBOL1,INTEGER);
38 sYt(TEST_GROUP_SYMBOL2,CSTRING);
43 T *t = _t_new(0,TEST_STR_SYMBOL,
"t",2);
44 T *t1 = _t_new(t,sy1,
"t1",3);
45 T *t11 = _t_new(t1,sy11,
"t11",4);
46 T *t111 = _t_new(t11,sy111,
"t111",5);
47 T *t2 = _t_new(t,sy2,
"t2",3);
48 T *t21 = _t_new(t2,sy21,
"t21",4);
49 T *t22 = _t_new(t2,sy22,
"t22",4);
50 T *t3 = _t_new(t,sy3,
"t3",3);
51 T *t4 = _t_new(t,sy4,
"t4",3);
55 T *_makeTestSemtrex1() {
57 T *s =
_sl(0,TEST_STR_SYMBOL);
58 T *ss = _t_newi(s,SEMTREX_SEQUENCE,0);
60 T *s11 =
_sl(s1,sy11);
61 T *s111 =
_sl(s11,sy111);
108 void testMatchTrees() {
109 T *t = _makeTestTree1();
110 T *s = _makeTestSemtrex1();
122 T *__stxcv(
T *stxx,
char c);
125 T *t = _makeTestTree1();
128 T *s11 =
_sl(s1,sy11);
129 T *s2 =
_sl(s,TEST_STR_SYMBOL);
142 s =
_t_parse(G_sem,0,
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHARS) (SEMTREX_SEQUENCE (SEMTREX_VALUE_LITERAL (ASCII_CHAR:'/')) (SEMTREX_OR (SEMTREX_SEQUENCE (SEMTREX_VALUE_LITERAL (ASCII_CHAR:'(')) (SEMTREX_VALUE_LITERAL (ASCII_CHAR:')'))) (SEMTREX_VALUE_LITERAL (ASCII_CHAR:'X')))))");
145 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/ASCII_CHARS/(ASCII_CHAR='/',(ASCII_CHAR='(',ASCII_CHAR=')')|ASCII_CHAR='X')");
146 t =
_t_parse(G_sem,0,
"(ASCII_CHARS (ASCII_CHAR:'/') (ASCII_CHAR:'X') (ASCII_CHAR:')')");
150 t =
_t_parse(G_sem,0,
"(ASCII_CHARS (ASCII_CHAR:'/') (ASCII_CHAR:'(') (ASCII_CHAR:')')");
154 t =
_t_parse(G_sem,0,
"(ASCII_CHARS (ASCII_CHAR:'/') (ASCII_CHAR:')')");
160 s =
_t_parse(G_sem,0,
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:A) (SEMTREX_SEQUENCE (SEMTREX_OR (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:B)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:C) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:D)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:E))))");
161 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/A/(B|C/D,E)");
163 t =
_t_parse(G_sem,0,
"(A (C (D)) (E))");
167 debug_disable(D_STX_MATCH);
169 t =
_t_parse(G_sem,0,
"(A (B) (E))");
172 t =
_t_parse(G_sem,0,
"(A (C) (E))");
179 void testMatchAny() {
180 T *t = _t_new(0,sy0,
"t",2);
181 T *t1 = _t_new(t,sy1,
"t1",3);
184 T *ss = _t_newr(s,SEMTREX_SEQUENCE);
185 T *s1 =
_sl(ss, sy1);
188 t->contents.symbol.id = 99;
195 void testMatchExcept() {
196 T *t = _t_new(0,sy0,
"t",2);
197 T *t1 = _t_new(t,sy1,
"t1",3);
201 T *ss = _t_newr(s,SEMTREX_SEQUENCE);
209 ss = _t_newr(s,SEMTREX_SEQUENCE);
216 s =
__sl(0,1,2,sy1,sy2);
222 s =
__sl(0,1,2,sy1,sy0);
228 s =
__sl(0,0,2,sy1,sy0);
234 s =
__sl(0,0,2,sy1,sy2);
241 void testMatchStar() {
244 T *s =
_sl(0,SIGNALS);
245 T *g = _t_news(s,SEMTREX_GROUP,SIGNALS);
246 T *ss = _t_newr(g,SEMTREX_ZERO_OR_MORE);
257 T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
260 T *sig =
__r_make_signal(fr,to,DEFAULT_ASPECT,TESTING,signal_contents,0,0,0);
265 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
270 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:2))");
273 spec_is_false(
_t_match(s,signal_contents));
278 s =
_t_parse(G_sem,0,
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:A) (SEMTREX_SEQUENCE (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:B))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:C))))");
281 t =
_t_parse(G_sem,0,
"(A (B) (C))");
284 t =
_t_parse(G_sem,0,
"(A (B) (B) (B) (C))");
289 s =
_t_parse(G_sem,0,
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:A) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:B) (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:C)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:D))))");
292 t =
_t_parse(G_sem,0,
"(A (B (C)) (D))");
295 debug_disable(D_STX_MATCH+D_STX_BUILD);
298 t =
_t_parse(G_sem,0,
"(A (B) (D))");
301 debug_disable(D_STX_MATCH+D_STX_BUILD);
309 void testMatchPlus() {
312 T *s =
_sl(0,SIGNALS);
313 T *g = _t_news(s,SEMTREX_GROUP,SIGNALS);
314 T *ss = _t_newr(g,SEMTREX_ONE_OR_MORE);
321 T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
324 T *sig =
__r_make_signal(fr,to,DEFAULT_ASPECT,TESTING,signal_contents,0,0,0);
328 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
333 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:2))");
336 spec_is_false(
_t_match(s,signal_contents));
344 T *s =
_sl(0,SIGNALS);
345 T *g = _t_news(s,SEMTREX_GROUP,SIGNALS);
346 T *ss = _t_newr(g,SEMTREX_ZERO_OR_ONE);
357 T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
360 T *sig =
__r_make_signal(fr,to,DEFAULT_ASPECT,TESTING,signal_contents,0,0,0);
365 debug_disable(D_STX_MATCH);
366 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
372 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
375 spec_is_false(
_t_match(s,signal_contents));
380 void testMatchGroup() {
381 T *sg2, *s3, *t, *r, *p1, *p2, *p1c, *p2c;
382 t = _makeTestTree1();
385 T *g = _t_news(0,SEMTREX_GROUP,TEST_STR_SYMBOL);
386 _sl(g,TEST_STR_SYMBOL);
393 T *s =
_sl(0,TEST_STR_SYMBOL);
394 T *ss = _t_newr(s,SEMTREX_SEQUENCE);
395 T *sg = _t_news(ss,SEMTREX_GROUP,TEST_GROUP_SYMBOL1);
396 T *ss2 = _t_newr(sg,SEMTREX_SEQUENCE);
397 T *st = _t_newr(ss2,SEMTREX_ZERO_OR_MORE);
398 _t_newr(st,SEMTREX_SYMBOL_ANY);
399 sg2 = _t_news(ss2,SEMTREX_GROUP,TEST_GROUP_SYMBOL2);
400 _t_newr(sg2,SEMTREX_SYMBOL_ANY);
405 debug_disable(D_STX_MATCH);
407 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:TEST_GROUP_SYMBOL1) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:3) (SEMTREX_MATCH:2 (SEMTREX_MATCH_SYMBOL:TEST_GROUP_SYMBOL2) (SEMTREX_MATCH_PATH:/3) (SEMTREX_MATCH_SIBLINGS_COUNT:1)))");
416 spec_is_ptr_equal(
_t_get_match(r,TEST_GROUP_SYMBOL1),r);
422 s =
_t_parse(G_sem,0,
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL) (SEMTREX_SEQUENCE (SEMTREX_GROUP:TEST_GROUP_SYMBOL1 (SEMTREX_ZERO_OR_MORE (SEMTREX_GROUP:TEST_GROUP_SYMBOL2 (SEMTREX_SYMBOL_ANY)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy4))))");
424 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/TEST_STR_SYMBOL/(<TEST_GROUP_SYMBOL1:<TEST_GROUP_SYMBOL2:.>*>,sy4)");
429 debug_disable(D_STX_MATCH+D_STX_BUILD);
431 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:TEST_GROUP_SYMBOL1) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:3) (SEMTREX_MATCH:2 (SEMTREX_MATCH_SYMBOL:TEST_GROUP_SYMBOL2) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1)) (SEMTREX_MATCH:2 (SEMTREX_MATCH_SYMBOL:TEST_GROUP_SYMBOL2) (SEMTREX_MATCH_PATH:/2) (SEMTREX_MATCH_SIBLINGS_COUNT:1)) (SEMTREX_MATCH:2 (SEMTREX_MATCH_SYMBOL:TEST_GROUP_SYMBOL2) (SEMTREX_MATCH_PATH:/3) (SEMTREX_MATCH_SIBLINGS_COUNT:1)))");
438 s =
_sl(0,TEST_STR_SYMBOL);
439 ss = _t_newr(s,SEMTREX_SEQUENCE);
440 st = _t_newr(ss,SEMTREX_ZERO_OR_MORE);
441 _t_newr(st,SEMTREX_SYMBOL_ANY);
442 sg = _t_news(ss,SEMTREX_GROUP,TEST_GROUP_SYMBOL1);
443 ss2 = _t_newr(sg,SEMTREX_SEQUENCE);
450 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:TEST_GROUP_SYMBOL1) (SEMTREX_MATCH_PATH:/3) (SEMTREX_MATCH_SIBLINGS_COUNT:2))");
457 sg = _t_news(0,SEMTREX_GROUP,VERB);
458 s = _t_newr(sg,SEMTREX_SYMBOL_LITERAL);
459 _t_news(s,SEMTREX_SYMBOL,LINE);
461 t = _t_new_str(0,LINE,
"receptors");
463 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:VERB) (SEMTREX_MATCH_PATH:/) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
466 spec_is_str_equal(t2s(map),
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:VERB) (REPLACEMENT_VALUE (VERB:receptors))))");
475 void testMatchGroupMulti() {
476 sX(TSTX_TOKENS,NULL_STRUCTURE);
477 sX(TSTX_OP,NULL_STRUCTURE);
478 sX(TSTX_SL,NULL_STRUCTURE);
481 _t_newc(s,ASCII_CHAR,
'/');
482 _t_newc(s,ASCII_CHAR,
'(');
483 _t_newc(s,ASCII_CHAR,
'(');
485 T *ts = _t_news(0,SEMTREX_GROUP,STX_TOKENS);
486 T *g =
_sl(ts,ASCII_CHARS);
487 T *sq = _t_newr(g,SEMTREX_SEQUENCE);
488 T *p = _t_newr(sq,SEMTREX_ONE_OR_MORE);
489 T *o = _t_newr(p,SEMTREX_OR);
490 T *t = _t_news(o,SEMTREX_GROUP,STX_SL);
492 t = _t_news(o,SEMTREX_GROUP,STX_OP);
498 spec_is_str_equal(t2s(results),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:STX_TOKENS) (SEMTREX_MATCH_PATH:/) (SEMTREX_MATCH_SIBLINGS_COUNT:1) (SEMTREX_MATCH:2 (SEMTREX_MATCH_SYMBOL:STX_SL) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1)) (SEMTREX_MATCH:3 (SEMTREX_MATCH_SYMBOL:STX_OP) (SEMTREX_MATCH_PATH:/2) (SEMTREX_MATCH_SIBLINGS_COUNT:1)) (SEMTREX_MATCH:3 (SEMTREX_MATCH_SYMBOL:STX_OP) (SEMTREX_MATCH_PATH:/3) (SEMTREX_MATCH_SIBLINGS_COUNT:1)))");
505 T *newvl(
T *p,
int not,
int count,...) {
507 T *t = _t_newr(p,not ? SEMTREX_VALUE_LITERAL_NOT : SEMTREX_VALUE_LITERAL);
508 T *v = _t_newr(t,SEMTREX_VALUE_SET);
510 va_start(values,count);
512 for(i=0;i<count;i++) {
513 T *x = va_arg(values,
T *);
520 void testMatchLiteralValue() {
521 T *t = _makeTestTree1();
525 s = newvl(0,1,1,_t_new(0,TEST_STR_SYMBOL,
"t",2));
530 s = newvl(0,0,1,_t_new(0,TEST_STR_SYMBOL,
"t",2));
536 s = newvl(0,0,1,_t_new(0,TEST_INT_SYMBOL2,
"t",2));
542 s = newvl(0,0,1,_t_new(0,TEST_STR_SYMBOL,
"x",2));
548 s = newvl(0,0,1,_t_new(0,TEST_STR_SYMBOL,
"tt",3));
553 s = newvl(0,0,2,_t_new(0,TEST_STR_SYMBOL,
"t",2),_t_new(0,TEST_STR_SYMBOL,
"q",2));
558 s = newvl(0,0,2,_t_new(0,TEST_STR_SYMBOL,
"q",2),_t_new(0,TEST_STR_SYMBOL,
"x",2));
563 s = newvl(0,1,2,_t_new(0,TEST_STR_SYMBOL,
"q",2),_t_new(0,TEST_STR_SYMBOL,
"x",2));
568 s = newvl(0,1,2,_t_new(0,TEST_STR_SYMBOL,
"q",2),_t_new(0,TEST_STR_SYMBOL,
"t",2));
574 s =
_t_parse(G_sem,0,
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHARS) (SEMTREX_SEQUENCE (SEMTREX_GROUP:TEST_GROUP_SYMBOL1 (SEMTREX_ZERO_OR_MORE (SEMTREX_VALUE_LITERAL_NOT (SEMTREX_VALUE_SET (ASCII_CHAR:'/') (ASCII_CHAR:'?') (ASCII_CHAR:' ')))))))");
576 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/ASCII_CHARS/<TEST_GROUP_SYMBOL1:ASCII_CHAR!={'/','?',' '}*>");
577 t =
_t_parse(G_sem,0,
"(ASCII_CHARS (ASCII_CHAR:'a') (ASCII_CHAR:'b') (ASCII_CHAR:'/'))");
582 debug_disable(D_STX_MATCH+D_STX_BUILD);
584 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:TEST_GROUP_SYMBOL1) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:2))");
592 void testMatchDescend() {
593 T *t = _makeTestTree1();
609 T *ss = _t_newr(s,SEMTREX_DESCEND);
618 void testMatchWalk() {
619 T *t = _makeTestTree1();
632 _sl(s,TEST_INT_SYMBOL);
647 T *g = _t_news(s,SEMTREX_GROUP,TEST_GROUP_SYMBOL1);
648 T *sq = _t_newr(g,SEMTREX_SEQUENCE);
653 spec_is_str_equal(t2s(results),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:TEST_GROUP_SYMBOL1) (SEMTREX_MATCH_PATH:/3) (SEMTREX_MATCH_SIBLINGS_COUNT:2))");
662 s =
_t_parse(G_sem,0,
"(SEMTREX_WALK (SEMTREX_SEQUENCE (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_ANY)) (SEMTREX_GROUP:STX_CHILD (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_LABEL)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_SL)) (SEMTREX_SYMBOL_LITERAL_NOT (SEMTREX_SYMBOL:STX_SL))))))");
663 t =
_t_parse(G_sem,0,
"(STX_TOKENS (STX_SL) (STX_LABEL:\"TEST_STR_SYMBOL\") (STX_SL) (STX_SIBS (STX_LABEL:\"sy1\") (STX_SL) (STX_LABEL:\"sy11\") (STX_SL) (STX_LABEL:\"sy111\") (STX_COMMA) (STX_LABEL:\"sy2\") (STX_COMMA) (STX_LABEL:\"sy3\")))");
667 debug_disable(D_STX_MATCH);
671 void testMatchNot() {
672 T *t = _makeTestTree1();
675 T *s =
_sl(0,TEST_STR_SYMBOL);
676 T *n = _t_newr(s,SEMTREX_NOT);
682 s =
_sl(0,TEST_STR_SYMBOL);
683 n = _t_newr(s,SEMTREX_NOT);
689 sX(
R,NULL_STRUCTURE);
690 sX(A,NULL_STRUCTURE);
691 sX(B,NULL_STRUCTURE);
692 sX(C,NULL_STRUCTURE);
693 sX(G,NULL_STRUCTURE);
706 s = _t_newr(0,SEMTREX_WALK);
707 g = _t_news(s,SEMTREX_GROUP,G);
708 x = _t_newr(g,SEMTREX_SEQUENCE);
713 n = _t_newr(x,SEMTREX_NOT);
715 n = _t_newr(x,SEMTREX_NOT);
725 spec_is_str_equal(t2s(results),
"");
742 void testSemtrexDump() {
743 T *s = _makeTestSemtrex1();
746 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/TEST_STR_SYMBOL/(sy1/sy11/sy111,sy2,sy3)");
750 s =
_sl(0,TEST_STR_SYMBOL);
751 T *ss = _t_newr(s,SEMTREX_SEQUENCE);
752 T *sg = _t_news(ss,SEMTREX_GROUP,TEST_GROUP_SYMBOL1);
753 T *ss2 = _t_newr(sg,SEMTREX_SEQUENCE);
754 T *st = _t_newr(ss2,SEMTREX_ZERO_OR_MORE);
755 _t_newr(st,SEMTREX_SYMBOL_ANY);
756 T *sg2 = _t_news(ss2,SEMTREX_GROUP,TEST_GROUP_SYMBOL2);
757 _t_newr(sg2,SEMTREX_SYMBOL_ANY);
759 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/TEST_STR_SYMBOL/(<TEST_GROUP_SYMBOL1:.*,<TEST_GROUP_SYMBOL2:.>>,sy4)");
764 _sl(s,TEST_STR_SYMBOL);
765 _sl(s,TEST_INT_SYMBOL);
766 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/TEST_STR_SYMBOL|TEST_INT_SYMBOL");
769 s = newvl(0,1,1,_t_newc(0,ASCII_CHAR,
'x'));
770 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/ASCII_CHAR!='x'");
773 s = newvl(0,0,1,_t_newc(0,ASCII_CHAR,
'x'));
774 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/ASCII_CHAR='x'");
777 s = newvl(0,0,1,_t_new(0,TEST_STR_SYMBOL,
"test",5));
778 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/TEST_STR_SYMBOL=\"test\"");
781 s = newvl(0,0,1,_t_newi(0,TEST_INT_SYMBOL,314));
782 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/TEST_INT_SYMBOL=314");
786 s =
_sl(0,TEST_STR_SYMBOL);
787 T *n = _t_newr(s,SEMTREX_NOT);
789 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/TEST_STR_SYMBOL/~sy1");
794 void testSemtrexParse() {
799 stx =
"/TEST_STR_SYMBOL/(sy1/sy11/sy111,sy2,sy3)";
804 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy1) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy11) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy111)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy2)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy3))))");
807 stx =
"/STX_STAR|STX_PLUS|STX_Q";
809 spec_is_str_equal(
_dump_semtrex(G_sem,s,buf),
"/(STX_STAR|STX_PLUS)|STX_Q");
810 spec_is_str_equal(t2s(s),
"(SEMTREX_OR (SEMTREX_OR (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_STAR)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_PLUS))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_Q)))");
813 stx =
"/TEST_STR_SYMBOL/(.+,sy1,.*,sy2,.?)";
816 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL) (SEMTREX_SEQUENCE (SEMTREX_ONE_OR_MORE (SEMTREX_SYMBOL_ANY)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy1)) (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_ANY)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy2)) (SEMTREX_ZERO_OR_ONE (SEMTREX_SYMBOL_ANY))))");
819 stx =
"/STX_TOKENS/(%<SEMTREX_SEQUENCE:(!STX_COMMA,STX_COMMA)+,!STX_COMMA>)";
822 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_TOKENS) (SEMTREX_WALK (SEMTREX_GROUP:SEMTREX_SEQUENCE (SEMTREX_SEQUENCE (SEMTREX_ONE_OR_MORE (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL_NOT (SEMTREX_SYMBOL:STX_COMMA)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_COMMA)))) (SEMTREX_SYMBOL_LITERAL_NOT (SEMTREX_SYMBOL:STX_COMMA))))))");
825 stx =
"/HTTP_REQUEST/(.,.,HTTP_REQUEST_PATH/HTTP_REQUEST_PATH_SEGMENTS/<HTTP_REQUEST_PATH_SEGMENT:HTTP_REQUEST_PATH_SEGMENT>)";
828 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_ANY) (SEMTREX_SYMBOL_ANY) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH_SEGMENTS) (SEMTREX_GROUP:HTTP_REQUEST_PATH_SEGMENT (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH_SEGMENT)))))))");
831 stx =
"/TEST_STR_SYMBOL/(TEST_INT_SYMBOL=314,ASCII_CHAR='x',TEST_STR_SYMBOL=\"abc\",TEST_STR_SYMBOL!=\"abc\")";
834 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL) (SEMTREX_SEQUENCE (SEMTREX_VALUE_LITERAL (TEST_INT_SYMBOL:314)) (SEMTREX_VALUE_LITERAL (ASCII_CHAR:'x')) (SEMTREX_VALUE_LITERAL (TEST_STR_SYMBOL:abc)) (SEMTREX_VALUE_LITERAL_NOT (TEST_STR_SYMBOL:abc))))");
837 stx =
"/TEST_STR_SYMBOL/~sy2";
840 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL) (SEMTREX_NOT (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy2))))");
844 stx =
"/STX_TOKENS/(.*,<STX_OP:STX_OP,<STX_SIBS:!STX_CP+>,STX_CP>)";
847 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_TOKENS) (SEMTREX_SEQUENCE (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_ANY)) (SEMTREX_GROUP:STX_OP (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_OP)) (SEMTREX_GROUP:STX_SIBS (SEMTREX_ONE_OR_MORE (SEMTREX_SYMBOL_LITERAL_NOT (SEMTREX_SYMBOL:STX_CP)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_CP))))))");
850 stx =
"/TEST_STR_SYMBOL=\"fish\"";
853 spec_is_str_equal(t2s(s),
"(SEMTREX_VALUE_LITERAL (TEST_STR_SYMBOL:fish))");
856 stx =
"/ASCII_CHARS/(ASCII_CHAR={'a','b'},ASCII_CHAR!={'a','b'})";
859 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHARS) (SEMTREX_SEQUENCE (SEMTREX_VALUE_LITERAL (SEMTREX_VALUE_SET (ASCII_CHAR:'a') (ASCII_CHAR:'b'))) (SEMTREX_VALUE_LITERAL_NOT (SEMTREX_VALUE_SET (ASCII_CHAR:'a') (ASCII_CHAR:'b')))))");
862 stx =
"/STX_TOKENS/(!{STX_OP,STX_CP},ASCII_CHAR!={'a','b'},{STX_OP,STX_CP})";
865 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:STX_TOKENS) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL_NOT (SEMTREX_SYMBOL_SET (SEMTREX_SYMBOL:STX_OP) (SEMTREX_SYMBOL:STX_CP))) (SEMTREX_VALUE_LITERAL_NOT (SEMTREX_VALUE_SET (ASCII_CHAR:'a') (ASCII_CHAR:'b'))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL_SET (SEMTREX_SYMBOL:STX_OP) (SEMTREX_SYMBOL:STX_CP)))))");
868 stx =
"/HTTP_REQUEST/(HTTP_REQUEST_HEADERS/HTTP_REQUEST_HOST*,HTTP_REQUEST_BODY)";
872 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_HEADERS) (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_HOST)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_BODY))))");
875 T *t =
_t_parse(G_sem,0,
"(HTTP_REQUEST (HTTP_REQUEST_HEADERS (HTTP_REQUEST_HOST:\"fish.com\")) (HTTP_REQUEST_BODY))");
883 void testSemtrexParseHHTPReq() {
884 char *req =
"GET /path/to/file.ext?name=joe&age=30 HTTP/0.9";
892 T *x = _t_news(0,SEMTREX_GROUP,NULL_SYMBOL);
897 writeFile(
"web/httpreqstx.json",buf,strlen(buf));
901 spec_is_str_equal(buf,
"/<NULL_SYMBOL:ASCII_CHARS/<HTTP_REQUEST:<HTTP_REQUEST_METHOD:ASCII_CHAR!=' '+>,ASCII_CHAR=' ',<HTTP_REQUEST_PATH:<HTTP_REQUEST_PATH_SEGMENTS:(ASCII_CHAR='/',<HTTP_REQUEST_PATH_SEGMENT:ASCII_CHAR!={'/','?',' '}*>)+>>,(ASCII_CHAR='?',<HTTP_REQUEST_PATH_QUERY:<HTTP_REQUEST_PATH_QUERY_PARAMS:(<HTTP_REQUEST_PATH_QUERY_PARAM:<PARAM_KEY:ASCII_CHAR!={'&',' ','='}+>,ASCII_CHAR='=',<PARAM_VALUE:ASCII_CHAR!={'&',' '}*>>,ASCII_CHAR='&'?)+>+>)?,ASCII_CHAR=' ',ASCII_CHAR='H',ASCII_CHAR='T',ASCII_CHAR='T',ASCII_CHAR='P',ASCII_CHAR='/',<HTTP_REQUEST_VERSION:<VERSION_MAJOR:ASCII_CHAR='0'>,ASCII_CHAR='.',<VERSION_MINOR:ASCII_CHAR='9'>>>>");
907 spec_is_str_equal(t2s(r),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:NULL_SYMBOL) (SEMTREX_MATCH_PATH:/) (SEMTREX_MATCH_SIBLINGS_COUNT:1) (SEMTREX_MATCH:2 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:46) (SEMTREX_MATCH:14 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_METHOD) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:3)) (SEMTREX_MATCH:11 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH) (SEMTREX_MATCH_PATH:/5) (SEMTREX_MATCH_SIBLINGS_COUNT:17) (SEMTREX_MATCH:12 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH_SEGMENTS) (SEMTREX_MATCH_PATH:/5) (SEMTREX_MATCH_SIBLINGS_COUNT:17) (SEMTREX_MATCH:13 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH_SEGMENT) (SEMTREX_MATCH_PATH:/6) (SEMTREX_MATCH_SIBLINGS_COUNT:4)) (SEMTREX_MATCH:13 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH_SEGMENT) (SEMTREX_MATCH_PATH:/11) (SEMTREX_MATCH_SIBLINGS_COUNT:2)) (SEMTREX_MATCH:13 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH_SEGMENT) (SEMTREX_MATCH_PATH:/14) (SEMTREX_MATCH_SIBLINGS_COUNT:8)))) (SEMTREX_MATCH:6 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH_QUERY) (SEMTREX_MATCH_PATH:/23) (SEMTREX_MATCH_SIBLINGS_COUNT:15) (SEMTREX_MATCH:7 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH_QUERY_PARAMS) (SEMTREX_MATCH_PATH:/23) (SEMTREX_MATCH_SIBLINGS_COUNT:15) (SEMTREX_MATCH:8 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH_QUERY_PARAM) (SEMTREX_MATCH_PATH:/23) (SEMTREX_MATCH_SIBLINGS_COUNT:8) (SEMTREX_MATCH:10 (SEMTREX_MATCH_SYMBOL:PARAM_KEY) (SEMTREX_MATCH_PATH:/23) (SEMTREX_MATCH_SIBLINGS_COUNT:4)) (SEMTREX_MATCH:9 (SEMTREX_MATCH_SYMBOL:PARAM_VALUE) (SEMTREX_MATCH_PATH:/28) (SEMTREX_MATCH_SIBLINGS_COUNT:3))) (SEMTREX_MATCH:8 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH_QUERY_PARAM) (SEMTREX_MATCH_PATH:/32) (SEMTREX_MATCH_SIBLINGS_COUNT:6) (SEMTREX_MATCH:10 (SEMTREX_MATCH_SYMBOL:PARAM_KEY) (SEMTREX_MATCH_PATH:/32) (SEMTREX_MATCH_SIBLINGS_COUNT:3)) (SEMTREX_MATCH:9 (SEMTREX_MATCH_SYMBOL:PARAM_VALUE) (SEMTREX_MATCH_PATH:/36) (SEMTREX_MATCH_SIBLINGS_COUNT:2))))) (SEMTREX_MATCH:3 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_VERSION) (SEMTREX_MATCH_PATH:/44) (SEMTREX_MATCH_SIBLINGS_COUNT:3) (SEMTREX_MATCH:5 (SEMTREX_MATCH_SYMBOL:VERSION_MAJOR) (SEMTREX_MATCH_PATH:/44) (SEMTREX_MATCH_SIBLINGS_COUNT:1)) (SEMTREX_MATCH:4 (SEMTREX_MATCH_SYMBOL:VERSION_MINOR) (SEMTREX_MATCH_PATH:/46) (SEMTREX_MATCH_SIBLINGS_COUNT:1)))))");
910 spec_is_str_equal(t2s(t),
"(HTTP_REQUEST (HTTP_REQUEST_METHOD:GET) (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext))) (HTTP_REQUEST_PATH_QUERY (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:name) (PARAM_VALUE:joe)) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:age) (PARAM_VALUE:30)))) (HTTP_REQUEST_VERSION (VERSION_MAJOR:0) (VERSION_MINOR:9)))");
913 spec_is_str_equal(t2s(map),
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:NULL_SYMBOL) (REPLACEMENT_VALUE (ASCII_CHARS (ASCII_CHAR:'G') (ASCII_CHAR:'E') (ASCII_CHAR:'T') (ASCII_CHAR:' ') (ASCII_CHAR:'/') (ASCII_CHAR:'p') (ASCII_CHAR:'a') (ASCII_CHAR:'t') (ASCII_CHAR:'h') (ASCII_CHAR:'/') (ASCII_CHAR:'t') (ASCII_CHAR:'o') (ASCII_CHAR:'/') (ASCII_CHAR:'f') (ASCII_CHAR:'i') (ASCII_CHAR:'l') (ASCII_CHAR:'e') (ASCII_CHAR:'.') (ASCII_CHAR:'e') (ASCII_CHAR:'x') (ASCII_CHAR:'t') (ASCII_CHAR:'?') (ASCII_CHAR:'n') (ASCII_CHAR:'a') (ASCII_CHAR:'m') (ASCII_CHAR:'e') (ASCII_CHAR:'=') (ASCII_CHAR:'j') (ASCII_CHAR:'o') (ASCII_CHAR:'e') (ASCII_CHAR:'&') (ASCII_CHAR:'a') (ASCII_CHAR:'g') (ASCII_CHAR:'e') (ASCII_CHAR:'=') (ASCII_CHAR:'3') (ASCII_CHAR:'0') (ASCII_CHAR:' ') (ASCII_CHAR:'H') (ASCII_CHAR:'T') (ASCII_CHAR:'T') (ASCII_CHAR:'P') (ASCII_CHAR:'/') (ASCII_CHAR:'0') (ASCII_CHAR:'.') (ASCII_CHAR:'9')))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST) (REPLACEMENT_VALUE (HTTP_REQUEST (HTTP_REQUEST_METHOD:GET) (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext))) (HTTP_REQUEST_PATH_QUERY (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:name) (PARAM_VALUE:joe)) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:age) (PARAM_VALUE:30)))) (HTTP_REQUEST_VERSION (VERSION_MAJOR:0) (VERSION_MINOR:9))))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_METHOD) (REPLACEMENT_VALUE (HTTP_REQUEST_METHOD:GET))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_PATH) (REPLACEMENT_VALUE (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext))))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_PATH_SEGMENTS) (REPLACEMENT_VALUE (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext)))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_PATH_SEGMENT) (REPLACEMENT_VALUE (HTTP_REQUEST_PATH_SEGMENT:path))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_PATH_SEGMENT) (REPLACEMENT_VALUE (HTTP_REQUEST_PATH_SEGMENT:to))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_PATH_SEGMENT) (REPLACEMENT_VALUE (HTTP_REQUEST_PATH_SEGMENT:file.ext))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_PATH_QUERY) (REPLACEMENT_VALUE (HTTP_REQUEST_PATH_QUERY (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:name) (PARAM_VALUE:joe)) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:age) (PARAM_VALUE:30)))))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_PATH_QUERY_PARAMS) (REPLACEMENT_VALUE (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:name) (PARAM_VALUE:joe)) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:age) (PARAM_VALUE:30))))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_PATH_QUERY_PARAM) (REPLACEMENT_VALUE (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:name) (PARAM_VALUE:joe)))) (SEMANTIC_LINK (USAGE:PARAM_KEY) (REPLACEMENT_VALUE (PARAM_KEY:name))) (SEMANTIC_LINK (USAGE:PARAM_VALUE) (REPLACEMENT_VALUE (PARAM_VALUE:joe))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_PATH_QUERY_PARAM) (REPLACEMENT_VALUE (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:age) (PARAM_VALUE:30)))) (SEMANTIC_LINK (USAGE:PARAM_KEY) (REPLACEMENT_VALUE (PARAM_KEY:age))) (SEMANTIC_LINK (USAGE:PARAM_VALUE) (REPLACEMENT_VALUE (PARAM_VALUE:30))) (SEMANTIC_LINK (USAGE:HTTP_REQUEST_VERSION) (REPLACEMENT_VALUE (HTTP_REQUEST_VERSION (VERSION_MAJOR:0) (VERSION_MINOR:9)))) (SEMANTIC_LINK (USAGE:VERSION_MAJOR) (REPLACEMENT_VALUE (VERSION_MAJOR:0))) (SEMANTIC_LINK (USAGE:VERSION_MINOR) (REPLACEMENT_VALUE (VERSION_MINOR:9))))");
917 T *pstx =
parseSemtrex(G_sem,
"/%HTTP_REQUEST_PATH_SEGMENTS/(HTTP_REQUEST_PATH_SEGMENT=\"path\",HTTP_REQUEST_PATH_SEGMENT=\"to\",HTTP_REQUEST_PATH_SEGMENT=\"file.ext\")");
927 void testEmbodyFromMatch() {
930 char *ts =
"label:abc,123,3.1415";
932 sX(LABELED_TRIPLET,NULL_STRUCTURE);
940 s =
parseSemtrex(G_sem,stx =
"/ASCII_CHARS/<LABELED_TRIPLET:(<LABEL:ASCII_CHAR+>,<NULL_SYMBOL:ASCII_CHAR=':'>,<X1:ASCII_CHAR+>,<NULL_SYMBOL:ASCII_CHAR=','>,<X2:ASCII_CHAR+>,<NULL_SYMBOL:ASCII_CHAR=','>,<X3:ASCII_CHAR+>)>");
942 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHARS) (SEMTREX_GROUP:LABELED_TRIPLET (SEMTREX_SEQUENCE (SEMTREX_GROUP:LABEL (SEMTREX_ONE_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHAR)))) (SEMTREX_GROUP:NULL_SYMBOL (SEMTREX_VALUE_LITERAL (ASCII_CHAR:':'))) (SEMTREX_GROUP:X1 (SEMTREX_ONE_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHAR)))) (SEMTREX_GROUP:NULL_SYMBOL (SEMTREX_VALUE_LITERAL (ASCII_CHAR:','))) (SEMTREX_GROUP:X2 (SEMTREX_ONE_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHAR)))) (SEMTREX_GROUP:NULL_SYMBOL (SEMTREX_VALUE_LITERAL (ASCII_CHAR:','))) (SEMTREX_GROUP:X3 (SEMTREX_ONE_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHAR)))))))");
946 T *e = __t_embody_from_match(G_sem,r,t);
947 spec_is_str_equal(t2s(e),
"(LABELED_TRIPLET (LABEL:label) (X1:abc) (X2:123) (X3:3.141500))");
952 s =
parseSemtrex(G_sem,
"/LABELED_TRIPLET/(.*,X3=3.1415)");
953 spec_is_str_equal(t2s(s),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:LABELED_TRIPLET) (SEMTREX_SEQUENCE (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_ANY)) (SEMTREX_VALUE_LITERAL (X3:3.141500))))");
963 void testSemtrexReplace() {
968 T *s =
_sl(stx,EXPECT);
969 s = _t_newr(s,SEMTREX_SEQUENCE);
970 _t_newr(_t_newr(s,SEMTREX_ZERO_OR_MORE),SEMTREX_SYMBOL_ANY);
971 T *g = _t_news(s,SEMTREX_GROUP,ACTION);
972 T *vl = _t_newr(g,SEMTREX_VALUE_LITERAL);
975 _t_news(vl,GOAL,some_process);
978 T *e = _t_newr(d,EXPECT);
982 _t_news(e,GOAL,some_process);
984 T *a = _t_news(0,ACTION,RESPOND);
985 _stx_replace(stx,d,a);
986 spec_is_str_equal(t2s(d),
"(some_interaction (EXPECT (PATTERN) (ACTION:RESPOND)))");
1004 testMatchLiteralValue();
1006 testMatchGroupMulti();
1011 testSemtrexParseHHTPReq();
1012 testEmbodyFromMatch();
1013 testSemtrexReplace();
T * _t_new_root(Symbol symbol)
T * _makeHTTPRequestSemtrex()
T * __sl(T *p, bool not, int count,...)
T * _t_child(T *t, int i)
T * makeASCIITree(char *c)
int _t_match(T *semtrex, T *t)
T * _t_get_match(T *match, Symbol group)
T * _t_embody_from_match(SemTable *sem, T *match, Symbol group, T *t)
Symbol _d_define_symbol(SemTable *sem, Structure s, char *label, Context c)
int _t_matchr(T *semtrex, T *t, T **rP)
T * __r_make_signal(ReceptorAddress from, ReceptorAddress to, Aspect aspect, Symbol carrier, T *signal_contents, UUIDt *in_response_to, T *until, T *cid)
#define _sl(t, s)
macro to add a single symbol literal to semtrex tree
T * parseSemtrex(SemTable *sem, char *stx)
T * _t_parse(SemTable *sem, T *parent, char *s,...)
T * _stx_results2sem_map(SemTable *sem, T *match_results, T *match_tree)
char * _t2json(SemTable *sem, T *t, int level, char *buf)
char * _dump_semtrex(SemTable *sem, T *s, char *buf)
#define _sln(t, s)
macro to add a single symbol literal not to semtrex tree