ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
semtrex_spec.h
Go to the documentation of this file.
1 
7 #include "../src/ceptr.h"
8 #include "../src/hashfn.h"
9 #include "../src/semtrex.h"
10 #include "../src/receptor.h"
11 #include "http_example.h"
12 #include "spec_utils.h"
13 
14 Symbol sy0 = {0,0,0};
15 Symbol sy1 = {0,0,1};
16 Symbol sy11 = {0,0,11};
17 Symbol sy111 = {0,0,111};
18 Symbol sy2 = {0,0,2};
19 Symbol sy21 = {0,0,21};
20 Symbol sy22 = {0,0,22};
21 Symbol sy3 = {0,0,3};
22 Symbol sy4 = {0,0,4};
23 
24 Symbol TEST_GROUP_SYMBOL1;
25 Symbol TEST_GROUP_SYMBOL2;
26 
27 void _stxSetup() {
28  sYt(sy0,CSTRING);
29  sYt(sy1,CSTRING);
30  sYt(sy11,CSTRING);
31  sYt(sy111,CSTRING);
32  sYt(sy2,CSTRING);
33  sYt(sy21,CSTRING);
34  sYt(sy22,CSTRING);
35  sYt(sy3,CSTRING);
36  sYt(sy4,CSTRING);
37  sYt(TEST_GROUP_SYMBOL1,INTEGER);
38  sYt(TEST_GROUP_SYMBOL2,CSTRING);
39 
40 }
41 
42 T *_makeTestTree1() {
43  T *t = _t_new(0,TEST_STR_SYMBOL,"t",2);
44  T *t1 = _t_new(t,sy1,"t1",3); // 1, 11, etc., are chosen symbols to match where the nodes are in the tree structure. 3 is length of t1....etc...
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);
52  return t;
53 }
54 
55 T *_makeTestSemtrex1() {
56  // /TEST_STR_SYMBOL/(1/11/111),2,3
57  T *s = _sl(0,TEST_STR_SYMBOL);
58  T *ss = _t_newi(s,SEMTREX_SEQUENCE,0);
59  T *s1 = _sl(ss,sy1);
60  T *s11 = _sl(s1,sy11);
61  T *s111 = _sl(s11,sy111);
62  T *s2 = _sl(ss,sy2);
63  T *s3 = _sl(ss,sy3);
64  return s;
65 }
66 
67 /* #define spec_state_equal(sa,st,tt,s) \ */
68 /* spec_is_equal(sa->type,st);\ */
69 /* spec_is_equal(sa->transition,tt);\ */
70 /* spec_is_symbol_equal(0,*(Symbol *)_t_surface(sa->data.symbol.symbols),s); \ */
71 /* spec_is_ptr_equal(sa->out1,NULL); */
72 
73 
74 /* void testMakeFA() { */
75 /* SState *s1, *s2, *s3, *s4, *s5, *s6; */
76 /* T *s = _makeTestSemtrex1(); */
77 
78 /* int states = 0; */
79 /* SState *sa = _stx_makeFA(s,&states); */
80 /* spec_is_equal(states,6); */
81 
82 /* spec_state_equal(sa,StateSymbol,TransitionDown,TEST_STR_SYMBOL); */
83 
84 /* s1 = sa->out; */
85 /* spec_state_equal(s1,StateSymbol,TransitionDown,sy1); */
86 
87 /* s2 = s1->out; */
88 /* spec_state_equal(s2,StateSymbol,TransitionDown,sy11); */
89 
90 /* s3 = s2->out; */
91 /* spec_state_equal(s3,StateSymbol,-2,sy111); */
92 
93 /* s4 = s3->out; */
94 /* spec_state_equal(s4,StateSymbol,TransitionNextChild,sy2); */
95 
96 /* s5 = s4->out; */
97 /* spec_state_equal(s5,StateSymbol,TransitionUp,sy3); */
98 
99 /* s6 = s5->out; */
100 /* spec_is_equal(s6->type,StateMatch); */
101 
102 /* spec_is_ptr_equal(s6->out,NULL); */
103 
104 /* _stx_freeFA(sa); */
105 /* _t_free(s); */
106 /* } */
107 
108 void testMatchTrees() {
109  T *t = _makeTestTree1();
110  T *s = _makeTestSemtrex1();
111  T *s2;
112 
113  spec_is_true(_t_match(s,t));
114 
115  Symbol sy99 = {0,0,99};
116  s2 = _sl(_t_child(s,2),sy99);
117  spec_is_true(!_t_match(s,t));
118  _t_free(t);
119  _t_free(s);
120 }
121 
122 T *__stxcv(T *stxx,char c);
123 
124 void testMatchOr() {
125  T *t = _makeTestTree1();
126  T *s = _t_new_root(SEMTREX_OR);
127  T *s1 = _sl(s,sy1);
128  T *s11 = _sl(s1,sy11);
129  T *s2 = _sl(s,TEST_STR_SYMBOL);
130  T *s3;
131 
132  spec_is_true(_t_match(s,t));
133 
134  Symbol sy99 = {0,0,99};
135  s3 = _sl(s2,sy99);
136 
137  spec_is_true(!_t_match(s,t));
138 
139  _t_free(t);
140  _t_free(s);
141 
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')))))");
143 
144  char buf[2000];
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:')')");
147  spec_is_true(_t_match(s,t));
148  _t_free(t);
149 
150  t = _t_parse(G_sem,0,"(ASCII_CHARS (ASCII_CHAR:'/') (ASCII_CHAR:'(') (ASCII_CHAR:')')");
151  spec_is_true(_t_match(s,t));
152  _t_free(t);
153 
154  t = _t_parse(G_sem,0,"(ASCII_CHARS (ASCII_CHAR:'/') (ASCII_CHAR:')')");
155  spec_is_false(_t_match(s,t));
156  _t_free(t);
157 
158  _t_free(s);
159 
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)");
162 
163  t = _t_parse(G_sem,0,"(A (C (D)) (E))");
164 
165  //debug_enable(D_STX_MATCH);
166  spec_is_true(_t_match(s,t));
167  debug_disable(D_STX_MATCH);
168  _t_free(t);
169  t = _t_parse(G_sem,0,"(A (B) (E))");
170  spec_is_true(_t_match(s,t));
171  _t_free(t);
172  t = _t_parse(G_sem,0,"(A (C) (E))");
173  spec_is_false(_t_match(s,t));
174  _t_free(t);
175 
176  _t_free(s);
177 }
178 
179 void testMatchAny() {
180  T *t = _t_new(0,sy0,"t",2);
181  T *t1 = _t_new(t,sy1,"t1",3);
182 
183  T *s = _t_new_root(SEMTREX_SYMBOL_ANY);
184  T *ss = _t_newr(s,SEMTREX_SEQUENCE);
185  T *s1 = _sl(ss, sy1);
186 
187  spec_is_true(_t_match(s,t));
188  t->contents.symbol.id = 99;
189  spec_is_true(_t_match(s,t));
190 
191  _t_free(t);
192  _t_free(s);
193 }
194 
195 void testMatchExcept() {
196  T *t = _t_new(0,sy0,"t",2);
197  T *t1 = _t_new(t,sy1,"t1",3);
198 
199  // //!sy0/sy1
200  T *s = _sln(0,sy0);
201  T *ss = _t_newr(s,SEMTREX_SEQUENCE);
202  T *s1 = _sl(ss,sy1);
203  spec_is_true(!_t_match(s,t));
204 
205  _t_free(s);
206 
207  // //!sy1/sy1
208  s = _sln(0,sy1);
209  ss = _t_newr(s,SEMTREX_SEQUENCE);
210  _sl(ss,sy1);
211  spec_is_true(_t_match(s,t));
212 
213  _t_free(s);
214 
215  // //!{sy1,sy2}
216  s = __sl(0,1,2,sy1,sy2);
217  spec_is_true(_t_match(s,t));
218 
219  _t_free(s);
220 
221  // //!{sy1,sy0}
222  s = __sl(0,1,2,sy1,sy0);
223  spec_is_true(!_t_match(s,t));
224 
225  _t_free(s);
226 
227  // //{sy1,sy0}
228  s = __sl(0,0,2,sy1,sy0);
229  spec_is_true(_t_match(s,t));
230 
231  _t_free(s);
232 
233  // //{sy1,sy2}
234  s = __sl(0,0,2,sy1,sy2);
235  spec_is_true(!_t_match(s,t));
236 
237  _t_free(s);
238  _t_free(t);
239 }
240 
241 void testMatchStar() {
242  // /SIGNALS/<SIGNALS:SIGNAL*>
243  T *r;
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);
247  _sl(ss,SIGNAL);
248 
249  T *t = _t_new_root(SIGNALS);
250 
251  spec_is_true(_t_match(s,t));
252  // @todo this is actually broken, it looks like if you add the GROUP something has to match
253  //spec_is_true(_t_matchr(s,t,&r));
254  //spec_is_str_equal(t2s(r),"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:0))");
255  // _t_free(r);
256 
257  T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
258  ReceptorAddress fr = {3}; // DUMMY ADDR
259  ReceptorAddress to = {4}; // DUMMY ADDR
260  T *sig = __r_make_signal(fr,to,DEFAULT_ASPECT,TESTING,signal_contents,0,0,0);
261  T *sig2 = _t_clone(sig);
262  _t_add(t,sig);
263 
264  spec_is_true(_t_matchr(s,t,&r));
265  spec_is_str_equal(t2s(r),"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
266  _t_free(r);
267 
268  _t_add(t,sig2);
269  spec_is_true(_t_matchr(s,t,&r));
270  spec_is_str_equal(t2s(r),"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:2))");
271  _t_free(r);
272 
273  spec_is_false(_t_match(s,signal_contents));
274  _t_free(t);
275  _t_free(s);
276 
277  char buf[1000];
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))))");
279  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),"/A/(B*,C)");
280 
281  t = _t_parse(G_sem,0,"(A (B) (C))");
282  spec_is_true(_t_match(s,t));
283  _t_free(t);
284  t = _t_parse(G_sem,0,"(A (B) (B) (B) (C))");
285  spec_is_true(_t_match(s,t));
286  _t_free(t);
287  _t_free(s);
288 
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))))");
290  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),"/A/(B/C*,D)");
291 
292  t = _t_parse(G_sem,0,"(A (B (C)) (D))");
293 // debug_enable(D_STX_MATCH+D_STX_BUILD);
294  spec_is_true(_t_match(s,t));
295  debug_disable(D_STX_MATCH+D_STX_BUILD);
296  _t_free(t);
297 
298  t = _t_parse(G_sem,0,"(A (B) (D))");
299 // debug_enable(D_STX_MATCH+D_STX_BUILD);
300  spec_is_true(_t_match(s,t));
301  debug_disable(D_STX_MATCH+D_STX_BUILD);
302  _t_free(t);
303 
304 
305  _t_free(s);
306 
307 }
308 
309 void testMatchPlus() {
310  // /SIGNALS/<SIGNALS:SIGNAL+>
311  T *r;
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);
315  _sl(ss,SIGNAL);
316 
317  T *t = _t_new_root(SIGNALS);
318 
319  spec_is_false(_t_matchr(s,t,&r));
320 
321  T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
322  ReceptorAddress fr = {3}; // DUMMY ADDR
323  ReceptorAddress to = {4}; // DUMMY ADDR
324  T *sig = __r_make_signal(fr,to,DEFAULT_ASPECT,TESTING,signal_contents,0,0,0);
325  T *sig2 = _t_clone(sig);
326  _t_add(t,sig);
327  spec_is_true(_t_matchr(s,t,&r));
328  spec_is_str_equal(t2s(r),"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
329  _t_free(r);
330 
331  _t_add(t,sig2);
332  spec_is_true(_t_matchr(s,t,&r));
333  spec_is_str_equal(t2s(r),"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:2))");
334  _t_free(r);
335 
336  spec_is_false(_t_match(s,signal_contents));
337  _t_free(t);
338  _t_free(s);
339 }
340 
341 void testMatchQ() {
342  // /SIGNALS/<SIGNALS:SIGNAL?>
343  T *r;
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);
347  _sl(ss,SIGNAL);
348 
349  T *t = _t_new_root(SIGNALS);
350 
351  spec_is_true(_t_match(s,t));
352  // @todo this is actually broken, it looks like if you add the GROUP something has to match
353  //spec_is_true(_t_matchr(s,t,&r));
354  //spec_is_str_equal(t2s(r),"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:0))");
355  // _t_free(r);
356 
357  T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
358  ReceptorAddress fr = {3}; // DUMMY ADDR
359  ReceptorAddress to = {4}; // DUMMY ADDR
360  T *sig = __r_make_signal(fr,to,DEFAULT_ASPECT,TESTING,signal_contents,0,0,0);
361  T *sig2 = _t_clone(sig);
362  _t_add(t,sig);
363  //debug_enable(D_STX_MATCH);
364  spec_is_true(_t_matchr(s,t,&r));
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))");
367  _t_free(r);
368 
369  // add a second signal and it still only matches on the first sibling
370  _t_add(t,sig2);
371  spec_is_true(_t_matchr(s,t,&r));
372  spec_is_str_equal(t2s(r),"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:SIGNALS) (SEMTREX_MATCH_PATH:/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
373  _t_free(r);
374 
375  spec_is_false(_t_match(s,signal_contents));
376  _t_free(t);
377  _t_free(s);
378 }
379 
380 void testMatchGroup() {
381  T *sg2, *s3, *t, *r, *p1, *p2, *p1c, *p2c;
382  t = _makeTestTree1();
383 
384  // /<TEST_STR_SYMBOL:TEST_STR_SYMBOL> <- the most simple group semtrex
385  T *g = _t_news(0,SEMTREX_GROUP,TEST_STR_SYMBOL);
386  _sl(g,TEST_STR_SYMBOL);
387 
388  spec_is_true(_t_matchr(g,t,&r));
389 
390  _t_free(r);
391 
392  // /TEST_STR_SYMBOL/(<TEST_GROUP_SYMBOL1:.*,<TEST_GROUP_SYMBOL2:.>>,sy4) <- a more complicated group semtrex
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);
401  s3 = _sl(ss,sy4);
402 
403  //debug_enable(D_STX_MATCH);
404  spec_is_true(_t_matchr(s,t,&r));
405  debug_disable(D_STX_MATCH);
406 
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)))");
408 
409  // @todo fix this spec so it will work. The spec uses nonsensical
410  // TEST_GROUP_SYMBOL that are integers so you wouldn't actually match on them
411  // for something with children...
412  // T *map = _stx_results2sem_map(G_sem,r,t);
413  //spec_is_str_equal(t2s(map),"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:TEST_GROUP_SYMBOL1) (REPLACEMENT_VALUE (TEST_GROUP_SYMBOL1:16789876 (sy11:t11 (sy111:t111))))) (SEMANTIC_LINK (USAGE:TEST_GROUP_SYMBOL2) (REPLACEMENT_VALUE (TEST_GROUP_SYMBOL2:t3))))");
414 
415  // you should also be able to find the matched group by uid
416  spec_is_ptr_equal(_t_get_match(r,TEST_GROUP_SYMBOL1),r);
417  spec_is_ptr_equal(_t_get_match(r,TEST_GROUP_SYMBOL2),_t_child(r,4));
418  _t_free(r);
419  _t_free(s);
420 
421  // /TEST_STR_SYMBOL/(<TEST_GROUP_SYMBOL1:<TEST_GROUP_SYMBOL2:.>*>,sy4) <- a more complicated group semtrex, this time where a group will be repeated
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))))");
423  char buf[2000];
424  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),"/TEST_STR_SYMBOL/(<TEST_GROUP_SYMBOL1:<TEST_GROUP_SYMBOL2:.>*>,sy4)");
425  //t = _t_parse(G_sem,0,"");
426  //t = (TEST_STR_SYMBOL:t (sy1:t1 (sy11:t11 (sy111:t111))) (sy2:t2 (sy21:t21) (sy22:t22)) (sy3:t3) (sy4:t4))
427  //debug_enable(D_STX_MATCH+D_STX_BUILD);
428  spec_is_true(_t_matchr(s,t,&r));
429  debug_disable(D_STX_MATCH+D_STX_BUILD);
430 
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)))");
432  _t_free(s);
433  _t_free(r);
434 
435  // test that the correct number of siblings is returned when the match matches a
436  // sequence that includes the final sibiling
437  // /TEST_STR_SYMBOL/.*,<TEST_GROUP_SYMBOL:sy3,sy4>
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);
444  _sl(ss2,sy3);
445  _sl(ss2,sy4);
446  //debug_enable(D_STX_MATCH);
447  spec_is_true(_t_matchr(s,t,&r));
448  //debug_disable(D_STX_MATCH);
449 
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))");
451 
452  _t_free(r);
453  _t_free(t);
454  _t_free(s);
455  _t_free(g);
456 
457  sg = _t_news(0,SEMTREX_GROUP,VERB);
458  s = _t_newr(sg,SEMTREX_SYMBOL_LITERAL);
459  _t_news(s,SEMTREX_SYMBOL,LINE);
460 
461  t = _t_new_str(0,LINE,"receptors");
462  spec_is_true(_t_matchr(sg,t,&r));
463  spec_is_str_equal(t2s(r), "(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:VERB) (SEMTREX_MATCH_PATH:/) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
464 
465  T *map = _stx_results2sem_map(G_sem,r,t);
466  spec_is_str_equal(t2s(map),"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:VERB) (REPLACEMENT_VALUE (VERB:receptors))))");
467 
468  _t_free(map);
469  _t_free(r);
470  _t_free(t);
471  _t_free(sg);
472 
473 }
474 
475 void testMatchGroupMulti() {
476  sX(TSTX_TOKENS,NULL_STRUCTURE); //should be some optionality LIST
477  sX(TSTX_OP,NULL_STRUCTURE);
478  sX(TSTX_SL,NULL_STRUCTURE);
479 
480  T *s = _t_new_root(ASCII_CHARS);
481  _t_newc(s,ASCII_CHAR,'/');
482  _t_newc(s,ASCII_CHAR,'(');
483  _t_newc(s,ASCII_CHAR,'(');
484 
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);
491  __stxcv(t,'/');
492  t = _t_news(o,SEMTREX_GROUP,STX_OP);
493  __stxcv(t,'(');
494 
495  T *results;
496  _t_matchr(ts,s,&results);
497 
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)))");
499 
500  _t_free(s);
501  _t_free(results);
502  _t_free(ts);
503 }
504 
505 T *newvl(T *p,int not,int count,...) {
506  va_list values;
507  T *t = _t_newr(p,not ? SEMTREX_VALUE_LITERAL_NOT : SEMTREX_VALUE_LITERAL);
508  T *v = _t_newr(t,SEMTREX_VALUE_SET);
509 
510  va_start(values,count);
511  int i;
512  for(i=0;i<count;i++) {
513  T *x = va_arg(values,T *);
514  _t_add(v,x);
515  }
516  va_end(values);
517  return t;
518 }
519 
520 void testMatchLiteralValue() {
521  T *t = _makeTestTree1();
522  T *s;
523 
524  // /TEST_INT_SYMBOL!="t"
525  s = newvl(0,1,1,_t_new(0,TEST_STR_SYMBOL,"t",2));
526  spec_is_true(!_t_match(s,t));
527  _t_free(s);
528 
529  // /TEST_INT_SYMBOL="t"
530  s = newvl(0,0,1,_t_new(0,TEST_STR_SYMBOL,"t",2));
531  spec_is_true(_t_match(s,t));
532  _t_free(s);
533 
534  // /TEST_INT_SYMBOL2="t"
535  // don't match on wrong symbol
536  s = newvl(0,0,1,_t_new(0,TEST_INT_SYMBOL2,"t",2));
537  spec_is_true(!_t_match(s,t));
538  _t_free(s);
539 
540  // /TEST_INT_SYMBOL="x"
541  // don't match if value is wrong
542  s = newvl(0,0,1,_t_new(0,TEST_STR_SYMBOL,"x",2));
543  spec_is_true(!_t_match(s,t));
544  _t_free(s);
545 
546  // /TEST_INT_SYMBOL=""
547  // don't match if value length is wrong
548  s = newvl(0,0,1,_t_new(0,TEST_STR_SYMBOL,"tt",3));
549  spec_is_true(!_t_match(s,t));
550  _t_free(s);
551 
552  // /TEST_INT_SYMBOL={"t","q"}
553  s = newvl(0,0,2,_t_new(0,TEST_STR_SYMBOL,"t",2),_t_new(0,TEST_STR_SYMBOL,"q",2));
554  spec_is_true(_t_match(s,t));
555  _t_free(s);
556 
557  // /TEST_INT_SYMBOL={"q","x"}
558  s = newvl(0,0,2,_t_new(0,TEST_STR_SYMBOL,"q",2),_t_new(0,TEST_STR_SYMBOL,"x",2));
559  spec_is_true(!_t_match(s,t));
560  _t_free(s);
561 
562  // /TEST_INT_SYMBOL!={"q","x"}
563  s = newvl(0,1,2,_t_new(0,TEST_STR_SYMBOL,"q",2),_t_new(0,TEST_STR_SYMBOL,"x",2));
564  spec_is_true(_t_match(s,t));
565  _t_free(s);
566 
567  // /TEST_INT_SYMBOL!={"q","t"}
568  s = newvl(0,1,2,_t_new(0,TEST_STR_SYMBOL,"q",2),_t_new(0,TEST_STR_SYMBOL,"t",2));
569  spec_is_true(!_t_match(s,t));
570  _t_free(s);
571 
572  _t_free(t);
573 
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:' ')))))))");
575  char buf[2000];
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:'/'))");
578 
579  T *r;
580  //debug_enable(D_STX_MATCH+D_STX_BUILD);
581  spec_is_true(_t_matchr(s,t,&r));
582  debug_disable(D_STX_MATCH+D_STX_BUILD);
583 
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))");
585 
586  _t_free(r);
587  _t_free(t);
588  _t_free(s);
589 
590 }
591 
592 void testMatchDescend() {
593  T *t = _makeTestTree1();
594 
595  // //sy1
596  T *s = _t_new_root(SEMTREX_DESCEND);
597  _sl(s,sy1);
598  spec_is_true(_t_match(s,t));
599  _t_free(s);
600 
601  // //sy11 <- shouldn't match
602  s = _t_new_root(SEMTREX_DESCEND);
603  _sl(s,sy11);
604  spec_is_true(!_t_match(s,t));
605  _t_free(s);
606 
607  // ///sy11
608  s = _t_new_root(SEMTREX_DESCEND);
609  T *ss = _t_newr(s,SEMTREX_DESCEND);
610  _sl(ss,sy11);
611  spec_is_true(_t_match(s,t));
612  _t_free(s);
613 
614 
615  _t_free(t);
616 }
617 
618 void testMatchWalk() {
619  T *t = _makeTestTree1();
620 
621  // search for a node down the left branch
622  // /%sy111
623  T *s = _t_new_root(SEMTREX_WALK);
624 
625  _sl(s,sy111);
626  spec_is_true(_t_match(s,t));
627  _t_free(s);
628 
629  // search for a node that doesn't exist
630  // /%TEST_INT_SYMBOL
631  s = _t_new_root(SEMTREX_WALK);
632  _sl(s,TEST_INT_SYMBOL);
633  spec_is_true(!_t_match(s,t));
634  _t_free(s);
635 
636  // search for a node down a right branch
637  // /%sy22
638  s = _t_new_root(SEMTREX_WALK);
639  _sl(s,sy22);
640  spec_is_true(_t_match(s,t));
641  _t_free(s);
642 
643  // search for a sequence
644  // %(sy3,sy4)
645  //debug_enable(D_STX_MATCH);
646  s = _t_new_root(SEMTREX_WALK);
647  T *g = _t_news(s,SEMTREX_GROUP,TEST_GROUP_SYMBOL1);
648  T *sq = _t_newr(g,SEMTREX_SEQUENCE);
649  _sl(sq,sy3);
650  _sl(sq,sy4);
651  T *results;
652  spec_is_true(_t_matchr(s,t,&results));
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))");
654 
655  _t_free(results);
656  _t_free(s);
657 
658  _t_free(t);
659 
660  // this test is taken from code that broke in semtrex parsing, I think because of the
661  // walking
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\")))");
664 
665  //debug_enable(D_STX_MATCH);
666  _t_matchr(s,t,&results);
667  debug_disable(D_STX_MATCH);
668 
669 }
670 
671 void testMatchNot() {
672  T *t = _makeTestTree1();
673 
674  // /TEST_STR_SYMBOL/~sy2
675  T *s = _sl(0,TEST_STR_SYMBOL);
676  T *n = _t_newr(s,SEMTREX_NOT);
677  n = _sl(n,sy2);
678  spec_is_true(_t_match(s,t));
679  _t_free(s);
680 
681  // /TEST_STR_SYMBOL/~sy1
682  s = _sl(0,TEST_STR_SYMBOL);
683  n = _t_newr(s,SEMTREX_NOT);
684  n = _sl(n,sy1);
685  spec_is_true(!_t_match(s,t));
686  _t_free(s);
687  _t_free(t);
688 
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);
694 
695  t = _t_new_root(R);
696  _t_newr(t,A);
697  _t_newr(t,B);
698  _t_newr(t,A);
699  _t_newr(t,B);
700  _t_newr(t,B);
701  _t_newr(t,C);
702 
703  char buf[2000];
704  T *g,*x,*results;
705 
706  s = _t_newr(0,SEMTREX_WALK);
707  g = _t_news(s,SEMTREX_GROUP,G);
708  x = _t_newr(g,SEMTREX_SEQUENCE);
709  // x = _t_newr(x,SEMTREX_NOT);
710  //_sl(x,A);
711 
712  _sl(x,B);
713  n = _t_newr(x,SEMTREX_NOT);
714  _sl(n,A);
715  n = _t_newr(x,SEMTREX_NOT);
716  _sl(n,A);
717  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),"");
718 
719  stx_dump(s);
720 
721  //debug_enable(D_STX_MATCH);
722  spec_is_true(_t_matchr(s,t,&results));
723  //debug_disable(D_STX_MATCH);
724 
725  spec_is_str_equal(t2s(results),"");
726  //int *p = _t_get_path(G_ts);
727  //puts("MATCHPATH:");
728  //puts(_t_sprint_path(p,buf));
729 
730  //_t_free(results);
731  //free(p);
732 
733 /* __t_dump(0,t,0,buf);
734  puts("ABABBA:");
735  puts(buf);
736 */
737  _t_free(s);
738  _t_free(t);
739 
740 }
741 
742 void testSemtrexDump() {
743  T *s = _makeTestSemtrex1();
744  char buf[2000];
745 
746  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),"/TEST_STR_SYMBOL/(sy1/sy11/sy111,sy2,sy3)");
747  _t_free(s);
748 
749  // /TEST_STR_SYMBOL/<.*,<.>>,4 <- a more complicated group semtrex
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);
758  T *s3 = _sl(ss,sy4);
759  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),"/TEST_STR_SYMBOL/(<TEST_GROUP_SYMBOL1:.*,<TEST_GROUP_SYMBOL2:.>>,sy4)");
760  _t_free(s);
761 
762  // /TEST_STR_SYMBOL|TEST_INT_SYMBOL
763  s = _t_new_root(SEMTREX_OR);
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");
767  _t_free(s);
768 
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'");
771  _t_free(s);
772 
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'");
775  _t_free(s);
776 
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\"");
779  _t_free(s);
780 
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");
783  _t_free(s);
784 
785  // /TEST_STR_SYMBOL/~sy1
786  s = _sl(0,TEST_STR_SYMBOL);
787  T *n = _t_newr(s,SEMTREX_NOT);
788  n = _sl(n,sy1);
789  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),"/TEST_STR_SYMBOL/~sy1");
790  _t_free(s);
791 
792 }
793 
794 void testSemtrexParse() {
795  char buf[5000];
796 
797  char *stx;
798  T *s;
799  stx = "/TEST_STR_SYMBOL/(sy1/sy11/sy111,sy2,sy3)";
800 
801  s = parseSemtrex(G_sem,stx);
802 
803  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
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))))");
805  _t_free(s);
806 
807  stx = "/STX_STAR|STX_PLUS|STX_Q";
808  s = parseSemtrex(G_sem,stx);
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)))");
811  _t_free(s);
812 
813  stx = "/TEST_STR_SYMBOL/(.+,sy1,.*,sy2,.?)";
814  s = parseSemtrex(G_sem,stx);
815  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
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))))");
817  _t_free(s);
818 
819  stx = "/STX_TOKENS/(%<SEMTREX_SEQUENCE:(!STX_COMMA,STX_COMMA)+,!STX_COMMA>)";
820  s = parseSemtrex(G_sem,stx);
821  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
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))))))");
823  _t_free(s);
824 
825  stx = "/HTTP_REQUEST/(.,.,HTTP_REQUEST_PATH/HTTP_REQUEST_PATH_SEGMENTS/<HTTP_REQUEST_PATH_SEGMENT:HTTP_REQUEST_PATH_SEGMENT>)";
826  s = parseSemtrex(G_sem,stx);
827  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
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)))))))");
829  _t_free(s);
830 
831  stx = "/TEST_STR_SYMBOL/(TEST_INT_SYMBOL=314,ASCII_CHAR='x',TEST_STR_SYMBOL=\"abc\",TEST_STR_SYMBOL!=\"abc\")";
832  s = parseSemtrex(G_sem,stx);
833  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
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))))");
835  _t_free(s);
836 
837  stx = "/TEST_STR_SYMBOL/~sy2";
838  s = parseSemtrex(G_sem,stx);
839  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
840  spec_is_str_equal(t2s(s),"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL) (SEMTREX_NOT (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:sy2))))");
841  _t_free(s);
842 
843 
844  stx = "/STX_TOKENS/(.*,<STX_OP:STX_OP,<STX_SIBS:!STX_CP+>,STX_CP>)";
845  s = parseSemtrex(G_sem,stx);
846  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
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))))))");
848  _t_free(s);
849 
850  stx = "/TEST_STR_SYMBOL=\"fish\"";
851  s = parseSemtrex(G_sem,stx);
852  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
853  spec_is_str_equal(t2s(s),"(SEMTREX_VALUE_LITERAL (TEST_STR_SYMBOL:fish))");
854  _t_free(s);
855 
856  stx = "/ASCII_CHARS/(ASCII_CHAR={'a','b'},ASCII_CHAR!={'a','b'})";
857  s = parseSemtrex(G_sem,stx);
858  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
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')))))");
860  _t_free(s);
861 
862  stx = "/STX_TOKENS/(!{STX_OP,STX_CP},ASCII_CHAR!={'a','b'},{STX_OP,STX_CP})";
863  s = parseSemtrex(G_sem,stx);
864  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
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)))))");
866  _t_free(s);
867 
868  stx = "/HTTP_REQUEST/(HTTP_REQUEST_HEADERS/HTTP_REQUEST_HOST*,HTTP_REQUEST_BODY)";
869  s = parseSemtrex(G_sem,stx);
870  spec_is_str_equal(_dump_semtrex(G_sem,s,buf),stx);
871 
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))))");
873 // stx_dump(s);
874 //(HTTP_REQUEST_LINE (HTTP_REQUEST_VERSION (VERSION_MAJOR:1) (VERSION_MINOR:1)) (HTTP_REQUEST_METHOD:\"GET\") (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:\"groups\") (HTTP_REQUEST_PATH_SEGMENT:\"5\")) (HTTP_REQUEST_PATH_FILE (FILE_NAME:\"users\") (FILE_EXTENSION:\"json\")) (HTTP_REQUEST_PATH_QUERY (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:\"sort_by\") (PARAM_VALUE:\"last_name\")) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:\"page\") (PARAM_VALUE:\"2\"))))))
875  T *t = _t_parse(G_sem,0,"(HTTP_REQUEST (HTTP_REQUEST_HEADERS (HTTP_REQUEST_HOST:\"fish.com\")) (HTTP_REQUEST_BODY))");
876 
877  spec_is_true(_t_match(s,t));
878  _t_free(s);
879  _t_free(t);
880 
881 }
882 
883 void testSemtrexParseHHTPReq() {
884  char *req = "GET /path/to/file.ext?name=joe&age=30 HTTP/0.9";
885  T *r,*s = makeASCIITree(req);
886 
887  char buf[50000];
888  T *stx;
889  stx = _makeHTTPRequestSemtrex();
890 
891  // we add the NULL_SYMBOL group in to test the kind of match that happens on expectations
892  T *x = _t_news(0,SEMTREX_GROUP,NULL_SYMBOL);
893  _t_add(x,stx);
894  stx = x;
895 
896  _t2json(G_sem,stx,INDENT,buf);
897  writeFile("web/httpreqstx.json",buf,strlen(buf));
898 
899  _dump_semtrex(G_sem,stx,buf);
900 
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'>>>>");
902 
903  //debug_enable(D_STX_MATCH);
904  spec_is_true(_t_matchr(stx,s,&r));
905  //debug_disable(D_STX_MATCH);
906 
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)))))");
908 
909  T *t = _t_embody_from_match(G_sem,r,HTTP_REQUEST,s);
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)))");
911 
912  T *map = _stx_results2sem_map(G_sem,r,s);
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))))");
914  _t_free(r);
915  _t_free(map);
916 
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\")");
918 
919  spec_is_true(_t_match(pstx,t));
920 
921  _t_free(pstx);
922  _t_free(t);
923  _t_free(s);
924  _t_free(stx);
925 }
926 
927 void testEmbodyFromMatch() {
928 
929  // test how embody from match ignores any capture that's identified as NULL_SYMBOL
930  char *ts = "label:abc,123,3.1415";
931  T *r,*t = makeASCIITree(ts);
932  sX(LABELED_TRIPLET,NULL_STRUCTURE); //should be an optionality LIST
933  sX(LABEL,CSTRING);
934  sX(X1,CSTRING);
935  sX(X2,INTEGER);
936  sX(X3,FLOAT);
937 
938  T *s;
939  char *stx;
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+>)>");
941 
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)))))))");
943 
944  spec_is_true(_t_matchr(s,t,&r));
945 
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))");
948 
949  _t_free(r);
950  _t_free(s);
951 
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))))");
954  spec_is_true(_t_match(s,e));
955 
956  // _t_free(r);
957  _t_free(s);
958 
959  _t_free(e);
960  _t_free(t);
961 }
962 
963 void testSemtrexReplace() {
964  // char *stx = "%EXPECT/.*,<ACTION:GOAL=RESPOND>";
965  // T *s = parseSemtrex(G_sem,stx); Doesn't work for symbols as value literals, sigh
966  // %EXPECT/.*,<ACTION:GOAL=some_process>
967  T *stx = _t_new_root(SEMTREX_WALK);
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);
973  Symbol some_process = _d_define_symbol(G_sem,PROCESS,"some_process",TEST_CONTEXT);
974  Symbol some_interaction = _d_define_symbol(G_sem,INTERACTION,"some_interaction",TEST_CONTEXT);
975  _t_news(vl,GOAL,some_process);
976 
977  T *d = _t_new_root(some_interaction);
978  T *e = _t_newr(d,EXPECT);
979  // _t_newr(rp,ROLE);
980  // _t_newr(rp,SOURCE);
981  _t_newr(e,PATTERN);
982  _t_news(e,GOAL,some_process);
983 
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)))");
987  _t_free(d);
988  _t_free(stx);
989  _t_free(a);
990 }
991 
992 
993 void testSemtrex() {
994  _stxSetup();
995  //testMakeFA();
996  testMatchTrees();
997  testSemtrexDump();
998  testMatchOr();
999  testMatchAny();
1000  testMatchExcept();
1001  testMatchStar();
1002  testMatchPlus();
1003  testMatchQ();
1004  testMatchLiteralValue();
1005  testMatchGroup();
1006  testMatchGroupMulti();
1007  testMatchDescend();
1008  testMatchWalk();
1009  //testMatchNot();
1010  testSemtrexParse();
1011  testSemtrexParseHHTPReq();
1012  testEmbodyFromMatch();
1013  testSemtrexReplace();
1014 }
T * _t_new_root(Symbol symbol)
Definition: tree.c:160
Definition: ceptr_types.h:114
T * _makeHTTPRequestSemtrex()
Definition: http_example.h:91
T * _t_clone(T *t)
Definition: tree.c:589
T * __sl(T *p, bool not, int count,...)
Definition: semtrex.c:1279
T * _t_child(T *t, int i)
Definition: tree.c:1251
T * makeASCIITree(char *c)
Definition: semtrex.c:1206
int _t_match(T *semtrex, T *t)
Definition: semtrex.c:809
T * _t_get_match(T *match, Symbol group)
Definition: semtrex.c:848
T * _t_embody_from_match(SemTable *sem, T *match, Symbol group, T *t)
Definition: semtrex.c:873
Symbol _d_define_symbol(SemTable *sem, Structure s, char *label, Context c)
Definition: def.c:83
int _t_matchr(T *semtrex, T *t, T **rP)
Definition: semtrex.c:798
T * __r_make_signal(ReceptorAddress from, ReceptorAddress to, Aspect aspect, Symbol carrier, T *signal_contents, UUIDt *in_response_to, T *until, T *cid)
Definition: receptor.c:515
#define _sl(t, s)
macro to add a single symbol literal to semtrex tree
Definition: semtrex.h:122
T * parseSemtrex(SemTable *sem, char *stx)
Definition: semtrex.c:1298
T * _t_parse(SemTable *sem, T *parent, char *s,...)
Definition: tree.c:919
void _t_add(T *t, T *c)
Definition: tree.c:261
T * _stx_results2sem_map(SemTable *sem, T *match_results, T *match_tree)
Definition: semtrex.c:2029
Definition: ceptr_types.h:168
char * _t2json(SemTable *sem, T *t, int level, char *buf)
Definition: tree.c:1912
char * _dump_semtrex(SemTable *sem, T *s, char *buf)
Definition: semtrex.c:1096
void _t_free(T *t)
Definition: tree.c:526
#define _sln(t, s)
macro to add a single symbol literal not to semtrex tree
Definition: semtrex.h:125