Quellcode durchsuchen

catch number format exceptions

Kajetan Johannes Hammerle vor 2 Jahren
Ursprung
Commit
787c15dc44
1 geänderte Dateien mit 17 neuen und 3 gelöschten Zeilen
  1. 17 3
      src/me/hammerle/snuviscript/tokenizer/Tokenizer.java

+ 17 - 3
src/me/hammerle/snuviscript/tokenizer/Tokenizer.java

@@ -142,14 +142,28 @@ public class Tokenizer {
 
         while(true) {
             int data = peek();
-            if(!Character.isLetterOrDigit(data) && data != '.') {
+            if(!Character.isDigit(data)) {
                 break;
             }
             next();
             sb.append((char) data);
         }
-
-        add(NUMBER, Double.parseDouble(sb.toString()));
+        if(peek() == '.') {
+            sb.append((char) next());
+        }
+        while(true) {
+            int data = peek();
+            if(!Character.isDigit(data)) {
+                break;
+            }
+            next();
+            sb.append((char) data);
+        }
+        try {
+            add(NUMBER, Double.parseDouble(sb.toString()));
+        } catch(NumberFormatException ex) {
+            throw new PreScriptException("invalid number", line);
+        }
     }
 
     private void handleSpecial(int c) {