Browse Source

[PATCH 128/188] adding number format support

From 7e195a3ab44683fb375c7a960b6e486619a077ab Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Tue, 24 Mar 2020 14:50:10 -0400

git-svn-id: branches/wasm@46124 -
nickysn 5 years ago
parent
commit
1a34ca2ea0
2 changed files with 40 additions and 6 deletions
  1. 20 5
      utils/wasmbin/parseutils.pas
  2. 20 1
      utils/wasmbin/watscanner.pas

+ 20 - 5
utils/wasmbin/parseutils.pas

@@ -45,7 +45,11 @@ procedure ParseCSSValues(const s: String; css: TStrings);
 procedure GetCssAbsBoundsRect(Css: TStrings; var r: TRect);
 procedure GetCssAbsBoundsRect(Css: TStrings; var r: TRect);
 function CssValInt(const s: String; Def: integer): Integer;
 function CssValInt(const s: String; Def: integer): Integer;
 
 
-function ScanNumberC(const buf: string; var idx: Integer; var numberText: string): Boolean;
+type
+  TCNumberFormat = (nfError, nfInteger, nfHex, nfFloat);
+
+function ScanNumberC(const buf: string; var idx: Integer;
+  var numberText: string): TCNumberFormat;
 
 
 implementation
 implementation
 
 
@@ -233,11 +237,13 @@ begin
   Result:=Copy(s, i, index-i);
   Result:=Copy(s, i, index-i);
 end;
 end;
 
 
-function ScanNumberC(const buf: string; var idx: Integer; var numberText: string): Boolean;
+function ScanNumberC(const buf: string; var idx: Integer; var numberText: string): TCNumberFormat;
 var
 var
   ch  : char;
   ch  : char;
+  sec : string;
 begin
 begin
-  Result := false;
+  Result := nfError;
+
   if buf[idx] in SignChars then begin
   if buf[idx] in SignChars then begin
     ch:=buf[idx];
     ch:=buf[idx];
     inc(idx);
     inc(idx);
@@ -247,14 +253,23 @@ begin
   if (idx<length(buf)) and (buf[idx]='0') and (buf[idx+1]='x') then begin
   if (idx<length(buf)) and (buf[idx]='0') and (buf[idx+1]='x') then begin
     inc(idx,2);
     inc(idx,2);
     numberText:='0x'+ScanWhile(buf, idx, HexChars);
     numberText:='0x'+ScanWhile(buf, idx, HexChars);
-  end else
+    Result := nfHex;
+  end else begin
     numberText:=ScanWhile(buf, idx, NumericChars);
     numberText:=ScanWhile(buf, idx, NumericChars);
+    if ((idx<=length(buf)) and (buf[idx]='.')) then begin
+      inc(idx);
+      sec := ScanWhile(buf, idx, NumericChars);
+      if (sec = '') then Exit;
+      numberText:=NumberText+'.'+sec;
+      Result := nfFloat;
+    end else
+      Result := nfInteger;
+  end;
 
 
   if (ch<>#0) then begin
   if (ch<>#0) then begin
     if (numberText = '') then Exit;
     if (numberText = '') then Exit;
     numberText:=ch+numberText;
     numberText:=ch+numberText;
   end;
   end;
-  Result := true;
 end;
 end;
 
 
 end.
 end.

+ 20 - 1
utils/wasmbin/watscanner.pas

@@ -24,6 +24,14 @@ type
      weElem, weData, weOffset
      weElem, weData, weOffset
    );
    );
 
 
+  // used only for weNumber
+  TWatNumberFormat = (
+     wnfNo,      // other than number
+     wnfInteger, // 00
+     wnfHex,     // 0xABC
+     wnfFloat    // 0.000
+  );
+
   { TWatScanner }
   { TWatScanner }
 
 
   TWatScanner = class(TObject)
   TWatScanner = class(TObject)
@@ -37,6 +45,7 @@ type
     instrCode : byte;
     instrCode : byte;
     ofs       : integer;
     ofs       : integer;
     token     : TWatToken;
     token     : TWatToken;
+    numformat : TWatNumberFormat;
     resText   : string;
     resText   : string;
     asmCmd    : string;
     asmCmd    : string;
 
 
@@ -200,7 +209,9 @@ function TWatScanner.Next: Boolean;
 var
 var
   cmt : string;
   cmt : string;
   done: boolean;
   done: boolean;
+  fmt : TCNumberFormat;
 begin
 begin
+  numformat := wnfNo;
   Result := idx<=length(buf);
   Result := idx<=length(buf);
   if not Result then Exit;
   if not Result then Exit;
 
 
@@ -240,11 +251,19 @@ begin
         token:=weIdent;
         token:=weIdent;
         resText:=ScanWhile(buf, idx, IdBody);
         resText:=ScanWhile(buf, idx, IdBody);
       end else if buf[idx] in SignNumericChars then begin
       end else if buf[idx] in SignNumericChars then begin
-        if not ScanNumberC(buf, idx, resText) then begin
+        fmt := ScanNumberC(buf, idx, resText);
+        if fmt = nfError then begin
           token := weError;
           token := weError;
           Exit;
           Exit;
         end else
         end else
           token:=weNumber;
           token:=weNumber;
+        case fmt of
+          nfFloat: numformat := wnfFloat;
+          nfHex: numformat := wnfHex;
+        else
+          numformat := wnfInteger;
+        end;
+
       end else if buf[idx] in AlphaNumChars then begin
       end else if buf[idx] in AlphaNumChars then begin
         resText:=ScanWhile(buf, idx, GrammarChars);
         resText:=ScanWhile(buf, idx, GrammarChars);
         GetGrammar(resText, token, instrCode);
         GetGrammar(resText, token, instrCode);