diff --git a/dlls/vbscript/lex.c b/dlls/vbscript/lex.c index f3dc8ee8004..d481e6af9f2 100644 --- a/dlls/vbscript/lex.c +++ b/dlls/vbscript/lex.c @@ -26,6 +26,31 @@ WINE_DEFAULT_DEBUG_CHANNEL(vbscript); +static inline BOOL is_identifier_char(WCHAR c) +{ + return isalnumW(c) || c == '_'; +} + +static int parse_identifier(parser_ctx_t *ctx, const WCHAR **ret) +{ + const WCHAR *ptr = ctx->ptr++; + WCHAR *str; + int len; + + while(ctx->ptr < ctx->end && is_identifier_char(*ctx->ptr)) + ctx->ptr++; + len = ctx->ptr-ptr; + + str = parser_alloc(ctx, (len+1)*sizeof(WCHAR)); + if(!str) + return 0; + + memcpy(str, ptr, (len+1)*sizeof(WCHAR)); + str[len] = 0; + *ret = str; + return tIdentifier; +} + static int parse_next_token(void *lval, parser_ctx_t *ctx) { WCHAR c; @@ -37,6 +62,9 @@ static int parse_next_token(void *lval, parser_ctx_t *ctx) c = *ctx->ptr; + if(isalphaW(c)) + return parse_identifier(ctx, lval); + switch(c) { case '\n': ctx->ptr++; diff --git a/dlls/vbscript/parse.h b/dlls/vbscript/parse.h index d6dfbbc56a6..fa6424f9891 100644 --- a/dlls/vbscript/parse.h +++ b/dlls/vbscript/parse.h @@ -30,3 +30,4 @@ typedef struct { HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN; int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN; +void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN; diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index e895cfd44ea..0ae6008026d 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -38,13 +38,12 @@ static void parse_complete(parser_ctx_t*); %pure_parser %start Program -%token tEOF - %union { const WCHAR *string; } -%token tNL +%token tEOF tNL +%token tIdentifier %% @@ -62,6 +61,17 @@ static void parse_complete(parser_ctx_t *ctx) ctx->parse_complete = TRUE; } +void *parser_alloc(parser_ctx_t *ctx, size_t size) +{ + void *ret; + + /* FIXME: leaks! */ + ret = heap_alloc(size); + if(!ret) + ctx->hres = E_OUTOFMEMORY; + return ret; +} + HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code) { ctx->code = ctx->ptr = code;