Fix a error parsing out nested arrays.
parent
1a97d61fd7
commit
3604535687
|
@ -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
|
{ 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
|
{ HEX: abcd } >string 1array [ <" "\uaBCd" "> json> ] unit-test
|
||||||
|
|
||||||
|
{ H{ { "a" { } } { "b" 123 } } } [ "{\"a\":[],\"b\":123}" json> ] unit-test
|
||||||
{ { } } [ "[]" json> ] unit-test
|
{ { } } [ "[]" json> ] unit-test
|
||||||
{ { 1 "two" 3.0 } } [ <" [1, "two", 3.0] "> json> ] unit-test
|
{ { 1 "two" 3.0 } } [ <" [1, "two", 3.0] "> json> ] unit-test
|
||||||
{ H{ } } [ "{}" json> ] unit-test
|
{ H{ } } [ "{}" json> ] unit-test
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2008 Peter Burns, 2009 Philipp Winkler
|
! Copyright (C) 2008 Peter Burns, 2009 Philipp Winkler
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays assocs combinators io io.streams.string json
|
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
|
IN: json.reader
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -62,18 +63,23 @@ DEFER: j-string
|
||||||
[ second-last ] bi push
|
[ second-last ] bi push
|
||||||
] when ;
|
] when ;
|
||||||
|
|
||||||
|
: (close-array) ( accum -- accum' )
|
||||||
|
dup last vector? [ v-over-push ] unless
|
||||||
|
dup pop >array over push ;
|
||||||
|
|
||||||
: (close-hash) ( accum -- accum' )
|
: (close-hash) ( accum -- accum' )
|
||||||
dup length 3 >= [ v-over-push ] when
|
dup length 3 >= [ v-over-push ] when
|
||||||
dup dup [ pop ] dip pop swap
|
dup dup [ pop ] dip pop swap
|
||||||
zip H{ } assoc-clone-like over push ;
|
zip H{ } assoc-clone-like over push ;
|
||||||
|
|
||||||
: scan ( accum char -- accum )
|
: scan ( accum char -- accum )
|
||||||
|
! 2dup . . ! Great for debug...
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
{ CHAR: \" [ j-string over push ] }
|
{ CHAR: \" [ j-string over push ] }
|
||||||
{ CHAR: [ [ V{ } clone over push ] }
|
{ CHAR: [ [ V{ } clone over push ] }
|
||||||
{ CHAR: , [ v-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: { [ 2 [ V{ } clone over push ] times ] }
|
||||||
{ CHAR: : [ v-pick-push ] }
|
{ CHAR: : [ v-pick-push ] }
|
||||||
{ CHAR: } [ (close-hash) ] }
|
{ CHAR: } [ (close-hash) ] }
|
||||||
|
|
Loading…
Reference in New Issue