From 0376cf0f9d5ec32ddfab59c4cab2059b33d05aa7 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Mon, 10 Aug 2009 19:33:27 -0400 Subject: [PATCH] allow commas in numeric literals --- core/math/parser/parser-tests.factor | 8 ++++++++ core/math/parser/parser.factor | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/math/parser/parser-tests.factor b/core/math/parser/parser-tests.factor index c655965e35..2b440b24d4 100644 --- a/core/math/parser/parser-tests.factor +++ b/core/math/parser/parser-tests.factor @@ -25,6 +25,14 @@ unit-test [ "e" string>number ] unit-test +[ 100000 ] +[ "100,000" string>number ] +unit-test + +[ 100000.0 ] +[ "100,000.0" string>number ] +unit-test + [ "100.0" ] [ "1.0e2" string>number number>string ] unit-test diff --git a/core/math/parser/parser.factor b/core/math/parser/parser.factor index 437308d53f..cc01699bd4 100644 --- a/core/math/parser/parser.factor +++ b/core/math/parser/parser.factor @@ -28,13 +28,16 @@ IN: math.parser { CHAR: d 13 } { CHAR: e 14 } { CHAR: f 15 } - } at 255 or ; inline + { CHAR: , f } + } at* [ drop 255 ] unless ; inline : string>digits ( str -- digits ) [ digit> ] B{ } map-as ; inline : (digits>integer) ( valid? accum digit radix -- valid? accum ) - 2dup < [ swapd * + ] [ 2drop 2drop f 0 ] if ; inline + over [ + 2dup < [ swapd * + ] [ 2drop 2drop f 0 ] if + ] [ 2drop ] if ; inline : each-digit ( seq radix quot -- n/f ) [ t 0 ] 3dip curry each swap [ drop f ] unless ; inline @@ -80,6 +83,7 @@ SYMBOL: negative? ] if ; inline : string>float ( str -- n/f ) + [ CHAR: , eq? not ] filter >byte-array 0 suffix (string>float) ; PRIVATE>