parrot / parrot

Parrot Virtual Machine
http://parrot.org
Artistic License 2.0
592 stars 138 forks source link

JSON libraries should be renamed to something less confusing #494

Open parrot opened 15 years ago

parrot commented 15 years ago

There are three JSON.pbc files currently:-

The supplied patch renames the purely read/write ones to library/JSONReader.pbc and library/JSONWriter.pbc.

However, what this patch misses is leaving a stub PBCs to manage a proper deprecation cycle.

Originally http://trac.parrot.org/parrot/ticket/508 by bsdz

parrot commented 15 years ago

29445 byte attachment from bsdz at http://trac.parrot.org/parrot/raw-attachment/ticket/508/json.patch

```Index: compilers/json/JSON.pir

--- compilers/json/JSON.pir (revision 37749) +++ compilers/json/JSON.pir (working copy) @@ -1,82 +0,0 @@

-# Copyright (C) 2005-2008, Parrot Foundation.

-=head1 NAME

-JSON (JavaScript Object Notation) is a lightweight data-interchange format.

-=head1 SYNOPSIS

-Given a valid JSON string, the compiler will return a PMC containing the

-appropriate values. For example:

- $P0 = JSON('[1,2,3]')

-Will create a pmc that C array, contains the values 1, 2, and 3, and

-store it in register C<$P0>.

-For more information about the structure of the JSON representation, see the

-documentation at Lhttp://www.json.org/.

-=cut

-.namespace [ 'JSON' ]

-.sub '__onload' :load

- load_bytecode 'TGE.pbc'

- load_bytecode 'compilers/json/JSON/pge2pir.pbc'

- compreg "JSON", $P1

- $P1['\t'] = "\t"

- .param string json_string

- parse = get_root_global ['parrot'; 'JSON'], 'value'

- unless match goto failed

- pir = pirbuilder.'get'('result')

- .tailcall result()

Property changes on: compilers\json\JSONReader.pir


Added: svn:mergeinfo Merged /branches/RELEASE_0_8_2/compilers/json/JSON.pir:r34004-34020 Merged /branches/removing_stm/compilers/json/JSON.pir:r35464-35502 Merged /branches/assert_args/compilers/json/JSON.pir:r34776-34857 Merged /branches/jit_h_files/compilers/json/JSON.pir:r34166-35215

Index: compilers/json/postalcodes.pir

--- compilers/json/postalcodes.pir (revision 37749) +++ compilers/json/postalcodes.pir (working copy) @@ -68,7 +68,7 @@ $I0 = index json_result, "\r\n\r\n" substr json_result, 0, $I0, ""

Index: compilers/json/test.pir

--- compilers/json/test.pir (revision 37749) +++ compilers/json/test.pir (working copy) @@ -9,7 +9,7 @@

load_bytecode 'PGE.pbc' load_bytecode 'PGE/Util.pbc'

+PARROT_LIBRARY := ../../runtime/parrot/library +

the default target

-all: JSON.pbc +all: $(PARROT_LIBRARY)/JSONReader.pbc

This is a listing of all targets, that are meant to be called by users

help: @echo "" @echo "Following targets are available for the user:" @echo ""

-JSON.pbc : JSON/grammar.pbc JSON/pge2pir.pbc JSON.pir

- $S0 = _json( $P0 )

-To generate a PMC from a JSON string, see L<compilers/json/JSON.pir>.

-=cut

-=head1 FUNCTIONS

-This library provides the following functions:

-=over 4

-=item (string) = _json(pmc, ?pretty )

-Convert a PMC to a JSON-serialized string. Note: If you pass in a cyclic

-structure, JSON will eventually throw a maximum recursion depth exception.

-=over 4

-=item pmc

-Required. The PMC to dump.

-=item pretty

-Optional. Boolean: If true, then the generated string will be very -readable for humans. Defaults to false, which will generate the

-most compact string possible.

-=back

-=cut

-.const string _json_prefix = ' '

-.sub _json

- .param int has_pretty :opt_flag

- .local string result

- pretty = 0

-done_init:

- .param int indent

-done_init:

- if_null thing, json_null

- if $I0 goto json_array

- if $I0 goto json_hash

- if $I0 goto json_string

- if $I0 goto json_boolean

- if $I0 goto json_integer

- if $I0 goto json_float

- .tailcall _json_number(thing,pretty,indent)

-.end

-.sub '_json_null'

- .param int indent

- unless indent goto plain

- .return (result)

-plain:

- .param int indent

- .local string result

- thing = escape thing

- result = result . '"'

- unless indent goto plain

- result = $S0 . result

-plain:

- .param int indent

- .local string result

- result = 'false'

-got_value:

- unless indent goto plain

- result = $S0 . result

-plain:

- .param int indent

- .local string result

- result = thing

- unless indent goto plain

- result = $S0 . result

-plain:

- .param int indent

- .local string result

- len = thing

- unless indent goto pre_loop

- result .= "\n"

-pre_loop:

- result .= "\n"

-loop:

- goto loop

-done_loop:

- dec indent

- optional_indent = ''

- optional_newline = "\n"

-indent1:

- optional_indent = repeat _json_prefix, indent

-done:

- result .= ']'

- .return (result)

-.end

-.sub '_json_hash'

- .param int indent

- not_empty = thing

- .local string key

-iter_loop:

- goto iter_loop

-done_iter:

- keys.'sort'()

- .local string result,separator

- separator = ':'

- unless indent goto pre_loop

- result .= "\n"

-pre_loop:

- result .= "\n"

-loop:

- $S0 = _json_any($P1,pretty,indent)

- unless pretty goto space_loop_skip

- space_len = length $S0

-space_loop:

- if $I0 != 32 goto space_loop_done

- goto space_loop

-space_loop_done:

- $S0 = substr $S0, space_pos

-space_loop_skip:

- goto loop

-done_loop:

- dec indent

- optional_indent = ''

- optional_newline = "\n"

-indent1:

- optional_indent = repeat _json_prefix, indent

-done:

- result .= '}'

-JSON.pir - PIR implementation of JSON data interchange format. +JSONWriter.pir - PIR implementation of JSON data interchange format.

=head1 SYNOPSIS

Use the C<_json> method to generate a JSON representation of a PMC.

-To generate a PMC from a JSON string, see L<compilers/json/JSON.pir>. +To generate a PMC from a JSON string, see L<compilers/json/JSONReader.pir>.

=cut

Property changes on: runtime\parrot\library\JSONWriter.pir


Added: svn:mergeinfo Merged /branches/assert_args/runtime/parrot/library/JSON.pir:r34776-34857 Merged /branches/jit_h_files/runtime/parrot/library/JSON.pir:r34166-35215 Merged /branches/RELEASE_0_8_2/runtime/parrot/library/JSON.pir:r34004-34020 Merged /branches/removing_stm/runtime/parrot/library/JSON.pir:r35464-35502

Index: t/compilers/json/from_parrot.t

--- t/compilers/json/from_parrot.t (revision 37749) +++ t/compilers/json/from_parrot.t (working copy) @@ -33,7 +33,7 @@ $S0 = _json( s, 0 ) say $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE "" OUT @@ -48,7 +48,7 @@ $S0 = json( s, 0 ) say $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE "abcdeABCDE01234$%^&" OUT @@ -63,7 +63,7 @@ $S0 = json( s, 0 ) say $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE "abcde\ABCDE\"01234\n$%^&" OUT @@ -89,7 +89,7 @@ $S0 = _json( i, 0 ) say $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE 0 35 @@ -116,7 +116,7 @@ $S0 = _json( n ) say $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE 0 2.5 @@ -143,7 +143,7 @@ $S0 = _json( n, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE "abcde\ABCDE\"01234\n$%^&*" -42 @@ -172,7 +172,7 @@ $S0 = _json( array, 0 ) say $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE [0,1,2,3,4,5,6,7,8,9] OUT @@ -199,7 +199,7 @@ $S0 = _json( array, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE [ 0, @@ -233,7 +233,7 @@ $S0 = _json( array, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE [ 35, @@ -263,7 +263,7 @@ $S0 = _json( array, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE [ 0, @@ -290,7 +290,7 @@ $S0 = _json( hash, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE { "alpha" : 29, @@ -315,7 +315,7 @@ $S0 = _json( hash, 0 ) say $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE {"alpha":29,"beta":"B","delta":"DELTA","gamma":3.1} OUT @@ -352,7 +352,7 @@ $S0 = _json( world, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE { "population" : 1234567890, @@ -403,7 +403,7 @@ $S0 = _json( world, 0 ) say $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE {"population":1234567890,"some_country":[[{"Perl":"Highway","Python":"Grove","Ruby":"Lane"},{}],[]]} OUT @@ -428,7 +428,7 @@ $S0 = _json( s, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE "" "" @@ -456,7 +456,7 @@ $S0 = _json( i, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE 0 0 @@ -484,7 +484,7 @@ $S0 = _json( b, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE false false @@ -510,7 +510,7 @@ $S0 = _json( n, 1 ) print $S0 .end -.include 'library/JSON.pir' +.include 'library/JSONWriter.pir' CODE null null

Index: t/compilers/json/to_parrot.t

--- t/compilers/json/to_parrot.t (revision 37749) +++ t/compilers/json/to_parrot.t (working copy) @@ -689,7 +689,7 @@ return pir_output_is( <<"END_PIR", $dumped, $reason, %args );

.sub test :main

parrot commented 15 years ago

Trac commenter: bsdz

    <p>

Patch to rename to JSONReader and JSONWriter

allisonrandal commented 15 years ago

Rather than putting in deprecation stubs, we'll just enter a deprecation notice now for the old library names (done in 37768) and make the change in 1.5.

For consistency and clarity, let's move these to library/JSON/Reader.pbc, library/JSON/Writer.pbc and library/JSON/Config.pbc. (With the class names ['JSON'; 'Reader'] etc).

coke commented 14 years ago

compilers/json is gone, use data_json instead.

bacek commented 14 years ago

So, resolving ticket.

coke commented 14 years ago

Original issue still not resolved.

Whiteknight commented 12 years ago

Is this something we still want to work on? If so, we're probably going to need an updated patch.