From 54c381b87f586e5ecd5fa8c1cdbf3a5efbd55e12 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 6 Jun 2005 16:04:18 +0000 Subject: [PATCH] *** empty log message *** --- ase/lsp/read.c | 6 +++--- ase/stx/parser.c | 41 ++++++++++++++++++++++++++--------------- ase/stx/token.h | 5 +++-- ase/test/stx/parser.c | 5 +++-- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/ase/lsp/read.c b/ase/lsp/read.c index 97d16846..30b8ca03 100644 --- a/ase/lsp/read.c +++ b/ase/lsp/read.c @@ -1,9 +1,9 @@ /* - * $Id: read.c,v 1.9 2005-05-30 07:15:35 bacon Exp $ + * $Id: read.c,v 1.10 2005-06-06 16:04:18 bacon Exp $ */ -#include -#include +#include +#include #include #include diff --git a/ase/stx/parser.c b/ase/stx/parser.c index 79d4ecc4..82455d61 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.16 2005-06-06 15:46:48 bacon Exp $ + * $Id: parser.c,v 1.17 2005-06-06 16:01:49 bacon Exp $ */ #include @@ -58,6 +58,13 @@ void xp_stx_parser_close (xp_stx_parser_t* parser) do { if (__unget_char(parser,c) == -1) return -1; } while (0) #define GET_TOKEN(parser) \ do { if (__get_token(parser) == -1) return -1; } while (0) +#define ADD_TOKEN_CHAR(parser,c) \ + do { \ + if (xp_stx_token_addc (&(parser)->token, c) == -1) { \ + (parser)->error_code = XP_STX_PARSER_ERROR_MEMORY; \ + return -1; \ + } \ + } while (0) int xp_stx_parser_parse_method ( xp_stx_parser_t* parser, xp_stx_word_t method_class, void* input) @@ -88,6 +95,11 @@ static int __parse_method ( static int __parse_message_pattern (xp_stx_parser_t* parser) { + while (parser->token.type != XP_STX_TOKEN_END) { + xp_printf (XP_TEXT("token: [%s] %d\n"), + parser->token.buffer, parser->token.type); + GET_TOKEN (parser); + } return 0; } @@ -107,7 +119,11 @@ static int __get_token (xp_stx_parser_t* parser) c = parser->curc; xp_stx_token_clear (&parser->token); - if (xp_stx_isalpha(c)) { +xp_printf (XP_TEXT("xxxxxxxxxx[%d][%d]xxx\n"), c, XP_STX_CHAR_EOF); + if (c == XP_STX_CHAR_EOF) { + parser->token.type = XP_STX_TOKEN_END; + } + else if (xp_stx_isalpha(c)) { if (__get_ident(parser) == -1) return -1; } else if (xp_stx_isdigit(c)) { @@ -118,6 +134,11 @@ static int __get_token (xp_stx_parser_t* parser) else if (c == XP_STX_CHAR('\'')) { if (__get_strlit(parser) == -1) return -1; } + else if (c == XP_STX_CHAR('^')) { + parser->token.type = XP_STX_TOKEN_RETURN; + ADD_TOKEN_CHAR(parser, c); + GET_CHAR (parser); + } else { parser->error_code = XP_STX_PARSER_ERROR_CHAR; return -1; @@ -137,10 +158,7 @@ static int __get_ident (xp_stx_parser_t* parser) parser->token.type = XP_STX_TOKEN_IDENT; do { - if (xp_stx_token_addc (&parser->token, c) == -1) { - parser->error_code = XP_STX_PARSER_ERROR_MEMORY; - return -1; - } + ADD_TOKEN_CHAR(parser, c); GET_CHAR (parser); c = parser->curc; } while (xp_stx_isalnum(c)); @@ -167,11 +185,7 @@ static int __get_charlit (xp_stx_parser_t* parser) } parser->token.type = XP_STX_TOKEN_CHARLIT; - if (xp_stx_token_addc (&parser->token, c) == -1) { - parser->error_code = XP_STX_PARSER_ERROR_MEMORY; - return -1; - } - + ADD_TOKEN_CHAR(parser, c); GET_CHAR (parser); return 0; } @@ -191,10 +205,7 @@ static int __get_strlit (xp_stx_parser_t* parser) do { do { - if (xp_stx_token_addc (&parser->token, c) == -1) { - parser->error_code = XP_STX_PARSER_ERROR_MEMORY; - return -1; - } + ADD_TOKEN_CHAR (parser, c); GET_CHAR (parser); c = parser->curc; diff --git a/ase/stx/token.h b/ase/stx/token.h index 0a0f75ca..580f45a3 100644 --- a/ase/stx/token.h +++ b/ase/stx/token.h @@ -1,5 +1,5 @@ /* - * $Id: token.h,v 1.4 2005-06-05 16:44:05 bacon Exp $ + * $Id: token.h,v 1.5 2005-06-06 16:01:49 bacon Exp $ */ #ifndef _XP_STX_TOKEN_H_ @@ -13,7 +13,8 @@ enum XP_STX_TOKEN_CHARLIT, XP_STX_TOKEN_STRLIT, XP_STX_TOKEN_IDENT, - XP_STX_TOKEN_KEYWORD + XP_STX_TOKEN_KEYWORD, + XP_STX_TOKEN_RETURN }; struct xp_stx_token_t diff --git a/ase/test/stx/parser.c b/ase/test/stx/parser.c index 64c710cf..6171ac1d 100644 --- a/ase/test/stx/parser.c +++ b/ase/test/stx/parser.c @@ -75,8 +75,9 @@ int stdio_func (int cmd, void* owner, void* arg) 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) { + xp_cint_t t = (xp_cint_t)xp_fgetc (p->stdio); +xp_printf (XP_TEXT("*c -> %d %d %d\n"), t, XP_CHAR_EOF, EOF); + if (t == XP_CHAR_EOF) { if (xp_ferror (p->stdio)) return -1; *c = XP_STX_CHAR_EOF; }