Browse Source

[PATCH 088/188] parsing integer with signs

From ed31376d1470b61911a44bc45f9f7d68e9c2b27e Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Tue, 10 Mar 2020 08:45:05 -0400

git-svn-id: branches/wasm@46084 -
nickysn 5 years ago
parent
commit
11d77e330b
2 changed files with 16 additions and 2 deletions
  1. 2 0
      utils/wasmbin/parseutils.pas
  2. 14 2
      utils/wasmbin/watscanner.pas

+ 2 - 0
utils/wasmbin/parseutils.pas

@@ -17,6 +17,8 @@ const
   WhiteSpaceChars = SpaceChars;
   SpaceEolnChars = EoLnChars+SpaceChars;
   NumericChars   = ['0'..'9'];
+  SignChars      = ['+','-'];
+  SignNumericChars = NumericChars + SignChars;
   AlphabetChars  = ['a'..'z','A'..'Z'];
   AlphaNumChars  = AlphabetChars+NumericChars;
 

+ 14 - 2
utils/wasmbin/watscanner.pas

@@ -201,6 +201,7 @@ var
   has2chars: Boolean;
   cmt : string;
   done: boolean;
+  ch  : char;
 begin
   Result := idx<=length(buf);
   if not Result then Exit;
@@ -240,9 +241,20 @@ begin
       end else if buf[idx] = IdStart then begin
         token:=weIdent;
         resText:=ScanWhile(buf, idx, IdBody);
-      end else if buf[idx] in NumericChars then begin
+      end else if buf[idx] in SignNumericChars then begin
         token:=weNumber;
-        resText:=ScanWhile(buf, idx, NumericChars);
+        if buf[idx] in SignChars then begin
+          ch:=buf[idx];
+          inc(idx);
+          resText:=ScanWhile(buf, idx, NumericChars);
+          if resText = '' then begin
+            token:=weError;
+            Exit;
+          end;
+          if (ch='-') then
+            resText:=ch+resText;
+        end else
+          resText:=ScanWhile(buf, idx, Numericchars);
       end else if buf[idx] in AlphaNumChars then begin
         resText:=ScanWhile(buf, idx, GrammarChars);
         GetGrammar(resText, token, instrCode);