*** empty log message ***
This commit is contained in:
154
ase/stx/parser.c
154
ase/stx/parser.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parser.c,v 1.12 2005-06-05 05:26:24 bacon Exp $
|
||||
* $Id: parser.c,v 1.13 2005-06-05 16:44:05 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/stx/parser.h>
|
||||
@ -7,6 +7,9 @@
|
||||
#include <xp/stx/misc.h>
|
||||
|
||||
static int __get_token (xp_stx_parser_t* parser);
|
||||
static int __get_ident (xp_stx_parser_t* parser);
|
||||
static int __get_charlit (xp_stx_parser_t* parser);
|
||||
static int __get_strlit (xp_stx_parser_t* parser);
|
||||
static int __skip_spaces (xp_stx_parser_t* parser);
|
||||
static int __skip_comment (xp_stx_parser_t* parser);
|
||||
static int __get_char (xp_stx_parser_t* parser);
|
||||
@ -50,12 +53,14 @@ void xp_stx_parser_close (xp_stx_parser_t* parser)
|
||||
do { if (__get_char(parser) == -1) return -1; } while (0)
|
||||
#define UNGET_CHAR(parser,c) \
|
||||
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)
|
||||
|
||||
|
||||
int xp_stx_parser_parse_method (
|
||||
xp_stx_parser_t* parser, xp_stx_word_t method_class, void* input)
|
||||
{
|
||||
if (parser->input == XP_NULL ||
|
||||
parser->input_reset == XP_NULL ||
|
||||
if (parser->input_reset == XP_NULL ||
|
||||
parser->input_consume == XP_NULL) {
|
||||
parser->error_code = XP_STX_PARSER_ERROR_INVALID;
|
||||
return -1;
|
||||
@ -63,6 +68,9 @@ int xp_stx_parser_parse_method (
|
||||
|
||||
RESET_INPUT (parser, input);
|
||||
GET_CHAR (parser);
|
||||
|
||||
GET_TOKEN (parser);
|
||||
xp_printf (XP_TEXT("%d, [%s]\n"), parser->token.type, parser->token.buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -81,12 +89,18 @@ static int __get_token (xp_stx_parser_t* parser)
|
||||
} while (1);
|
||||
|
||||
c = parser->curc;
|
||||
xp_stx_token_clear (&parser->token);
|
||||
|
||||
if (xp_stx_isalpha(c)) {
|
||||
if (__get_ident(parser) == -1) return -1;
|
||||
}
|
||||
else if (xp_stx_isdigit(c)) {
|
||||
}
|
||||
else if (c == XP_STX_CHAR('$')) {
|
||||
if (__get_charlit(parser) == -1) return -1;
|
||||
}
|
||||
else if (c == XP_STX_CHAR('\'')) {
|
||||
if (__get_strlit(parser) == -1) return -1;
|
||||
}
|
||||
else {
|
||||
parser->error_code = XP_STX_PARSER_ERROR_CHAR;
|
||||
@ -96,6 +110,91 @@ static int __get_token (xp_stx_parser_t* parser)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __get_ident (xp_stx_parser_t* parser)
|
||||
{
|
||||
/*
|
||||
* identifier ::= letter (letter | digit)*
|
||||
* keyword ::= identifier ':'
|
||||
*/
|
||||
|
||||
xp_cint_t c = parser->curc;
|
||||
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;
|
||||
}
|
||||
GET_CHAR (parser);
|
||||
c = parser->curc;
|
||||
} while (xp_stx_isalnum(c));
|
||||
|
||||
if (c == XP_STX_CHAR(':')) {
|
||||
parser->token.type = XP_STX_TOKEN_KEYWORD;
|
||||
GET_CHAR (parser);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __get_charlit (xp_stx_parser_t* parser)
|
||||
{
|
||||
/*
|
||||
* character_literal ::= '$' character
|
||||
* character ::= "Any character in the implementation-defined character set"
|
||||
*/
|
||||
|
||||
xp_cint_t c = parser->curc;
|
||||
if (c == XP_STX_CHAR_EOF) {
|
||||
parser->error_code = XP_STX_PARSER_ERROR_CHARLIT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
GET_CHAR (parser);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __get_strlit (xp_stx_parser_t* parser)
|
||||
{
|
||||
/*
|
||||
* string_literal ::= stringDelimiter stringBody stringDelimiter
|
||||
* stringBody ::= (nonStringDelimiter | (stringDelimiter stringDelimiter)*)
|
||||
* stringDelimiter ::= ''' "a single quote"
|
||||
*/
|
||||
|
||||
/* TODO: C-like string */
|
||||
|
||||
xp_cint_t c = parser->curc;
|
||||
parser->token.type = XP_STX_TOKEN_STRLIT;
|
||||
|
||||
do {
|
||||
do {
|
||||
if (xp_stx_token_addc (&parser->token, c) == -1) {
|
||||
parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
GET_CHAR (parser);
|
||||
c = parser->curc;
|
||||
|
||||
if (c == XP_STX_CHAR_EOF) {
|
||||
parser->error_code = XP_STX_PARSER_ERROR_STRLIT;
|
||||
return -1;
|
||||
}
|
||||
} while (c != XP_STX_CHAR('\''));
|
||||
|
||||
GET_CHAR (parser);
|
||||
c = parser->curc;
|
||||
} while (c == XP_STX_CHAR('\''));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __skip_spaces (xp_stx_parser_t* parser)
|
||||
{
|
||||
while (xp_stx_isspace(parser->curc)) GET_CHAR (parser);
|
||||
@ -112,11 +211,17 @@ static int __skip_comment (xp_stx_parser_t* parser)
|
||||
static int __get_char (xp_stx_parser_t* parser)
|
||||
{
|
||||
xp_cint_t c;
|
||||
if (parser->input_consume (parser, &c) == -1) {
|
||||
parser->error_code = XP_STX_PARSER_ERROR_INPUT;
|
||||
return -1;
|
||||
|
||||
if (parser->ungotc_count > 0) {
|
||||
parser->curc = parser->ungotc[parser->ungotc_count--];
|
||||
}
|
||||
else {
|
||||
if (parser->input_consume (parser, &c) == -1) {
|
||||
parser->error_code = XP_STX_PARSER_ERROR_INPUT;
|
||||
return -1;
|
||||
}
|
||||
parser->curc = c;
|
||||
}
|
||||
parser->curc = c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -138,38 +243,3 @@ static int __reset_input (xp_stx_parser_t* parser, void* input)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
static int __get_token (xp_stx_parser_t* parser)
|
||||
{
|
||||
xp_cint_t c = parser->curc;
|
||||
|
||||
__skip_spaces (parser);
|
||||
__skip_comment (parser);
|
||||
|
||||
switch (c) {
|
||||
case
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int __get_char (xp_stx_parser_t* parser)
|
||||
{
|
||||
xp_cint_t c = parser->curp;
|
||||
|
||||
if (c == XP_STX_CHAR('\0')) {
|
||||
parser->curc = XP_EOF_CHAR;
|
||||
}
|
||||
else {
|
||||
parser->curc = c;
|
||||
parser->curp++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __skip_spaces (xp_stx_parser_t* parser)
|
||||
{
|
||||
while (xp_stx_isspace(parser->curc)) __get_char
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user