json: Rename `json_to_nit_object` to `parse_json`.
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Fri, 14 Nov 2014 16:27:18 +0000 (11:27 -0500)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Mon, 17 Nov 2014 19:59:26 +0000 (14:59 -0500)
Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

lib/github_api.nit
lib/json/dynamic.nit
lib/json/static.nit
lib/json_serialization.nit
tests/test_json_static.nit

index f2e5a69..39fca84 100644 (file)
@@ -53,7 +53,7 @@ class GithubCurl
                var response = request.execute
 
                if response isa CurlResponseSuccess then
-                       var obj = response.body_str.json_to_nit_object
+                       var obj = response.body_str.parse_json
                        if obj isa JsonObject then
                                if obj.keys.has("message") then
                                        print "Message from Github API: {obj["message"] or else ""}"
index 4ab9aa3..e39e2d6 100644 (file)
@@ -218,9 +218,8 @@ end
 
 redef class Text
        # Parse `self` to obtain a `JsonValue`
-       fun to_json_value: JsonValue
-       do
-               var value = json_to_nit_object
+       fun to_json_value: JsonValue do
+               var value = parse_json
                return new JsonValue(value)
        end
 end
index 4841020..67ae0db 100644 (file)
@@ -18,7 +18,7 @@
 
 # Static interface to get Nit objects from a Json string.
 #
-# `String::json_to_nit_object` returns an equivalent Nit object from
+# `Text::parse_json` returns an equivalent Nit object from
 # the Json source. This object can then be type checked by the usual
 # languages features (`isa` and `as`).
 module static
@@ -75,7 +75,7 @@ redef class Text
                return buffer.write_to_string
        end
 
-       fun json_to_nit_object: nullable Jsonable do
+       fun parse_json: nullable Jsonable do
                var lexer = new Lexer_json(to_s)
                var parser = new Parser_json
                var tokens = lexer.lex
index 4de3b23..c77ecc0 100644 (file)
@@ -79,7 +79,7 @@ class JsonDeserializer
 
        init(text: Text)
        do
-               var root = text.json_to_nit_object
+               var root = text.parse_json
                if root isa JsonObject then path.add(root)
                self.root = root
        end
index efc65d2..db6b1cf 100644 (file)
@@ -27,7 +27,7 @@ var c = "\{\"foo\":\"bar\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0020\\u0000\"\}"
 var d = "\{ \"face with tears of joy\" : \"\\uD83D\\uDE02\" \}"
 
 for s in [a, b, c, d] do
-       var obj = s.json_to_nit_object
+       var obj = s.parse_json
        print "# Json: {s}"
        print "# Nit: {obj or else "<null>"}"
 end