From 14efcc69ab14c48e60a3e5235038a75ce3433225 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Thu, 24 Nov 2011 12:27:40 -0800 Subject: [PATCH] math.parser: reject "0x" etc. without any digits --- core/math/parser/parser-tests.factor | 16 ++++++++++++++++ core/math/parser/parser.factor | 14 +++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/core/math/parser/parser-tests.factor b/core/math/parser/parser-tests.factor index 7194f1b427..378862fbca 100644 --- a/core/math/parser/parser-tests.factor +++ b/core/math/parser/parser-tests.factor @@ -239,6 +239,7 @@ unit-test [ 0 ] [ "0" string>number ] unit-test [ 0 ] [ "00" string>number ] unit-test +[ 0 ] [ "0,000" string>number ] unit-test [ 0.0 ] [ "0." string>number ] unit-test [ 0.0 ] [ "0.0" string>number ] unit-test [ 0.0 ] [ "0x0.0p0" string>number ] unit-test @@ -256,4 +257,19 @@ unit-test [ -8 ] [ "-0o10" string>number ] unit-test [ -2 ] [ "-0b10" string>number ] unit-test +[ 0x7FFF,ABCD ] [ "0x7FFF,ABCD" string>number ] unit-test + [ 1.0 ] [ "0x1.0p0" string>number ] unit-test + +[ f ] [ "0x" string>number ] unit-test +[ f ] [ "0b" string>number ] unit-test +[ f ] [ "0o" string>number ] unit-test +[ f ] [ "0x," string>number ] unit-test +[ f ] [ "0b," string>number ] unit-test +[ f ] [ "0o," string>number ] unit-test +[ f ] [ "0x,1" string>number ] unit-test +[ f ] [ "0b,1" string>number ] unit-test +[ f ] [ "0o,1" string>number ] unit-test +[ f ] [ "0x1," string>number ] unit-test +[ f ] [ "0b1," string>number ] unit-test +[ f ] [ "0o1," string>number ] unit-test diff --git a/core/math/parser/parser.factor b/core/math/parser/parser.factor index 2934d9549a..8d006141e3 100644 --- a/core/math/parser/parser.factor +++ b/core/math/parser/parser.factor @@ -217,9 +217,9 @@ DEFER: @neg-digit : with-radix-char ( i number-parse n radix-quot nonradix-quot -- n/f ) [ rot { - { CHAR: b [ drop 2 ->radix next-digit ] } - { CHAR: o [ drop 8 ->radix next-digit ] } - { CHAR: x [ drop 16 ->radix next-digit ] } + { CHAR: b [ drop 2 ->radix require-next-digit ] } + { CHAR: o [ drop 8 ->radix require-next-digit ] } + { CHAR: x [ drop 16 ->radix require-next-digit ] } { f [ 3drop 2drop 0 ] } [ [ drop ] 2dip swap call ] } case @@ -228,9 +228,9 @@ DEFER: @neg-digit : @pos-first-digit ( i number-parse n char -- n/f ) { { CHAR: . [ ->required-mantissa ] } - { CHAR: 0 [ [ @pos-digit ] [ @pos-digit-or-punc ] with-radix-char ] } + { CHAR: 0 [ [ @pos-first-digit ] [ @pos-digit-or-punc ] with-radix-char ] } [ @pos-digit ] - } case ; inline + } case ; inline recursive : @neg-digit-or-punc ( i number-parse n char -- n/f ) { @@ -248,9 +248,9 @@ DEFER: @neg-digit : @neg-first-digit ( i number-parse n char -- n/f ) { { CHAR: . [ ->required-mantissa ] } - { CHAR: 0 [ [ @neg-digit ] [ @neg-digit-or-punc ] with-radix-char ] } + { CHAR: 0 [ [ @neg-first-digit ] [ @neg-digit-or-punc ] with-radix-char ] } [ @neg-digit ] - } case ; inline + } case ; inline recursive : @first-char ( i number-parse n char -- n/f ) {