Negative numbers are now considered numbers too...

Mon, 16 Jul 2012 04:26:27 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 16 Jul 2012 04:26:27 +0300
changeset 30
6c4efed2dbdd
parent 29
b4e09ae24bf1
child 31
ad027ea58097

Negative numbers are now considered numbers too...

scriptreader.cxx file | annotate | diff | comparison | revisions
str.cxx file | annotate | diff | comparison | revisions
--- a/scriptreader.cxx	Mon Jul 16 04:15:49 2012 +0300
+++ b/scriptreader.cxx	Mon Jul 16 04:26:27 2012 +0300
@@ -273,9 +273,19 @@
 }
 
 void ScriptReader::MustNumber () {
+	str num;
 	MustNext ();
-	if (!token.isnumber())
-		ParserError ("expected a number, got `%s`", token.chars());
+	num += token;
+	
+	// Cater for a possible minus sign, since it
+	// breaks the token, read a new one with the number.
+	if (!token.compare ("-")) {
+		MustNext ();
+		num += token;
+	}
+	
+	if (!num.isnumber())
+		ParserError ("expected a number, got `%s`", num.chars());
 }
 
 void ScriptReader::MustBool () {
--- a/str.cxx	Mon Jul 16 04:15:49 2012 +0300
+++ b/str.cxx	Mon Jul 16 04:26:27 2012 +0300
@@ -309,9 +309,16 @@
 
 // ============================================================================
 bool str::isnumber () {
-	ITERATE_STRING (u)
+	ITERATE_STRING (u) {
+		// Minus sign as the first character is allowed for negatives
+		if (!u && text[u] == '-') {
+			printf ("%u was minus sign\n", u);
+			continue;
+		}
+		
 		if (text[u] < '0' || text[u] > '9')
 			return false;
+	}
 	return true;
 }
 

mercurial