Jacek Caban : vbscript: Added support for HTML comments.

Alexandre Julliard julliard at winehq.org
Thu Oct 18 14:33:12 CDT 2012


Module: wine
Branch: master
Commit: 290f5631993ddd77df7be1b836f0948d6929d39f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=290f5631993ddd77df7be1b836f0948d6929d39f

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Oct 18 11:49:17 2012 +0200

vbscript: Added support for HTML comments.

---

 dlls/vbscript/compile.c  |    4 ++--
 dlls/vbscript/lex.c      |   26 +++++++++++++++++++-------
 dlls/vbscript/parse.h    |    3 ++-
 dlls/vbscript/parser.y   |    5 ++++-
 dlls/vbscript/vbscript.c |    4 ++--
 dlls/vbscript/vbscript.h |    2 +-
 6 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c
index 327d97b..58afdf4 100644
--- a/dlls/vbscript/compile.c
+++ b/dlls/vbscript/compile.c
@@ -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;
 
diff --git a/dlls/vbscript/lex.c b/dlls/vbscript/lex.c
index 8e971e2..65d2334 100644
--- a/dlls/vbscript/lex.c
+++ b/dlls/vbscript/lex.c
@@ -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 '>':
diff --git a/dlls/vbscript/parse.h b/dlls/vbscript/parse.h
index df8f9b5..74e0a8a 100644
--- a/dlls/vbscript/parse.h
+++ b/dlls/vbscript/parse.h
@@ -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;
diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y
index 3f86b04..8a2a9e3 100644
--- a/dlls/vbscript/parser.y
+++ b/dlls/vbscript/parser.y
@@ -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);
 
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c
index 05132a6..1195f85 100644
--- a/dlls/vbscript/vbscript.c
+++ b/dlls/vbscript/vbscript.c
@@ -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;
 
diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h
index 41982da..2ce93b6 100644
--- a/dlls/vbscript/vbscript.h
+++ b/dlls/vbscript/vbscript.h
@@ -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;
 




More information about the wine-cvs mailing list