2011-09-06 15:18:55 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2014-06-05 11:45:41 +02:00
|
|
|
#include <limits.h>
|
2019-06-25 08:38:01 +02:00
|
|
|
#include <math.h>
|
2011-09-06 15:18:55 +02:00
|
|
|
|
|
|
|
#include "vbscript.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "parser.tab.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
|
|
|
|
|
2011-09-08 14:55:51 +02:00
|
|
|
static const struct {
|
|
|
|
const WCHAR *word;
|
|
|
|
int token;
|
|
|
|
} keywords[] = {
|
2019-10-29 19:01:02 +01:00
|
|
|
{L"and", tAND},
|
|
|
|
{L"byref", tBYREF},
|
|
|
|
{L"byval", tBYVAL},
|
|
|
|
{L"call", tCALL},
|
|
|
|
{L"case", tCASE},
|
|
|
|
{L"class", tCLASS},
|
|
|
|
{L"const", tCONST},
|
|
|
|
{L"default", tDEFAULT},
|
|
|
|
{L"dim", tDIM},
|
|
|
|
{L"do", tDO},
|
|
|
|
{L"each", tEACH},
|
|
|
|
{L"else", tELSE},
|
|
|
|
{L"elseif", tELSEIF},
|
|
|
|
{L"empty", tEMPTY},
|
|
|
|
{L"end", tEND},
|
|
|
|
{L"eqv", tEQV},
|
|
|
|
{L"error", tERROR},
|
|
|
|
{L"exit", tEXIT},
|
|
|
|
{L"explicit", tEXPLICIT},
|
|
|
|
{L"false", tFALSE},
|
|
|
|
{L"for", tFOR},
|
|
|
|
{L"function", tFUNCTION},
|
|
|
|
{L"get", tGET},
|
|
|
|
{L"goto", tGOTO},
|
|
|
|
{L"if", tIF},
|
|
|
|
{L"imp", tIMP},
|
|
|
|
{L"in", tIN},
|
|
|
|
{L"is", tIS},
|
|
|
|
{L"let", tLET},
|
|
|
|
{L"loop", tLOOP},
|
|
|
|
{L"me", tME},
|
|
|
|
{L"mod", tMOD},
|
|
|
|
{L"new", tNEW},
|
|
|
|
{L"next", tNEXT},
|
|
|
|
{L"not", tNOT},
|
|
|
|
{L"nothing", tNOTHING},
|
|
|
|
{L"null", tNULL},
|
|
|
|
{L"on", tON},
|
|
|
|
{L"option", tOPTION},
|
|
|
|
{L"or", tOR},
|
2019-11-01 17:50:57 +01:00
|
|
|
{L"preserve", tPRESERVE},
|
2019-10-29 19:01:02 +01:00
|
|
|
{L"private", tPRIVATE},
|
|
|
|
{L"property", tPROPERTY},
|
|
|
|
{L"public", tPUBLIC},
|
2019-11-01 17:50:57 +01:00
|
|
|
{L"redim", tREDIM},
|
2019-10-29 19:01:02 +01:00
|
|
|
{L"rem", tREM},
|
|
|
|
{L"resume", tRESUME},
|
|
|
|
{L"select", tSELECT},
|
|
|
|
{L"set", tSET},
|
|
|
|
{L"step", tSTEP},
|
|
|
|
{L"stop", tSTOP},
|
|
|
|
{L"sub", tSUB},
|
|
|
|
{L"then", tTHEN},
|
|
|
|
{L"to", tTO},
|
|
|
|
{L"true", tTRUE},
|
|
|
|
{L"until", tUNTIL},
|
|
|
|
{L"wend", tWEND},
|
|
|
|
{L"while", tWHILE},
|
2019-10-29 19:01:14 +01:00
|
|
|
{L"with", tWITH},
|
2019-10-29 19:01:02 +01:00
|
|
|
{L"xor", tXOR}
|
2011-09-08 14:55:51 +02:00
|
|
|
};
|
|
|
|
|
2011-09-07 14:08:07 +02:00
|
|
|
static inline BOOL is_identifier_char(WCHAR c)
|
|
|
|
{
|
2019-06-25 08:38:01 +02:00
|
|
|
return iswalnum(c) || c == '_';
|
2011-09-07 14:08:07 +02:00
|
|
|
}
|
|
|
|
|
2019-02-15 14:06:15 +01:00
|
|
|
static int check_keyword(parser_ctx_t *ctx, const WCHAR *word, const WCHAR **lval)
|
2011-09-08 14:55:51 +02:00
|
|
|
{
|
|
|
|
const WCHAR *p1 = ctx->ptr;
|
|
|
|
const WCHAR *p2 = word;
|
|
|
|
WCHAR c;
|
|
|
|
|
|
|
|
while(p1 < ctx->end && *p2) {
|
2019-06-25 08:38:01 +02:00
|
|
|
c = towlower(*p1);
|
2011-09-08 14:55:51 +02:00
|
|
|
if(c != *p2)
|
|
|
|
return c - *p2;
|
|
|
|
p1++;
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*p2 || (p1 < ctx->end && is_identifier_char(*p1)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
ctx->ptr = p1;
|
2019-02-15 14:06:15 +01:00
|
|
|
*lval = word;
|
2011-09-08 14:55:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-15 14:06:15 +01:00
|
|
|
static int check_keywords(parser_ctx_t *ctx, const WCHAR **lval)
|
2011-09-08 14:55:51 +02:00
|
|
|
{
|
2018-07-18 23:01:34 +02:00
|
|
|
int min = 0, max = ARRAY_SIZE(keywords)-1, r, i;
|
2011-09-08 14:55:51 +02:00
|
|
|
|
|
|
|
while(min <= max) {
|
|
|
|
i = (min+max)/2;
|
|
|
|
|
2019-02-15 14:06:15 +01:00
|
|
|
r = check_keyword(ctx, keywords[i].word, lval);
|
2011-09-08 14:55:51 +02:00
|
|
|
if(!r)
|
|
|
|
return keywords[i].token;
|
|
|
|
|
|
|
|
if(r > 0)
|
|
|
|
min = i+1;
|
|
|
|
else
|
|
|
|
max = i-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-07 14:08:07 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:56:48 +02:00
|
|
|
static int parse_string_literal(parser_ctx_t *ctx, const WCHAR **ret)
|
|
|
|
{
|
|
|
|
const WCHAR *ptr = ++ctx->ptr;
|
|
|
|
WCHAR *rptr;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
while(ctx->ptr < ctx->end) {
|
2019-03-05 00:14:55 +01:00
|
|
|
if(*ctx->ptr == '\n' || *ctx->ptr == '\r') {
|
2011-09-08 14:56:48 +02:00
|
|
|
FIXME("newline inside string literal\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ctx->ptr == '"') {
|
|
|
|
if(ctx->ptr[1] != '"')
|
|
|
|
break;
|
|
|
|
len--;
|
|
|
|
ctx->ptr++;
|
|
|
|
}
|
|
|
|
ctx->ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ctx->ptr == ctx->end) {
|
|
|
|
FIXME("unterminated string literal\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
len += ctx->ptr-ptr;
|
|
|
|
|
|
|
|
*ret = rptr = parser_alloc(ctx, (len+1)*sizeof(WCHAR));
|
|
|
|
if(!rptr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while(ptr < ctx->ptr) {
|
|
|
|
if(*ptr == '"')
|
|
|
|
ptr++;
|
|
|
|
*rptr++ = *ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rptr = 0;
|
|
|
|
ctx->ptr++;
|
|
|
|
return tString;
|
|
|
|
}
|
|
|
|
|
2021-09-14 13:18:41 +02:00
|
|
|
static int parse_date_literal(parser_ctx_t *ctx, DATE *ret)
|
|
|
|
{
|
|
|
|
const WCHAR *ptr = ++ctx->ptr;
|
|
|
|
WCHAR *rptr;
|
|
|
|
int len = 0;
|
|
|
|
HRESULT res;
|
|
|
|
|
|
|
|
while(ctx->ptr < ctx->end) {
|
|
|
|
if(*ctx->ptr == '\n' || *ctx->ptr == '\r') {
|
|
|
|
FIXME("newline inside date literal\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ctx->ptr == '#')
|
|
|
|
break;
|
|
|
|
ctx->ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ctx->ptr == ctx->end) {
|
|
|
|
FIXME("unterminated date literal\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
len += ctx->ptr-ptr;
|
|
|
|
|
|
|
|
rptr = heap_alloc((len+1)*sizeof(WCHAR));
|
|
|
|
if(!rptr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
memcpy( rptr, ptr, len * sizeof(WCHAR));
|
|
|
|
rptr[len] = 0;
|
|
|
|
res = VarDateFromStr(rptr, ctx->lcid, 0, ret);
|
|
|
|
heap_free(rptr);
|
2021-10-19 22:54:34 +02:00
|
|
|
if (FAILED(res)) {
|
2021-09-14 13:18:41 +02:00
|
|
|
FIXME("Invalid date literal\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->ptr++;
|
|
|
|
return tDate;
|
|
|
|
}
|
|
|
|
|
2011-09-12 12:29:43 +02:00
|
|
|
static int parse_numeric_literal(parser_ctx_t *ctx, void **ret)
|
|
|
|
{
|
2014-06-05 11:45:41 +02:00
|
|
|
BOOL use_int = TRUE;
|
2014-05-16 17:22:37 +02:00
|
|
|
LONGLONG d = 0, hlp;
|
|
|
|
int exp = 0;
|
2014-06-05 11:45:41 +02:00
|
|
|
double r;
|
2011-09-12 12:29:43 +02:00
|
|
|
|
|
|
|
if(*ctx->ptr == '0' && !('0' <= ctx->ptr[1] && ctx->ptr[1] <= '9') && ctx->ptr[1] != '.')
|
|
|
|
return *ctx->ptr++;
|
|
|
|
|
2019-11-08 21:28:32 +01:00
|
|
|
while(ctx->ptr < ctx->end && is_digit(*ctx->ptr)) {
|
2014-05-16 17:22:37 +02:00
|
|
|
hlp = d*10 + *(ctx->ptr++) - '0';
|
|
|
|
if(d>MAXLONGLONG/10 || hlp<0) {
|
|
|
|
exp++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
d = hlp;
|
|
|
|
}
|
2019-11-08 21:28:32 +01:00
|
|
|
while(ctx->ptr < ctx->end && is_digit(*ctx->ptr)) {
|
2014-05-16 17:22:37 +02:00
|
|
|
exp++;
|
|
|
|
ctx->ptr++;
|
|
|
|
}
|
2011-09-12 12:29:43 +02:00
|
|
|
|
2014-06-05 11:45:41 +02:00
|
|
|
if(*ctx->ptr == '.') {
|
|
|
|
use_int = FALSE;
|
2014-05-16 17:22:37 +02:00
|
|
|
ctx->ptr++;
|
|
|
|
|
2019-11-08 21:28:32 +01:00
|
|
|
while(ctx->ptr < ctx->end && is_digit(*ctx->ptr)) {
|
2014-05-16 17:22:37 +02:00
|
|
|
hlp = d*10 + *(ctx->ptr++) - '0';
|
|
|
|
if(d>MAXLONGLONG/10 || hlp<0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
d = hlp;
|
|
|
|
exp--;
|
|
|
|
}
|
2019-11-08 21:28:32 +01:00
|
|
|
while(ctx->ptr < ctx->end && is_digit(*ctx->ptr))
|
2014-05-16 17:22:37 +02:00
|
|
|
ctx->ptr++;
|
2011-09-12 12:29:43 +02:00
|
|
|
}
|
|
|
|
|
2014-06-05 11:45:41 +02:00
|
|
|
if(*ctx->ptr == 'e' || *ctx->ptr == 'E') {
|
|
|
|
int e = 0, sign = 1;
|
|
|
|
|
2019-08-26 17:04:32 +02:00
|
|
|
ctx->ptr++;
|
|
|
|
if(*ctx->ptr == '-') {
|
2014-06-05 11:45:41 +02:00
|
|
|
ctx->ptr++;
|
|
|
|
sign = -1;
|
2019-08-26 17:04:32 +02:00
|
|
|
}else if(*ctx->ptr == '+') {
|
|
|
|
ctx->ptr++;
|
2014-06-05 11:45:41 +02:00
|
|
|
}
|
|
|
|
|
2019-11-08 21:28:32 +01:00
|
|
|
if(!is_digit(*ctx->ptr)) {
|
2014-06-05 11:45:41 +02:00
|
|
|
FIXME("Invalid numeric literal\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
use_int = FALSE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
e = e*10 + *(ctx->ptr++) - '0';
|
|
|
|
if(sign == -1 && -e+exp < -(INT_MAX/100)) {
|
|
|
|
/* The literal will be rounded to 0 anyway. */
|
2019-11-08 21:28:32 +01:00
|
|
|
while(is_digit(*ctx->ptr))
|
2014-06-05 11:45:41 +02:00
|
|
|
ctx->ptr++;
|
|
|
|
*(double*)ret = 0;
|
|
|
|
return tDouble;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sign*e + exp > INT_MAX/100) {
|
|
|
|
FIXME("Invalid numeric literal\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2019-11-08 21:28:32 +01:00
|
|
|
} while(is_digit(*ctx->ptr));
|
2014-06-05 11:45:41 +02:00
|
|
|
|
|
|
|
exp += sign*e;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(use_int && (LONG)d == d) {
|
2019-08-22 19:31:41 +02:00
|
|
|
*(LONG*)ret = d;
|
2019-08-22 19:31:49 +02:00
|
|
|
return tInt;
|
2014-06-05 11:45:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r = exp>=0 ? d*pow(10, exp) : d/pow(10, -exp);
|
|
|
|
if(isinf(r)) {
|
|
|
|
FIXME("Invalid numeric literal\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(double*)ret = r;
|
2011-09-12 12:29:43 +02:00
|
|
|
return tDouble;
|
|
|
|
}
|
|
|
|
|
2011-09-12 12:30:34 +02:00
|
|
|
static int hex_to_int(WCHAR c)
|
|
|
|
{
|
|
|
|
if('0' <= c && c <= '9')
|
|
|
|
return c-'0';
|
|
|
|
if('a' <= c && c <= 'f')
|
|
|
|
return c+10-'a';
|
|
|
|
if('A' <= c && c <= 'F')
|
|
|
|
return c+10-'A';
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_hex_literal(parser_ctx_t *ctx, LONG *ret)
|
|
|
|
{
|
|
|
|
const WCHAR *begin = ctx->ptr;
|
2020-01-27 14:25:32 +01:00
|
|
|
unsigned l = 0, d;
|
2011-09-12 12:30:34 +02:00
|
|
|
|
|
|
|
while((d = hex_to_int(*++ctx->ptr)) != -1)
|
|
|
|
l = l*16 + d;
|
|
|
|
|
2020-11-27 17:33:21 +01:00
|
|
|
if(begin + 9 /* max digits+1 */ < ctx->ptr) {
|
2011-09-12 12:30:34 +02:00
|
|
|
FIXME("invalid literal\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-03 19:57:03 +01:00
|
|
|
if(*ctx->ptr == '&') {
|
2011-10-18 12:36:03 +02:00
|
|
|
ctx->ptr++;
|
2020-02-03 19:57:03 +01:00
|
|
|
*ret = l;
|
|
|
|
}else {
|
|
|
|
*ret = l == (UINT16)l ? (INT16)l : l;
|
|
|
|
}
|
2019-08-22 19:31:49 +02:00
|
|
|
return tInt;
|
2011-09-12 12:30:34 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 14:46:46 +02:00
|
|
|
static void skip_spaces(parser_ctx_t *ctx)
|
|
|
|
{
|
2018-06-17 02:05:30 +02:00
|
|
|
while(*ctx->ptr == ' ' || *ctx->ptr == '\t')
|
2011-09-09 14:46:46 +02:00
|
|
|
ctx->ptr++;
|
|
|
|
}
|
|
|
|
|
2012-10-18 11:49:17 +02:00
|
|
|
static int comment_line(parser_ctx_t *ctx)
|
|
|
|
{
|
2020-11-15 23:11:20 +01:00
|
|
|
ctx->ptr = wcspbrk(ctx->ptr, L"\n\r");
|
2012-10-18 11:49:17 +02:00
|
|
|
if(ctx->ptr)
|
|
|
|
ctx->ptr++;
|
|
|
|
else
|
|
|
|
ctx->ptr = ctx->end;
|
|
|
|
return tNL;
|
|
|
|
}
|
|
|
|
|
2020-01-22 23:27:14 +01:00
|
|
|
static int parse_next_token(void *lval, unsigned *loc, parser_ctx_t *ctx)
|
2011-09-06 15:18:55 +02:00
|
|
|
{
|
|
|
|
WCHAR c;
|
|
|
|
|
2011-09-09 14:46:46 +02:00
|
|
|
skip_spaces(ctx);
|
2020-01-22 23:27:14 +01:00
|
|
|
*loc = ctx->ptr - ctx->code;
|
2011-09-06 15:18:55 +02:00
|
|
|
if(ctx->ptr == ctx->end)
|
2020-01-22 23:27:35 +01:00
|
|
|
return ctx->last_token == tNL ? 0 : tNL;
|
2011-09-06 15:18:55 +02:00
|
|
|
|
|
|
|
c = *ctx->ptr;
|
2011-09-07 14:07:54 +02:00
|
|
|
|
2011-09-12 12:29:43 +02:00
|
|
|
if('0' <= c && c <= '9')
|
|
|
|
return parse_numeric_literal(ctx, lval);
|
|
|
|
|
2019-06-25 08:38:01 +02:00
|
|
|
if(iswalpha(c)) {
|
2019-11-12 14:26:04 +01:00
|
|
|
int ret = 0;
|
|
|
|
if(ctx->last_token != '.' && ctx->last_token != tDOT)
|
|
|
|
ret = check_keywords(ctx, lval);
|
2011-09-08 14:55:51 +02:00
|
|
|
if(!ret)
|
|
|
|
return parse_identifier(ctx, lval);
|
2011-09-20 14:59:07 +02:00
|
|
|
if(ret != tREM)
|
|
|
|
return ret;
|
|
|
|
c = '\'';
|
2011-09-08 14:55:51 +02:00
|
|
|
}
|
2011-09-07 14:08:07 +02:00
|
|
|
|
2011-09-07 14:07:54 +02:00
|
|
|
switch(c) {
|
|
|
|
case '\n':
|
2018-06-17 02:05:30 +02:00
|
|
|
case '\r':
|
2011-09-07 14:07:54 +02:00
|
|
|
ctx->ptr++;
|
|
|
|
return tNL;
|
|
|
|
case '\'':
|
2012-10-18 11:49:17 +02:00
|
|
|
return comment_line(ctx);
|
2011-09-20 14:58:53 +02:00
|
|
|
case ':':
|
2011-09-08 14:55:14 +02:00
|
|
|
case ')':
|
|
|
|
case ',':
|
|
|
|
case '=':
|
|
|
|
case '+':
|
|
|
|
case '*':
|
|
|
|
case '/':
|
|
|
|
case '^':
|
|
|
|
case '\\':
|
2011-10-17 14:32:13 +02:00
|
|
|
case '_':
|
2011-09-08 14:55:14 +02:00
|
|
|
return *ctx->ptr++;
|
2019-10-29 19:01:14 +01:00
|
|
|
case '.':
|
|
|
|
/*
|
|
|
|
* We need to distinguish between '.' used as part of a member expression and
|
|
|
|
* a beginning of a dot expression (a member expression accessing with statement
|
2020-09-15 13:33:38 +02:00
|
|
|
* expression) and a floating point number like ".2" .
|
2019-10-29 19:01:14 +01:00
|
|
|
*/
|
|
|
|
c = ctx->ptr > ctx->code ? ctx->ptr[-1] : '\n';
|
2020-09-15 13:33:38 +02:00
|
|
|
if (is_identifier_char(c) || c == ')') {
|
|
|
|
ctx->ptr++;
|
|
|
|
return '.';
|
|
|
|
}
|
|
|
|
c = ctx->ptr[1];
|
|
|
|
if('0' <= c && c <= '9')
|
|
|
|
return parse_numeric_literal(ctx, lval);
|
2019-10-29 19:01:14 +01:00
|
|
|
ctx->ptr++;
|
2020-09-15 13:33:38 +02:00
|
|
|
return tDOT;
|
2012-10-18 11:49:17 +02:00
|
|
|
case '-':
|
|
|
|
if(ctx->is_html && ctx->ptr[1] == '-' && ctx->ptr[2] == '>')
|
|
|
|
return comment_line(ctx);
|
|
|
|
ctx->ptr++;
|
|
|
|
return '-';
|
2011-09-09 14:46:46 +02:00
|
|
|
case '(':
|
|
|
|
/* NOTE:
|
|
|
|
* We resolve empty brackets in lexer instead of parser to avoid complex conflicts
|
|
|
|
* in call statement special case |f()| without 'call' keyword
|
|
|
|
*/
|
|
|
|
ctx->ptr++;
|
|
|
|
skip_spaces(ctx);
|
|
|
|
if(*ctx->ptr == ')') {
|
|
|
|
ctx->ptr++;
|
|
|
|
return tEMPTYBRACKETS;
|
|
|
|
}
|
2019-11-05 14:08:35 +01:00
|
|
|
/*
|
|
|
|
* Parser can't predict if bracket is part of argument expression or an argument
|
|
|
|
* in call expression. We predict it here instead.
|
|
|
|
*/
|
|
|
|
if(ctx->last_token == tIdentifier || ctx->last_token == ')')
|
|
|
|
return '(';
|
|
|
|
return tEXPRLBRACKET;
|
2011-09-08 14:56:48 +02:00
|
|
|
case '"':
|
|
|
|
return parse_string_literal(ctx, lval);
|
2021-09-14 13:18:41 +02:00
|
|
|
case '#':
|
|
|
|
return parse_date_literal(ctx, lval);
|
2011-09-12 12:30:34 +02:00
|
|
|
case '&':
|
|
|
|
if(*++ctx->ptr == 'h' || *ctx->ptr == 'H')
|
|
|
|
return parse_hex_literal(ctx, lval);
|
|
|
|
return '&';
|
2011-09-12 12:28:55 +02:00
|
|
|
case '<':
|
|
|
|
switch(*++ctx->ptr) {
|
|
|
|
case '>':
|
|
|
|
ctx->ptr++;
|
|
|
|
return tNEQ;
|
|
|
|
case '=':
|
|
|
|
ctx->ptr++;
|
|
|
|
return tLTEQ;
|
2012-10-18 11:49:17 +02:00
|
|
|
case '!':
|
|
|
|
if(ctx->is_html && ctx->ptr[1] == '-' && ctx->ptr[2] == '-')
|
|
|
|
return comment_line(ctx);
|
2011-09-12 12:28:55 +02:00
|
|
|
}
|
|
|
|
return '<';
|
|
|
|
case '>':
|
|
|
|
if(*++ctx->ptr == '=') {
|
|
|
|
ctx->ptr++;
|
|
|
|
return tGTEQ;
|
|
|
|
}
|
|
|
|
return '>';
|
2011-09-07 14:07:54 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled char %c in %s\n", *ctx->ptr, debugstr_w(ctx->ptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-09-06 15:18:55 +02:00
|
|
|
}
|
|
|
|
|
2020-01-22 23:27:14 +01:00
|
|
|
int parser_lex(void *lval, unsigned *loc, parser_ctx_t *ctx)
|
2011-09-06 15:18:55 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2019-09-17 14:54:31 +02:00
|
|
|
if (ctx->last_token == tEXPRESSION)
|
|
|
|
{
|
|
|
|
ctx->last_token = tNL;
|
|
|
|
return tEXPRESSION;
|
|
|
|
}
|
|
|
|
|
2011-09-06 15:18:55 +02:00
|
|
|
while(1) {
|
2020-01-22 23:27:14 +01:00
|
|
|
ret = parse_next_token(lval, loc, ctx);
|
2011-10-17 14:32:13 +02:00
|
|
|
if(ret == '_') {
|
|
|
|
skip_spaces(ctx);
|
2019-03-05 00:14:55 +01:00
|
|
|
if(*ctx->ptr != '\n' && *ctx->ptr != '\r') {
|
2011-10-17 14:32:13 +02:00
|
|
|
FIXME("'_' not followed by newline\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2019-03-05 00:14:55 +01:00
|
|
|
if(*ctx->ptr == '\r')
|
|
|
|
ctx->ptr++;
|
|
|
|
if(*ctx->ptr == '\n')
|
|
|
|
ctx->ptr++;
|
2011-10-17 14:32:13 +02:00
|
|
|
continue;
|
|
|
|
}
|
2011-09-06 15:18:55 +02:00
|
|
|
if(ret != tNL || ctx->last_token != tNL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ctx->last_nl = ctx->ptr-ctx->code;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ctx->last_token = ret);
|
|
|
|
}
|