Commit 290f5631 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Added support for HTML comments.

parent 68c1bf50
......@@ -1644,7 +1644,7 @@ static void release_compiler(compile_ctx_t *ctx)
release_vbscode(ctx->code);
}
HRESULT compile_script(script_ctx_t *script, const WCHAR *src, vbscode_t **ret)
HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *delimiter, vbscode_t **ret)
{
function_t *new_func;
function_decl_t *func_decl;
......@@ -1653,7 +1653,7 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, vbscode_t **ret)
vbscode_t *code;
HRESULT hres;
hres = parse_script(&ctx.parser, src);
hres = parse_script(&ctx.parser, src, delimiter);
if(FAILED(hres))
return hres;
......
......@@ -320,6 +320,16 @@ static void skip_spaces(parser_ctx_t *ctx)
ctx->ptr++;
}
static int comment_line(parser_ctx_t *ctx)
{
ctx->ptr = strchrW(ctx->ptr, '\n');
if(ctx->ptr)
ctx->ptr++;
else
ctx->ptr = ctx->end;
return tNL;
}
static int parse_next_token(void *lval, parser_ctx_t *ctx)
{
WCHAR c;
......@@ -347,18 +357,12 @@ static int parse_next_token(void *lval, parser_ctx_t *ctx)
ctx->ptr++;
return tNL;
case '\'':
ctx->ptr = strchrW(ctx->ptr, '\n');
if(ctx->ptr)
ctx->ptr++;
else
ctx->ptr = ctx->end;
return tNL;
return comment_line(ctx);
case ':':
case ')':
case ',':
case '=':
case '+':
case '-':
case '*':
case '/':
case '^':
......@@ -366,6 +370,11 @@ static int parse_next_token(void *lval, parser_ctx_t *ctx)
case '.':
case '_':
return *ctx->ptr++;
case '-':
if(ctx->is_html && ctx->ptr[1] == '-' && ctx->ptr[2] == '>')
return comment_line(ctx);
ctx->ptr++;
return '-';
case '(':
/* NOTE:
* We resolve empty brackets in lexer instead of parser to avoid complex conflicts
......@@ -392,6 +401,9 @@ static int parse_next_token(void *lval, parser_ctx_t *ctx)
case '=':
ctx->ptr++;
return tLTEQ;
case '!':
if(ctx->is_html && ctx->ptr[1] == '-' && ctx->ptr[2] == '-')
return comment_line(ctx);
}
return '<';
case '>':
......
......@@ -253,6 +253,7 @@ typedef struct {
BOOL option_explicit;
BOOL parse_complete;
BOOL is_html;
HRESULT hres;
int last_token;
......@@ -265,7 +266,7 @@ typedef struct {
vbsheap_t heap;
} parser_ctx_t;
HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
HRESULT parse_script(parser_ctx_t*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;
......@@ -919,8 +919,10 @@ void *parser_alloc(parser_ctx_t *ctx, size_t size)
return ret;
}
HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code)
HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code, const WCHAR *delimiter)
{
const WCHAR html_delimiterW[] = {'<','/','s','c','r','i','p','t','>',0};
ctx->code = ctx->ptr = code;
ctx->end = ctx->code + strlenW(ctx->code);
......@@ -934,6 +936,7 @@ HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code)
ctx->stats = ctx->stats_tail = NULL;
ctx->class_decls = NULL;
ctx->option_explicit = FALSE;
ctx->is_html = delimiter && !strcmpiW(delimiter, html_delimiterW);
parser_parse(ctx);
......
......@@ -612,7 +612,7 @@ static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface,
if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED)
return E_UNEXPECTED;
hres = compile_script(This->ctx, pstrCode, &code);
hres = compile_script(This->ctx, pstrCode, pstrDelimiter, &code);
if(FAILED(hres))
return hres;
......@@ -672,7 +672,7 @@ static HRESULT WINAPI VBScriptParseProcedure_ParseProcedureText(IActiveScriptPar
if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED)
return E_UNEXPECTED;
hres = compile_script(This->ctx, pstrCode, &code);
hres = compile_script(This->ctx, pstrCode, pstrDelimiter, &code);
if(FAILED(hres))
return hres;
......
......@@ -326,7 +326,7 @@ struct _vbscode_t {
};
void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN;
HRESULT compile_script(script_ctx_t*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN;
HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN;
HRESULT exec_script(script_ctx_t*,function_t*,IDispatch*,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
void release_dynamic_vars(dynamic_var_t*) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment