]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: hex> etc. shouldn't take radix prefix
authorJoe Groff <arcata@gmail.com>
Sat, 17 Dec 2011 01:20:05 +0000 (17:20 -0800)
committerJoe Groff <arcata@gmail.com>
Sat, 17 Dec 2011 01:20:05 +0000 (17:20 -0800)
Fixes #453

core/math/parser/parser-tests.factor
core/math/parser/parser.factor

index ad396555ac17e187916e391de636be373282b159..640f8c509b633fee66726a1d1803e03c9d25190e 100644 (file)
@@ -333,3 +333,26 @@ unit-test
 [ -0x1.0000,0000,0000,2p0 ] [ "-0x1.0000,0000,0000,1,Cp0" string>number ] unit-test
 [ -0x1.0000,0000,0000,2p0 ] [ "-0x1.0000,0000,0000,1,81p0" string>number ] unit-test
 [ -0x1.0000,0000,0000,2p0 ] [ "-0x1.0000,0000,0000,1,8000,0000,0000,0001p0" string>number ] unit-test
+
+! #453
+! hex> dec> oct> bin> shouldn't admit radix prefixes
+
+[ 0x0b ] [ "0b" hex> ] unit-test
+[ 0x0b0 ] [ "0b0" hex> ] unit-test
+[ f ] [ "0o0" hex> ] unit-test
+[ f ] [ "0x0" hex> ] unit-test
+
+[ f ] [ "0b" dec> ] unit-test
+[ f ] [ "0b0" dec> ] unit-test
+[ f ] [ "0o0" dec> ] unit-test
+[ f ] [ "0x0" dec> ] unit-test
+
+[ f ] [ "0b" oct> ] unit-test
+[ f ] [ "0b0" oct> ] unit-test
+[ f ] [ "0o0" oct> ] unit-test
+[ f ] [ "0x0" oct> ] unit-test
+
+[ f ] [ "0b" bin> ] unit-test
+[ f ] [ "0b0" bin> ] unit-test
+[ f ] [ "0o0" bin> ] unit-test
+[ f ] [ "0x0" bin> ] unit-test
index bae9f473fee44b3e7cbf7ae101bdc09d79408352..43abb5a0107d1d89d451b60adee4ead8f0c6c5a4 100644 (file)
@@ -267,12 +267,20 @@ DEFER: @neg-digit
         [ @pos-first-digit ]
     } case ; inline
 
+: @first-char-no-radix ( i number-parse n char -- n/f ) 
+    {
+        { CHAR: - [ [ @neg-digit ] require-next-digit ?neg ] }
+        { CHAR: + [ [ @pos-digit ] require-next-digit ] }
+        [ @pos-digit ]
+    } case ; inline
+
 PRIVATE>
 
-: base> ( str radix -- n/f )
-    <number-parse> [ @first-char ] require-next-digit ;
+: string>number ( str -- n/f )
+    10 <number-parse> [ @first-char ] require-next-digit ;
 
-: string>number ( str -- n/f ) 10 base> ; inline
+: base> ( str radix -- n/f )
+    <number-parse> [ @first-char-no-radix ] require-next-digit ;
 
 : bin> ( str -- n/f )  2 base> ; inline
 : oct> ( str -- n/f )  8 base> ; inline