Browse Source

[PATCH 056/188] fix comments scanning

From 4933bad2fb89f856c5cfc5d60378e619c92a5413 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Sun, 24 Nov 2019 20:18:09 -0500

git-svn-id: branches/wasm@46052 -
nickysn 5 years ago
parent
commit
8b1d615a77
2 changed files with 6 additions and 8 deletions
  1. 2 1
      utils/wasmbin/parseutils.pas
  2. 4 7
      utils/wasmbin/watscanner.pas

+ 2 - 1
utils/wasmbin/parseutils.pas

@@ -222,7 +222,8 @@ begin
     if isSubStrMatch(s, index, substr) then begin
     if isSubStrMatch(s, index, substr) then begin
       inc(index, length(substr));
       inc(index, length(substr));
       Break;
       Break;
-    end;
+    end else
+      inc(index);
   end;
   end;
   Result:=Copy(s, i, index-i);
   Result:=Copy(s, i, index-i);
 end;
 end;

+ 4 - 7
utils/wasmbin/watscanner.pas

@@ -192,13 +192,12 @@ begin
     Result := idx<=length(buf);
     Result := idx<=length(buf);
     if not Result then Exit;
     if not Result then Exit;
     ofs:=idx;
     ofs:=idx;
-    has2chars := idx<length(buf);
-    if has2chars then begin
-      if (buf[idx]=';') and (buf[idx+1]=';') then begin
+    if (idx<length(buf)) and (buf[idx] in [';','(']) and (buf[idx+1]=';') then begin
+      if (buf[idx]=';') then begin
         // comment until the end of the line
         // comment until the end of the line
         cmt := ScanTo(buf, idx, EoLnChars);
         cmt := ScanTo(buf, idx, EoLnChars);
         ScanWhile(buf, idx, EoLnChars);
         ScanWhile(buf, idx, EoLnChars);
-      end else if (buf[idx]='(') and (buf[idx+1]=';') then
+      end else
         // comment until the ;)
         // comment until the ;)
         cmt := ScanToSubstr(buf, idx, ';)');
         cmt := ScanToSubstr(buf, idx, ';)');
 
 
@@ -207,9 +206,7 @@ begin
         done:=true;
         done:=true;
       end else
       end else
         DoComment(cmt);
         DoComment(cmt);
-    end;
-
-    if not done then begin
+    end else begin
       done:=true;
       done:=true;
       if buf[idx] = '(' then begin
       if buf[idx] = '(' then begin
         token:=weOpenBrace;
         token:=weOpenBrace;