2014-05-25 21:35:50 +01:00
|
|
|
#define WIN32_MEAN_AND_LEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
//#include <windows.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#define STB_DEFINE
|
2019-02-07 12:42:32 +00:00
|
|
|
#ifndef _M_AMD64
|
2014-05-25 21:35:50 +01:00
|
|
|
#define STB_NPTR
|
2019-02-07 12:42:32 +00:00
|
|
|
#endif
|
2014-05-25 21:35:50 +01:00
|
|
|
#define STB_ONLY
|
|
|
|
#include "stb.h"
|
|
|
|
//#include "stb_file.h"
|
|
|
|
|
|
|
|
int count;
|
2019-03-04 22:45:06 +00:00
|
|
|
void c(int truth, const char *error)
|
2014-05-25 21:35:50 +01:00
|
|
|
{
|
|
|
|
if (!truth) {
|
|
|
|
fprintf(stderr, "Test failed: %s\n", error);
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 22:45:06 +00:00
|
|
|
char *expects(stb_matcher *m, char *s, int result, int len, const char *str)
|
2014-05-25 21:35:50 +01:00
|
|
|
{
|
|
|
|
int res2,len2=0;
|
|
|
|
res2 = stb_lex(m, s, &len2);
|
|
|
|
c(result == res2 && len == len2, str);
|
|
|
|
return s + len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_lex(void)
|
|
|
|
{
|
|
|
|
stb_matcher *m = stb_lex_matcher();
|
|
|
|
// tok_en5 .3 20.1 20. .20 .1
|
2019-03-04 22:45:06 +00:00
|
|
|
char *s = (char*) "tok_en5.3 20.1 20. .20.1";
|
2014-05-25 21:35:50 +01:00
|
|
|
|
|
|
|
stb_lex_item(m, "[a-zA-Z_][a-zA-Z0-9_]*", 1 );
|
|
|
|
stb_lex_item(m, "[0-9]*\\.?[0-9]*" , 2 );
|
|
|
|
stb_lex_item(m, "[\r\n\t ]+" , 3 );
|
|
|
|
stb_lex_item(m, "." , -99 );
|
|
|
|
s=expects(m,s,1,7, "stb_lex 1");
|
|
|
|
s=expects(m,s,2,2, "stb_lex 2");
|
|
|
|
s=expects(m,s,3,1, "stb_lex 3");
|
|
|
|
s=expects(m,s,2,4, "stb_lex 4");
|
|
|
|
s=expects(m,s,3,1, "stb_lex 5");
|
|
|
|
s=expects(m,s,2,3, "stb_lex 6");
|
|
|
|
s=expects(m,s,3,1, "stb_lex 7");
|
|
|
|
s=expects(m,s,2,3, "stb_lex 8");
|
|
|
|
s=expects(m,s,2,2, "stb_lex 9");
|
|
|
|
s=expects(m,s,0,0, "stb_lex 10");
|
|
|
|
stb_matcher_free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2020-02-01 12:21:41 +00:00
|
|
|
#if 0
|
2014-05-25 21:35:50 +01:00
|
|
|
char *p;
|
2019-03-04 22:45:06 +00:00
|
|
|
p = (char*) "abcdefghijklmnopqrstuvwxyz";
|
2014-05-25 21:35:50 +01:00
|
|
|
c(stb_ischar('c', p), "stb_ischar 1");
|
|
|
|
c(stb_ischar('x', p), "stb_ischar 2");
|
|
|
|
c(!stb_ischar('#', p), "stb_ischar 3");
|
|
|
|
c(!stb_ischar('X', p), "stb_ischar 4");
|
2019-03-04 22:45:06 +00:00
|
|
|
p = (char*) "0123456789";
|
2014-05-25 21:35:50 +01:00
|
|
|
c(!stb_ischar('c', p), "stb_ischar 5");
|
|
|
|
c(!stb_ischar('x', p), "stb_ischar 6");
|
|
|
|
c(!stb_ischar('#', p), "stb_ischar 7");
|
|
|
|
c(!stb_ischar('X', p), "stb_ischar 8");
|
2019-03-04 22:45:06 +00:00
|
|
|
p = (char*) "#####";
|
2014-05-25 21:35:50 +01:00
|
|
|
c(!stb_ischar('c', p), "stb_ischar a");
|
|
|
|
c(!stb_ischar('x', p), "stb_ischar b");
|
|
|
|
c(stb_ischar('#', p), "stb_ischar c");
|
|
|
|
c(!stb_ischar('X', p), "stb_ischar d");
|
2019-03-04 22:45:06 +00:00
|
|
|
p = (char*) "xXyY";
|
2014-05-25 21:35:50 +01:00
|
|
|
c(!stb_ischar('c', p), "stb_ischar e");
|
|
|
|
c(stb_ischar('x', p), "stb_ischar f");
|
|
|
|
c(!stb_ischar('#', p), "stb_ischar g");
|
|
|
|
c(stb_ischar('X', p), "stb_ischar h");
|
2020-02-01 12:21:41 +00:00
|
|
|
#endif
|
2014-05-25 21:35:50 +01:00
|
|
|
|
|
|
|
test_lex();
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
_getch();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|