]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix a error parsing out nested arrays.
authorPhilipp Winkler <philippwinkler@gmail.com>
Sun, 7 Jun 2009 03:49:44 +0000 (20:49 -0700)
committerPhilipp Winkler <philippwinkler@gmail.com>
Sun, 7 Jun 2009 03:49:44 +0000 (20:49 -0700)
basis/json/reader/reader-tests.factor
basis/json/reader/reader.factor

index fa6c8d7d3aaa21807f49d212108729465b5deb9f..14a54b89c0ff3ea2f4934e919894dad7e8d10367 100644 (file)
@@ -33,6 +33,7 @@ IN: json.reader.tests
 { 8 9 10 12 13 34 47 92 } >string 1array [ <" "\b\t\n\f\r\"\/\\" "> json> ] unit-test
 { HEX: abcd } >string 1array [ <" "\uaBCd" "> json> ] unit-test
 
+{ H{ { "a" { } } { "b" 123 } } } [ "{\"a\":[],\"b\":123}" json> ] unit-test
 { { } } [ "[]" json> ] unit-test 
 { { 1 "two" 3.0 } } [ <" [1, "two", 3.0] "> json> ] unit-test
 { H{ } } [ "{}" json> ] unit-test
index 1544af55cfd9f97d3ee505e6a7e755f7e73aed80..9886e316d7af2231feaa57f8fadcd6f60c803191 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2008 Peter Burns, 2009 Philipp Winkler
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays assocs combinators io io.streams.string json
-kernel math math.parser math.parser.private sequences strings ;
+kernel math math.parser math.parser.private prettyprint
+sequences strings vectors ;
 IN: json.reader
 
 <PRIVATE
@@ -62,18 +63,23 @@ DEFER: j-string
         [ second-last ] bi push
     ] when ;
 
+: (close-array) ( accum -- accum' )
+    dup last vector? [ v-over-push ] unless
+    dup pop >array over push ;
+
 : (close-hash) ( accum -- accum' )
     dup length 3 >= [ v-over-push ] when
     dup dup [ pop ] dip pop swap
     zip H{ } assoc-clone-like over push ;
                                                  
 : scan ( accum char -- accum )
+    ! 2dup . . ! Great for debug...
     [
         {
             { CHAR: \" [ j-string over push ] }
             { CHAR: [  [ V{ } clone over push ] }
             { CHAR: ,  [ v-over-push ] }
-            { CHAR: ]  [ v-over-push dup pop >array over push ] }
+            { CHAR: ]  [ (close-array) ] }
             { CHAR: {  [ 2 [ V{ } clone over push ] times ] }
             { CHAR: :  [ v-pick-push ] }
             { CHAR: }  [ (close-hash) ] }