2 * Copyright 2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "parser.tab.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
29 static inline BOOL is_identifier_char(WCHAR c)
31 return isalnumW(c) || c == '_';
34 static int parse_identifier(parser_ctx_t *ctx, const WCHAR **ret)
36 const WCHAR *ptr = ctx->ptr++;
40 while(ctx->ptr < ctx->end && is_identifier_char(*ctx->ptr))
44 str = parser_alloc(ctx, (len+1)*sizeof(WCHAR));
48 memcpy(str, ptr, (len+1)*sizeof(WCHAR));
54 static int parse_next_token(void *lval, parser_ctx_t *ctx)
58 while(*ctx->ptr == ' ' || *ctx->ptr == '\t' || *ctx->ptr == '\r')
60 if(ctx->ptr == ctx->end)
61 return ctx->last_token == tNL ? tEOF : tNL;
66 return parse_identifier(ctx, lval);
73 ctx->ptr = strchrW(ctx->ptr, '\n');
80 FIXME("Unhandled char %c in %s\n", *ctx->ptr, debugstr_w(ctx->ptr));
86 int parser_lex(void *lval, parser_ctx_t *ctx)
91 ret = parse_next_token(lval, ctx);
92 if(ret != tNL || ctx->last_token != tNL)
95 ctx->last_nl = ctx->ptr-ctx->code;
98 return (ctx->last_token = ret);