vbscript: Added identifiers support to lexer.

This commit is contained in:
Jacek Caban 2011-09-07 14:08:07 +02:00 committed by Alexandre Julliard
parent 9f8492692c
commit 91cc7bd719
3 changed files with 42 additions and 3 deletions

View file

@ -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++;

View file

@ -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;

View file

@ -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 <string> 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;