*** empty log message ***

This commit is contained in:
2005-06-06 03:47:56 +00:00
parent 2837717c2a
commit 9833d078dd
4 changed files with 127 additions and 35 deletions

View File

@ -13,27 +13,77 @@
struct ss_t
{
const xp_stx_char_t* text;
xp_size_t size;
xp_size_t index;
};
typedef struct ss_t ss_t;
int ss_input (void* owner, int cmd, void* arg)
int ss_func (int cmd, void* owner, void* arg)
{
ss_t* ss = (ss_t*)owner;
if (cmd == XP_STX_PARSER_INPUT_OPEN) {
ss_t* ss = *(ss_t**)owner;
ss->text = (const xp_stx_char_t*)arg;
ss->index = 0;
return 0;
}
else if (cmd == XP_STX_PARSER_INPUT_CLOSE) {
//ss_t* ss = (ss_t*)owner;
return 0;
}
else if (cmd == XP_STX_PARSER_INPUT_CONSUME) {
if (ss->index < ss->size) *c = ss->text[ss->index++];
else *c = XP_STX_CHAR_EOF;
ss_t* ss = (ss_t*)owner;
xp_cint_t* c = (xp_cint_t*)arg;
if (ss->text[ss->index] == XP_STX_CHAR('\0')) {
*c = XP_STX_CHAR_EOF;
}
else *c = ss->text[ss->index++];
return 0;
}
return 0;
else if (cmd == XP_STX_PARSER_INPUT_REWIND) {
return 0;
}
return -1;
}
struct stdio_t
{
XP_FILE* stdio;
};
typedef struct stdio_t stdio_t;
int stdio_func (int cmd, void* owner, void* arg)
{
if (cmd == XP_STX_PARSER_INPUT_OPEN) {
stdio_t* p = *(stdio_t**)owner;
p->stdio = xp_fopen ((const xp_char_t*)arg, XP_TEXT("r"));
if (p->stdio == XP_NULL) return -1;
return 0;
}
else if (cmd == XP_STX_PARSER_INPUT_CLOSE) {
stdio_t* p = (stdio_t*)owner;
xp_fclose (p->stdio);
return 0;
}
else if (cmd == XP_STX_PARSER_INPUT_CONSUME) {
stdio_t* p = (stdio_t*)owner;
xp_cint_t* c = (xp_cint_t*)arg;
xp_cint_t t = xp_fgetc (p->stdio);
if (t == EOF) {
if (xp_ferror (p->stdio)) return -1;
*c = XP_STX_CHAR_EOF;
}
else *c = t;
xp_printf (XP_TEXT("[%c]\n"), *c);
return 0;
}
else if (cmd == XP_STX_PARSER_INPUT_REWIND) {
return 0;
}
return -1;
}
int xp_main (int argc, xp_char_t* argv[])
@ -53,17 +103,21 @@ int xp_main (int argc, xp_char_t* argv[])
return -1;
}
parser.input_func = ss_func;
{
/*
ss_t ss = {
XP_STX_TEXT("isNil\n^true"),
11,
0
};
*/
xp_stx_parser_parse_method (&parser, 0, &ss);
/*
ss_t ss;
parser.input_owner = (void*)&ss;
parser.input_func = ss_func;
xp_stx_parser_parse_method (&parser, 0,
XP_TEXT("isNil\n^true"));
*/
stdio_t stdio;
parser.input_owner = (void*)&stdio;
parser.input_func = stdio_func;
if (xp_stx_parser_parse_method (&parser, 0,
(void*)XP_TEXT("test.st")) == -1) {
xp_printf (XP_TEXT("parser error\n"));
}
}
xp_stx_parser_close (&parser);

2
ase/test/stx/test.st Normal file
View File

@ -0,0 +1,2 @@
isNil
^true