Commit 84ef7ece authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

jscript: Added html comments handling.

parent 754b5cf2
......@@ -55,6 +55,7 @@ typedef struct _parser_ctx_t {
script_ctx_t *script;
source_elements_t *source;
BOOL nl;
BOOL is_html;
HRESULT hres;
jsheap_t heap;
......@@ -65,7 +66,7 @@ typedef struct _parser_ctx_t {
struct _parser_ctx_t *next;
} parser_ctx_t;
HRESULT script_parse(script_ctx_t*,const WCHAR*,parser_ctx_t**);
HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,parser_ctx_t**);
void parser_release(parser_ctx_t*);
int parser_lex(void*,parser_ctx_t*);
......
......@@ -264,7 +264,7 @@ static HRESULT JSGlobal_eval(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
}
TRACE("parsing %s\n", debugstr_w(V_BSTR(arg)));
hres = script_parse(dispex->ctx, V_BSTR(arg), &parser_ctx);
hres = script_parse(dispex->ctx, V_BSTR(arg), NULL, &parser_ctx);
if(FAILED(hres)) {
WARN("parse (%s) failed: %08x\n", debugstr_w(V_BSTR(arg)), hres);
return hres;
......
......@@ -596,7 +596,7 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
return E_UNEXPECTED;
hres = script_parse(This->ctx, pstrCode, &parser_ctx);
hres = script_parse(This->ctx, pstrCode, pstrDelimiter, &parser_ctx);
if(FAILED(hres))
return hres;
......@@ -662,7 +662,7 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars
if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
return E_UNEXPECTED;
hres = script_parse(This->ctx, pstrCode, &parser_ctx);
hres = script_parse(This->ctx, pstrCode, pstrDelimiter, &parser_ctx);
if(FAILED(hres)) {
WARN("Parse failed %08x\n", hres);
return hres;
......
......@@ -174,6 +174,20 @@ static void skip_spaces(parser_ctx_t *ctx)
}
}
static BOOL skip_html_comment(parser_ctx_t *ctx)
{
const WCHAR html_commentW[] = {'<','!','-','-',0};
if(!ctx->is_html || ctx->ptr+3 >= ctx->end ||
memcmp(ctx->ptr, html_commentW, sizeof(WCHAR)*4))
return FALSE;
ctx->nl = TRUE;
while(ctx->ptr < ctx->end && !is_endline(*ctx->ptr++));
return TRUE;
}
static BOOL skip_comment(parser_ctx_t *ctx)
{
if(ctx->ptr+1 >= ctx->end || *ctx->ptr != '/')
......@@ -466,13 +480,13 @@ int parser_lex(void *lval, parser_ctx_t *ctx)
{
int ret;
ctx->nl = FALSE;
ctx->nl = ctx->ptr == ctx->begin;
do {
skip_spaces(ctx);
if(ctx->ptr == ctx->end)
return 0;
}while(skip_comment(ctx));
}while(skip_comment(ctx) || skip_html_comment(ctx));
if(isalphaW(*ctx->ptr)) {
ret = check_keywords(ctx, lval);
......@@ -585,8 +599,12 @@ int parser_lex(void *lval, parser_ctx_t *ctx)
ctx->ptr++;
if(ctx->ptr < ctx->end) {
switch(*ctx->ptr) {
case '-': /* -- */
case '-': /* -- or --> */
ctx->ptr++;
if(ctx->is_html && ctx->nl && ctx->ptr < ctx->end && *ctx->ptr == '>') {
ctx->ptr++;
return tHTMLCOMMENT;
}
return tDEC;
case '=': /* -= */
ctx->ptr++;
......
......@@ -170,7 +170,7 @@ static source_elements_t *source_elements_add_statement(source_elements_t*,state
/* keywords */
%token kBREAK kCASE kCATCH kCONTINUE kDEFAULT kDELETE kDO kELSE kIF kFINALLY kFOR kIN
%token kINSTANCEOF kNEW kNULL kUNDEFINED kRETURN kSWITCH kTHIS kTHROW kTRUE kFALSE kTRY kTYPEOF kVAR kVOID kWHILE kWITH
%token tANDAND tOROR tINC tDEC
%token tANDAND tOROR tINC tDEC tHTMLCOMMENT
%token <srcptr> kFUNCTION '}'
......@@ -251,7 +251,12 @@ static source_elements_t *source_elements_add_statement(source_elements_t*,state
/* ECMA-262 3rd Edition 14 */
Program
: SourceElements { program_parsed(ctx, $1); }
: SourceElements HtmlComment
{ program_parsed(ctx, $1); }
HtmlComment
: tHTMLCOMMENT {}
| /* empty */ {}
/* ECMA-262 3rd Edition 14 */
SourceElements
......@@ -1549,18 +1554,22 @@ void parser_release(parser_ctx_t *ctx)
heap_free(ctx);
}
HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, parser_ctx_t **ret)
HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimiter,
parser_ctx_t **ret)
{
parser_ctx_t *parser_ctx;
jsheap_t *mark;
HRESULT hres;
const WCHAR html_tagW[] = {'<','/','s','c','r','i','p','t','>',0};
parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t));
if(!parser_ctx)
return E_OUTOFMEMORY;
parser_ctx->ref = 1;
parser_ctx->hres = E_FAIL;
parser_ctx->is_html = delimiter && !strcmpiW(delimiter, html_tagW);
parser_ctx->begin = parser_ctx->ptr = code;
parser_ctx->end = code + strlenW(code);
......
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