Updated eJSON to use Eiffel 6.8 version.
Basically the changes are: Replace ? by detachable indexing by note removing `is' from features, and in some places replaced by = In the ecf now we need to include every gobo library, because the gobo.ecf, exclude libraries that are needed. TODO: the test-suite is not void-safety.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "Objects that ..."
|
description: "Objects that ..."
|
||||||
author: ""
|
author: ""
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
@@ -9,11 +9,11 @@ class
|
|||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
read_json_from (a_path: STRING): ?STRING is
|
read_json_from (a_path: STRING): detachable STRING
|
||||||
local
|
local
|
||||||
l_file: PLAIN_TEXT_FILE
|
l_file: PLAIN_TEXT_FILE
|
||||||
template_content: STRING
|
template_content: STRING
|
||||||
l_last_string: ?STRING
|
l_last_string: detachable STRING
|
||||||
do
|
do
|
||||||
create l_file.make (a_path)
|
create l_file.make (a_path)
|
||||||
-- We perform several checks until we make a real attempt to open the file.
|
-- We perform several checks until we make a real attempt to open the file.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description:
|
description:
|
||||||
|
|
||||||
"JSON Visitor"
|
"JSON Visitor"
|
||||||
@@ -14,42 +14,42 @@ deferred class
|
|||||||
|
|
||||||
feature -- Visitor Pattern
|
feature -- Visitor Pattern
|
||||||
|
|
||||||
visit_json_array (a_json_array: JSON_ARRAY) is
|
visit_json_array (a_json_array: JSON_ARRAY)
|
||||||
-- Visit `a_json_array'.
|
-- Visit `a_json_array'.
|
||||||
require
|
require
|
||||||
a_json_array_not_void: a_json_array /= Void
|
a_json_array_not_void: a_json_array /= Void
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_boolean (a_json_boolean: JSON_BOOLEAN) is
|
visit_json_boolean (a_json_boolean: JSON_BOOLEAN)
|
||||||
-- Visit `a_json_boolean'.
|
-- Visit `a_json_boolean'.
|
||||||
require
|
require
|
||||||
a_json_boolean_not_void: a_json_boolean /= Void
|
a_json_boolean_not_void: a_json_boolean /= Void
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_null (a_json_null: JSON_NULL) is
|
visit_json_null (a_json_null: JSON_NULL)
|
||||||
-- Visit `a_json_null'.
|
-- Visit `a_json_null'.
|
||||||
require
|
require
|
||||||
a_json_null_not_void: a_json_null /= Void
|
a_json_null_not_void: a_json_null /= Void
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_number (a_json_number: JSON_NUMBER) is
|
visit_json_number (a_json_number: JSON_NUMBER)
|
||||||
-- Visit `a_json_number'.
|
-- Visit `a_json_number'.
|
||||||
require
|
require
|
||||||
a_json_number_not_void: a_json_number /= Void
|
a_json_number_not_void: a_json_number /= Void
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_object (a_json_object: JSON_OBJECT) is
|
visit_json_object (a_json_object: JSON_OBJECT)
|
||||||
-- Visit `a_json_object'.
|
-- Visit `a_json_object'.
|
||||||
require
|
require
|
||||||
a_json_object_not_void: a_json_object /= Void
|
a_json_object_not_void: a_json_object /= Void
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_string (a_json_string: JSON_STRING) is
|
visit_json_string (a_json_string: JSON_STRING)
|
||||||
-- Visit `a_json_string'.
|
-- Visit `a_json_string'.
|
||||||
require
|
require
|
||||||
a_json_string_not_void: a_json_string /= Void
|
a_json_string_not_void: a_json_string /= Void
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "PRINT_JSON_VISITOR Generates the JSON-String for a JSON_VALUE"
|
description: "PRINT_JSON_VISITOR Generates the JSON-String for a JSON_VALUE"
|
||||||
author: "jvelilla"
|
author: "jvelilla"
|
||||||
date: "2008/08/24"
|
date: "2008/08/24"
|
||||||
@@ -14,7 +14,7 @@ create make
|
|||||||
|
|
||||||
feature -- Initialization
|
feature -- Initialization
|
||||||
|
|
||||||
make is
|
make
|
||||||
-- Create a new instance
|
-- Create a new instance
|
||||||
do
|
do
|
||||||
create to_json.make_empty
|
create to_json.make_empty
|
||||||
@@ -27,7 +27,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Visitor Pattern
|
feature -- Visitor Pattern
|
||||||
|
|
||||||
visit_json_array (a_json_array: JSON_ARRAY) is
|
visit_json_array (a_json_array: JSON_ARRAY)
|
||||||
-- Visit `a_json_array'.
|
-- Visit `a_json_array'.
|
||||||
local
|
local
|
||||||
value: JSON_VALUE
|
value: JSON_VALUE
|
||||||
@@ -50,25 +50,25 @@ feature -- Visitor Pattern
|
|||||||
to_json.append ("]")
|
to_json.append ("]")
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_boolean (a_json_boolean: JSON_BOOLEAN) is
|
visit_json_boolean (a_json_boolean: JSON_BOOLEAN)
|
||||||
-- Visit `a_json_boolean'.
|
-- Visit `a_json_boolean'.
|
||||||
do
|
do
|
||||||
to_json.append (a_json_boolean.item.out)
|
to_json.append (a_json_boolean.item.out)
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_null (a_json_null: JSON_NULL) is
|
visit_json_null (a_json_null: JSON_NULL)
|
||||||
-- Visit `a_json_null'.
|
-- Visit `a_json_null'.
|
||||||
do
|
do
|
||||||
to_json.append ("null")
|
to_json.append ("null")
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_number (a_json_number: JSON_NUMBER) is
|
visit_json_number (a_json_number: JSON_NUMBER)
|
||||||
-- Visit `a_json_number'.
|
-- Visit `a_json_number'.
|
||||||
do
|
do
|
||||||
to_json.append (a_json_number.item)
|
to_json.append (a_json_number.item)
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_object (a_json_object: JSON_OBJECT) is
|
visit_json_object (a_json_object: JSON_OBJECT)
|
||||||
-- Visit `a_json_object'.
|
-- Visit `a_json_object'.
|
||||||
local
|
local
|
||||||
l_pairs: HASH_TABLE[JSON_VALUE,JSON_STRING]
|
l_pairs: HASH_TABLE[JSON_VALUE,JSON_STRING]
|
||||||
@@ -91,7 +91,7 @@ feature -- Visitor Pattern
|
|||||||
to_json.append ("}")
|
to_json.append ("}")
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_string (a_json_string: JSON_STRING) is
|
visit_json_string (a_json_string: JSON_STRING)
|
||||||
-- Visit `a_json_string'.
|
-- Visit `a_json_string'.
|
||||||
do
|
do
|
||||||
to_json.append ("%"")
|
to_json.append ("%"")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "A JSON converter for DS_HASH_TABLE [ANY, HASHABLE]"
|
description: "A JSON converter for DS_HASH_TABLE [ANY, HASHABLE]"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date: $"
|
date: "$Date: $"
|
||||||
@@ -15,7 +15,7 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make is
|
make
|
||||||
do
|
do
|
||||||
create object.make (0)
|
create object.make (0)
|
||||||
end
|
end
|
||||||
@@ -28,7 +28,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like value): like object is
|
from_json (j: like value): detachable like object
|
||||||
local
|
local
|
||||||
keys: ARRAY [JSON_STRING]
|
keys: ARRAY [JSON_STRING]
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
@@ -50,7 +50,7 @@ feature -- Conversion
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): like value is
|
to_json (o: like object): like value
|
||||||
local
|
local
|
||||||
c: DS_HASH_TABLE_CURSOR [ANY, HASHABLE]
|
c: DS_HASH_TABLE_CURSOR [ANY, HASHABLE]
|
||||||
js: JSON_STRING
|
js: JSON_STRING
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "A JSON converter for DS_LINKED_LIST [ANY]"
|
description: "A JSON converter for DS_LINKED_LIST [ANY]"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date: $"
|
date: "$Date: $"
|
||||||
@@ -15,7 +15,7 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make is
|
make
|
||||||
do
|
do
|
||||||
create object.make
|
create object.make
|
||||||
end
|
end
|
||||||
@@ -28,7 +28,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like value): like object is
|
from_json (j: like value): detachable like object
|
||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
do
|
do
|
||||||
@@ -43,7 +43,7 @@ feature -- Conversion
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): like value is
|
to_json (o: like object): like value
|
||||||
local
|
local
|
||||||
c: DS_LIST_CURSOR [ANY]
|
c: DS_LIST_CURSOR [ANY]
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "[
|
description: "[
|
||||||
Shared factory class for creating JSON objects. Maps JSON
|
Shared factory class for creating JSON objects. Maps JSON
|
||||||
objects to Gobo DS_HASH_TABLEs and JSON arrays to Gobo
|
objects to Gobo DS_HASH_TABLEs and JSON arrays to Gobo
|
||||||
@@ -15,7 +15,7 @@ class SHARED_GOBO_EJSON
|
|||||||
|
|
||||||
feature
|
feature
|
||||||
|
|
||||||
json: EJSON is
|
json: EJSON
|
||||||
-- A shared EJSON instance with default converters for
|
-- A shared EJSON instance with default converters for
|
||||||
-- DS_LINKED_LIST [ANY] and DS_HASH_TABLE [ANY, HASHABLE]
|
-- DS_LINKED_LIST [ANY] and DS_HASH_TABLE [ANY, HASHABLE]
|
||||||
local
|
local
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-5-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-5-0 http://www.eiffel.com/developers/xml/configuration-1-5-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
|
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
|
||||||
<target name="json">
|
<target name="json">
|
||||||
<root all_classes="true"/>
|
<root all_classes="true"/>
|
||||||
<option trace="false" profile="false" debug="false" warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="obsolete" namespace="EJSON.Library">
|
<option trace="false" profile="false" debug="false" warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard" namespace="EJSON.Library">
|
||||||
<assertions/>
|
<assertions/>
|
||||||
<warning name="export_class_missing" enabled="false"/>
|
<warning name="export_class_missing" enabled="false"/>
|
||||||
<warning name="old_verbatim_strings" enabled="false"/>
|
<warning name="old_verbatim_strings" enabled="false"/>
|
||||||
@@ -13,16 +13,15 @@
|
|||||||
<cluster name="json" location=".\" recursive="true">
|
<cluster name="json" location=".\" recursive="true">
|
||||||
<file_rule>
|
<file_rule>
|
||||||
<exclude>/EIFGENs$</exclude>
|
<exclude>/EIFGENs$</exclude>
|
||||||
<exclude>/.svn$</exclude>
|
|
||||||
<exclude>/CVS$</exclude>
|
<exclude>/CVS$</exclude>
|
||||||
|
<exclude>/.svn$</exclude>
|
||||||
</file_rule>
|
</file_rule>
|
||||||
<file_rule>
|
<file_rule>
|
||||||
<exclude>^/kernel$</exclude>
|
|
||||||
<exclude>^/gobo$</exclude>
|
<exclude>^/gobo$</exclude>
|
||||||
|
<exclude>^/kernel$</exclude>
|
||||||
<exclude>^/extras$</exclude>
|
<exclude>^/extras$</exclude>
|
||||||
</file_rule>
|
</file_rule>
|
||||||
<cluster name="kernel" location=".\kernel\" recursive="true"/>
|
<cluster name="kernel" location=".\kernel\" recursive="true"/>
|
||||||
<cluster name="gobo" location=".\gobo\" recursive="true"/>
|
|
||||||
<cluster name="extras" location=".\extras\" recursive="true"/>
|
<cluster name="extras" location=".\extras\" recursive="true"/>
|
||||||
</cluster>
|
</cluster>
|
||||||
</target>
|
</target>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-3-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-3-0 http://www.eiffel.com/developers/xml/configuration-1-3-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
|
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
|
||||||
<target name="json">
|
<target name="json">
|
||||||
<root all_classes="true"/>
|
<root all_classes="true"/>
|
||||||
<option trace="false" profile="false" debug="false" warning="true" full_class_checking="true" namespace="EJSON.Library">
|
<option trace="false" profile="false" debug="false" warning="true" full_class_checking="true" void_safety="none" syntax="standard" namespace="EJSON.Library">
|
||||||
<assertions/>
|
<assertions/>
|
||||||
<warning name="export_class_missing" enabled="false"/>
|
<warning name="export_class_missing" enabled="false"/>
|
||||||
<warning name="old_verbatim_strings" enabled="false"/>
|
<warning name="old_verbatim_strings" enabled="false"/>
|
||||||
@@ -10,16 +10,28 @@
|
|||||||
<warning name="vjrv" enabled="false"/>
|
<warning name="vjrv" enabled="false"/>
|
||||||
</option>
|
</option>
|
||||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf" readonly="true"/>
|
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf" readonly="true"/>
|
||||||
<library name="gobo_ise" location="$ISE_LIBRARY\library\gobo\gobo.ecf" readonly="true"/>
|
<library name="gobo_argument" location="$ISE_LIBRARY\library\gobo\gobo_argument.ecf"/>
|
||||||
|
<library name="gobo_kernel" location="$ISE_LIBRARY\library\gobo\gobo_kernel.ecf"/>
|
||||||
|
<library name="gobo_lexical" location="$ISE_LIBRARY\library\gobo\gobo_lexical.ecf"/>
|
||||||
|
<library name="gobo_math" location="$ISE_LIBRARY\library\gobo\gobo_math.ecf"/>
|
||||||
|
<library name="gobo_parse" location="$ISE_LIBRARY\library\gobo\gobo_parse.ecf"/>
|
||||||
|
<library name="gobo_pattern" location="$ISE_LIBRARY\library\gobo\gobo_pattern.ecf"/>
|
||||||
|
<library name="gobo_regexp" location="$ISE_LIBRARY\library\gobo\gobo_regexp.ecf"/>
|
||||||
|
<library name="gobo_string" location="$ISE_LIBRARY\library\gobo\gobo_string.ecf"/>
|
||||||
|
<library name="gobo_structure" location="$ISE_LIBRARY\library\gobo\gobo_structure.ecf"/>
|
||||||
|
<library name="gobo_time" location="$ISE_LIBRARY\library\gobo\gobo_time.ecf"/>
|
||||||
|
<library name="gobo_tools" location="$ISE_LIBRARY\library\gobo\gobo_tools.ecf"/>
|
||||||
|
<library name="gobo_utility" location="$ISE_LIBRARY\library\gobo\gobo_utility.ecf"/>
|
||||||
|
<library name="gobo_xml" location="$ISE_LIBRARY\library\gobo\gobo_xml.ecf"/>
|
||||||
<cluster name="json" location=".\" recursive="true">
|
<cluster name="json" location=".\" recursive="true">
|
||||||
<file_rule>
|
<file_rule>
|
||||||
<exclude>/EIFGENs$</exclude>
|
<exclude>/EIFGENs$</exclude>
|
||||||
<exclude>/.svn$</exclude>
|
|
||||||
<exclude>/CVS$</exclude>
|
<exclude>/CVS$</exclude>
|
||||||
|
<exclude>/.svn$</exclude>
|
||||||
</file_rule>
|
</file_rule>
|
||||||
<file_rule>
|
<file_rule>
|
||||||
<exclude>^/kernel$</exclude>
|
|
||||||
<exclude>^/gobo$</exclude>
|
<exclude>^/gobo$</exclude>
|
||||||
|
<exclude>^/kernel$</exclude>
|
||||||
<exclude>^/extras$</exclude>
|
<exclude>^/extras$</exclude>
|
||||||
</file_rule>
|
</file_rule>
|
||||||
<cluster name="kernel" location=".\kernel\" recursive="true"/>
|
<cluster name="kernel" location=".\kernel\" recursive="true"/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "A JSON converter"
|
description: "A JSON converter"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date: $"
|
date: "$Date: $"
|
||||||
@@ -12,24 +12,20 @@ inherit
|
|||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
value: JSON_VALUE is
|
object: ANY
|
||||||
-- JSON value
|
|
||||||
deferred
|
|
||||||
end
|
|
||||||
|
|
||||||
object: ANY is
|
|
||||||
-- Eiffel object
|
-- Eiffel object
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like value): like object is
|
from_json (j: attached like to_json): detachable like object
|
||||||
-- Convert from JSON value. Returns Void if unable to convert
|
-- Convert from JSON value.
|
||||||
|
-- Returns Void if unable to convert
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): like value is
|
to_json (o: like object): detachable JSON_VALUE
|
||||||
-- Convert to JSON value
|
-- Convert to JSON value
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
@@ -37,5 +33,4 @@ feature -- Conversion
|
|||||||
invariant
|
invariant
|
||||||
has_eiffel_object: object /= Void -- An empty object must be created at creation time!
|
has_eiffel_object: object /= Void -- An empty object must be created at creation time!
|
||||||
|
|
||||||
end -- class JSON_CONVERTER
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
|
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
@@ -15,25 +15,24 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make is
|
make
|
||||||
do
|
do
|
||||||
create object.make (0)
|
create object.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
value: JSON_OBJECT
|
|
||||||
|
|
||||||
object: HASH_TABLE [ANY, HASHABLE]
|
object: HASH_TABLE [ANY, HASHABLE]
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like value): like object is
|
from_json (j: attached like to_json): like object
|
||||||
local
|
local
|
||||||
keys: ARRAY [JSON_STRING]
|
keys: ARRAY [JSON_STRING]
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
h: HASHABLE
|
h: detachable HASHABLE
|
||||||
a: ANY
|
jv: detachable JSON_VALUE
|
||||||
|
a: detachable ANY
|
||||||
do
|
do
|
||||||
keys := j.current_keys
|
keys := j.current_keys
|
||||||
create Result.make (keys.count)
|
create Result.make (keys.count)
|
||||||
@@ -44,32 +43,42 @@ feature -- Conversion
|
|||||||
loop
|
loop
|
||||||
h ?= json.object (keys [i], void)
|
h ?= json.object (keys [i], void)
|
||||||
check h /= Void end
|
check h /= Void end
|
||||||
a := json.object (j.item (keys [i]), Void)
|
jv := j.item (keys [i])
|
||||||
|
if jv /= Void then
|
||||||
|
a := json.object (jv, Void)
|
||||||
|
if a /= Void then
|
||||||
Result.put (a, h)
|
Result.put (a, h)
|
||||||
|
else
|
||||||
|
check a_attached: a /= Void end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
check j_has_item: False end
|
||||||
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): like value is
|
to_json (o: like object): detachable JSON_OBJECT
|
||||||
local
|
local
|
||||||
|
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
|
||||||
js: JSON_STRING
|
js: JSON_STRING
|
||||||
jv: JSON_VALUE
|
jv: detachable JSON_VALUE
|
||||||
failed: BOOLEAN
|
failed: BOOLEAN
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
from
|
from
|
||||||
o.start
|
c := o.new_cursor
|
||||||
until
|
until
|
||||||
o.after
|
c.after
|
||||||
loop
|
loop
|
||||||
create js.make_json (o.key_for_iteration.out)
|
create js.make_json (c.key.out)
|
||||||
jv := json.value (o.item_for_iteration)
|
jv := json.value (c.item)
|
||||||
if jv /= Void then
|
if jv /= Void then
|
||||||
Result.put (jv, js)
|
Result.put (jv, js)
|
||||||
else
|
else
|
||||||
failed := True
|
failed := True
|
||||||
end
|
end
|
||||||
o.forth
|
c.forth
|
||||||
end
|
end
|
||||||
if failed then
|
if failed then
|
||||||
Result := Void
|
Result := Void
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "A JSON converter for LINKED_LIST [ANY]"
|
description: "A JSON converter for LINKED_LIST [ANY]"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
@@ -15,20 +15,18 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make is
|
make
|
||||||
do
|
do
|
||||||
create object.make
|
create object.make
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
value: JSON_ARRAY
|
object: LINKED_LIST [detachable ANY]
|
||||||
|
|
||||||
object: LINKED_LIST [ANY]
|
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like value): like object is
|
from_json (j: like to_json): detachable like object
|
||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
do
|
do
|
||||||
@@ -43,18 +41,22 @@ feature -- Conversion
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): like value is
|
to_json (o: like object): JSON_ARRAY
|
||||||
local
|
local
|
||||||
c: LINKED_LIST_CURSOR [ANY]
|
c: ITERATION_CURSOR [detachable ANY]
|
||||||
do
|
do
|
||||||
create Result.make_array
|
create Result.make_array
|
||||||
from
|
from
|
||||||
o.start
|
c := o.new_cursor
|
||||||
until
|
until
|
||||||
o.after
|
c.after
|
||||||
loop
|
loop
|
||||||
Result.add (json.value (o.item))
|
if attached json.value (c.item) as v then
|
||||||
o.forth
|
Result.add (v)
|
||||||
|
else
|
||||||
|
check attached_value: False end
|
||||||
|
end
|
||||||
|
c.forth
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "Core factory class for creating JSON objects and corresponding Eiffel objects."
|
description: "Core factory class for creating JSON objects and corresponding Eiffel objects."
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date: $"
|
date: "$Date: $"
|
||||||
@@ -8,98 +8,73 @@ indexing
|
|||||||
class EJSON
|
class EJSON
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
{NONE} KL_EXCEPTIONS
|
{NONE} EXCEPTIONS
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
value (an_object: ?ANY): JSON_VALUE is
|
value (an_object: detachable ANY): detachable JSON_VALUE
|
||||||
-- JSON value from Eiffel object. Raises an "eJSON exception" if
|
-- JSON value from Eiffel object. Raises an "eJSON exception" if
|
||||||
-- unable to convert value.
|
-- unable to convert value.
|
||||||
local
|
local
|
||||||
b: BOOLEAN
|
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
i8: INTEGER_8
|
|
||||||
i16: INTEGER_16
|
|
||||||
i32: INTEGER_32
|
|
||||||
i64: INTEGER_64
|
|
||||||
n8: NATURAL_8
|
|
||||||
n16: NATURAL_16
|
|
||||||
n32: NATURAL_32
|
|
||||||
n64: NATURAL_64
|
|
||||||
r32: REAL_32
|
|
||||||
r64: REAL_64
|
|
||||||
a: ARRAY [ANY]
|
|
||||||
c: CHARACTER
|
|
||||||
s8: STRING_8
|
|
||||||
ucs: UC_STRING
|
|
||||||
ja: JSON_ARRAY
|
ja: JSON_ARRAY
|
||||||
jc: JSON_CONVERTER
|
|
||||||
do
|
do
|
||||||
-- Try to convert from basic Eiffel types. Note that we check with
|
-- Try to convert from basic Eiffel types. Note that we check with
|
||||||
-- `conforms_to' since the client may have subclassed the base class
|
-- `conforms_to' since the client may have subclassed the base class
|
||||||
-- that these basic types are derived from.
|
-- that these basic types are derived from.
|
||||||
if an_object = Void then
|
if an_object = Void then
|
||||||
create {JSON_NULL} Result
|
create {JSON_NULL} Result
|
||||||
elseif an_object.conforms_to (a_boolean) then
|
elseif attached {BOOLEAN} an_object as b then
|
||||||
b ?= an_object
|
|
||||||
create {JSON_BOOLEAN} Result.make_boolean (b)
|
create {JSON_BOOLEAN} Result.make_boolean (b)
|
||||||
elseif an_object.conforms_to (an_integer_8) then
|
elseif attached {INTEGER_8} an_object as i8 then
|
||||||
i8 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_integer (i8)
|
create {JSON_NUMBER} Result.make_integer (i8)
|
||||||
elseif an_object.conforms_to (an_integer_16) then
|
elseif attached {INTEGER_16} an_object as i16 then
|
||||||
i16 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_integer (i16)
|
create {JSON_NUMBER} Result.make_integer (i16)
|
||||||
elseif an_object.conforms_to (an_integer_32) then
|
elseif attached {INTEGER_32} an_object as i32 then
|
||||||
i32 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_integer (i32)
|
create {JSON_NUMBER} Result.make_integer (i32)
|
||||||
elseif an_object.conforms_to (an_integer_64) then
|
elseif attached {INTEGER_64} an_object as i64 then
|
||||||
i64 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_integer (i64)
|
create {JSON_NUMBER} Result.make_integer (i64)
|
||||||
elseif an_object.conforms_to (a_natural_8) then
|
elseif attached {NATURAL_8} an_object as n8 then
|
||||||
n8 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_natural (n8)
|
create {JSON_NUMBER} Result.make_natural (n8)
|
||||||
elseif an_object.conforms_to (a_natural_16) then
|
elseif attached {NATURAL_16} an_object as n16 then
|
||||||
n16 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_natural (n16)
|
create {JSON_NUMBER} Result.make_natural (n16)
|
||||||
elseif an_object.conforms_to (a_natural_32) then
|
elseif attached {NATURAL_32} an_object as n32 then
|
||||||
n32 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_natural (n32)
|
create {JSON_NUMBER} Result.make_natural (n32)
|
||||||
elseif an_object.conforms_to (a_natural_64) then
|
elseif attached {NATURAL_64} an_object as n64 then
|
||||||
n64 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_natural (n64)
|
create {JSON_NUMBER} Result.make_natural (n64)
|
||||||
elseif an_object.conforms_to (a_real_32) then
|
elseif attached {REAL_32} an_object as r32 then
|
||||||
r32 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_real (r32)
|
create {JSON_NUMBER} Result.make_real (r32)
|
||||||
elseif an_object.conforms_to (a_real_64) then
|
elseif attached {REAL_64} an_object as r64 then
|
||||||
r64 ?= an_object
|
|
||||||
create {JSON_NUMBER} Result.make_real (r64)
|
create {JSON_NUMBER} Result.make_real (r64)
|
||||||
elseif an_object.conforms_to (an_array) then
|
elseif attached {ARRAY [detachable ANY]} an_object as a then
|
||||||
a ?= an_object
|
|
||||||
create ja.make_array
|
create ja.make_array
|
||||||
from
|
from
|
||||||
i := a.lower
|
i := a.lower
|
||||||
until
|
until
|
||||||
i > a.upper
|
i > a.upper
|
||||||
loop
|
loop
|
||||||
ja.add (value (a @ i))
|
if attached value (a @ i) as v then
|
||||||
|
ja.add (v)
|
||||||
|
else
|
||||||
|
check value_attached: False end
|
||||||
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
Result := ja
|
Result := ja
|
||||||
elseif an_object.conforms_to (a_character) then
|
elseif attached {CHARACTER_8} an_object as c8 then
|
||||||
c ?= an_object
|
create {JSON_STRING} Result.make_json (c8.out)
|
||||||
create {JSON_STRING} Result.make_json (c.out)
|
elseif attached {CHARACTER_32} an_object as c32 then
|
||||||
elseif an_object.conforms_to (a_uc_string) then
|
create {JSON_STRING} Result.make_json (c32.out)
|
||||||
ucs ?= an_object
|
|
||||||
create {JSON_STRING} Result.make_json (ucs.to_utf8)
|
elseif attached {STRING_8} an_object as s8 then
|
||||||
elseif an_object.conforms_to (a_string_8) then
|
|
||||||
s8 ?= an_object
|
|
||||||
create {JSON_STRING} Result.make_json (s8)
|
create {JSON_STRING} Result.make_json (s8)
|
||||||
|
elseif attached {STRING_32} an_object as s32 then
|
||||||
|
create {JSON_STRING} Result.make_json (s32.as_string_8) -- FIXME: need correct convertion/encoding here ...
|
||||||
end
|
end
|
||||||
|
|
||||||
if Result = Void then
|
if Result = Void then
|
||||||
-- Now check the converters
|
-- Now check the converters
|
||||||
jc := converter_for (an_object)
|
if an_object /= Void and then attached converter_for (an_object) as jc then
|
||||||
if jc /= Void then
|
|
||||||
Result := jc.to_json (an_object)
|
Result := jc.to_json (an_object)
|
||||||
else
|
else
|
||||||
raise (exception_failed_to_convert_to_json (an_object))
|
raise (exception_failed_to_convert_to_json (an_object))
|
||||||
@@ -107,35 +82,29 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
object (a_value: JSON_VALUE; base_class: ?STRING): ANY is
|
object (a_value: detachable JSON_VALUE; base_class: detachable STRING): detachable ANY
|
||||||
-- Eiffel object from JSON value. If `base_class' /= Void an eiffel
|
-- Eiffel object from JSON value. If `base_class' /= Void an eiffel
|
||||||
-- object based on `base_class' will be returned. Raises an "eJSON
|
-- object based on `base_class' will be returned. Raises an "eJSON
|
||||||
-- exception" if unable to convert value.
|
-- exception" if unable to convert value.
|
||||||
require
|
|
||||||
a_value_not_void: a_value /= Void
|
|
||||||
local
|
local
|
||||||
jc: JSON_CONVERTER
|
|
||||||
jb: JSON_BOOLEAN
|
|
||||||
jn: JSON_NUMBER
|
|
||||||
js: JSON_STRING
|
|
||||||
ja: JSON_ARRAY
|
|
||||||
jo: JSON_OBJECT
|
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
ll: LINKED_LIST [ANY]
|
ll: LINKED_LIST [detachable ANY]
|
||||||
t: HASH_TABLE [ANY, UC_STRING]
|
t: HASH_TABLE [detachable ANY, STRING_GENERAL]
|
||||||
keys: ARRAY [JSON_STRING]
|
keys: ARRAY [JSON_STRING]
|
||||||
ucs: UC_STRING
|
s32: STRING_32
|
||||||
|
s: detachable STRING_GENERAL
|
||||||
do
|
do
|
||||||
if base_class = Void then
|
if a_value = Void then
|
||||||
if a_value.generator.is_equal ("JSON_NULL") then
|
|
||||||
Result := Void
|
Result := Void
|
||||||
elseif a_value.generator.is_equal ("JSON_BOOLEAN") then
|
else
|
||||||
jb ?= a_value
|
if base_class = Void then
|
||||||
check jb /= Void end
|
if a_value = Void then
|
||||||
|
Result := Void
|
||||||
|
elseif attached {JSON_NULL} a_value then
|
||||||
|
Result := Void
|
||||||
|
elseif attached {JSON_BOOLEAN} a_value as jb then
|
||||||
Result := jb.item
|
Result := jb.item
|
||||||
elseif a_value.generator.is_equal ("JSON_NUMBER") then
|
elseif attached {JSON_NUMBER} a_value as jn then
|
||||||
jn ?= a_value
|
|
||||||
check jn /= Void end
|
|
||||||
if jn.item.is_integer_8 then
|
if jn.item.is_integer_8 then
|
||||||
Result := jn.item.to_integer_8
|
Result := jn.item.to_integer_8
|
||||||
elseif jn.item.is_integer_16 then
|
elseif jn.item.is_integer_16 then
|
||||||
@@ -149,16 +118,12 @@ feature -- Access
|
|||||||
elseif jn.item.is_double then
|
elseif jn.item.is_double then
|
||||||
Result := jn.item.to_double
|
Result := jn.item.to_double
|
||||||
end
|
end
|
||||||
elseif a_value.generator.is_equal ("JSON_STRING") then
|
elseif attached {JSON_STRING} a_value as js then
|
||||||
js ?= a_value
|
create s32.make_from_string (js.item)
|
||||||
check js /= Void end
|
Result := s32
|
||||||
create ucs.make_from_string (js.item)
|
elseif attached {JSON_ARRAY} a_value as ja then
|
||||||
Result := ucs
|
|
||||||
elseif a_value.generator.is_equal ("JSON_ARRAY") then
|
|
||||||
ja ?= a_value
|
|
||||||
check ja /= Void end
|
|
||||||
from
|
from
|
||||||
create ll.make ()
|
create ll.make
|
||||||
i := 1
|
i := 1
|
||||||
until
|
until
|
||||||
i > ja.count
|
i > ja.count
|
||||||
@@ -167,9 +132,7 @@ feature -- Access
|
|||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
Result := ll
|
Result := ll
|
||||||
elseif a_value.generator.is_equal ("JSON_OBJECT") then
|
elseif attached {JSON_OBJECT} a_value as jo then
|
||||||
jo ?= a_value
|
|
||||||
check jo /= Void end
|
|
||||||
keys := jo.current_keys
|
keys := jo.current_keys
|
||||||
create t.make (keys.count)
|
create t.make (keys.count)
|
||||||
from
|
from
|
||||||
@@ -177,48 +140,50 @@ feature -- Access
|
|||||||
until
|
until
|
||||||
i > keys.upper
|
i > keys.upper
|
||||||
loop
|
loop
|
||||||
ucs ?= object (keys [i], Void)
|
s ?= object (keys [i], Void)
|
||||||
check ucs /= Void end
|
check s /= Void end
|
||||||
t.put (object (jo.item (keys [i]), Void), ucs)
|
t.put (object (jo.item (keys [i]), Void), s)
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
Result := t
|
Result := t
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if converters.has (base_class) then
|
if converters.has_key (base_class) and then attached converters.found_item as jc then
|
||||||
jc := converters @ base_class
|
|
||||||
Result := jc.from_json (a_value)
|
Result := jc.from_json (a_value)
|
||||||
else
|
else
|
||||||
raise (exception_failed_to_convert_to_eiffel (a_value, base_class))
|
raise (exception_failed_to_convert_to_eiffel (a_value, base_class))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
object_from_json (json: STRING; base_class: ?STRING): ANY is
|
object_from_json (json: STRING; base_class: detachable STRING): detachable ANY
|
||||||
-- Eiffel object from JSON representation. If `base_class' /= Void an
|
-- Eiffel object from JSON representation. If `base_class' /= Void an
|
||||||
-- Eiffel object based on `base_class' will be returned. Raises an
|
-- Eiffel object based on `base_class' will be returned. Raises an
|
||||||
-- "eJSON exception" if unable to convert value.
|
-- "eJSON exception" if unable to convert value.
|
||||||
require
|
require
|
||||||
json_not_void: json /= Void
|
json_not_void: json /= Void
|
||||||
local
|
local
|
||||||
jv: JSON_VALUE
|
jv: detachable JSON_VALUE
|
||||||
do
|
do
|
||||||
json_parser.set_representation (json)
|
json_parser.set_representation (json)
|
||||||
jv := json_parser.parse
|
jv := json_parser.parse
|
||||||
|
if jv /= Void then
|
||||||
Result := object (jv, base_class)
|
Result := object (jv, base_class)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
converter_for (an_object: ANY): JSON_CONVERTER is
|
converter_for (an_object: ANY): detachable JSON_CONVERTER
|
||||||
-- Converter for objects. Returns Void if none found.
|
-- Converter for objects. Returns Void if none found.
|
||||||
require
|
require
|
||||||
an_object_not_void: an_object /= Void
|
an_object_not_void: an_object /= Void
|
||||||
do
|
do
|
||||||
if converters.has (an_object.generator) then
|
if converters.has_key (an_object.generator) then
|
||||||
Result := converters @ an_object.generator
|
Result := converters.found_item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
json_reference (s: STRING): JSON_OBJECT is
|
json_reference (s: STRING): JSON_OBJECT
|
||||||
-- A JSON (Dojo style) reference object using `s' as the
|
-- A JSON (Dojo style) reference object using `s' as the
|
||||||
-- reference value. The caller is responsable for ensuring
|
-- reference value. The caller is responsable for ensuring
|
||||||
-- the validity of `s' as a json reference.
|
-- the validity of `s' as a json reference.
|
||||||
@@ -233,7 +198,7 @@ feature -- Access
|
|||||||
Result.put (js_value, js_key)
|
Result.put (js_value, js_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
json_references (l: DS_LIST [STRING]): JSON_ARRAY is
|
json_references (l: LIST [STRING]): JSON_ARRAY
|
||||||
-- A JSON array of JSON (Dojo style) reference objects using the
|
-- A JSON array of JSON (Dojo style) reference objects using the
|
||||||
-- strings in `l' as reference values. The caller is responsable
|
-- strings in `l' as reference values. The caller is responsable
|
||||||
-- for ensuring the validity of all strings in `l' as json
|
-- for ensuring the validity of all strings in `l' as json
|
||||||
@@ -241,12 +206,11 @@ feature -- Access
|
|||||||
require
|
require
|
||||||
l_not_void: l /= Void
|
l_not_void: l /= Void
|
||||||
local
|
local
|
||||||
c: DS_LIST_CURSOR [STRING]
|
c: ITERATION_CURSOR [STRING]
|
||||||
do
|
do
|
||||||
create Result.make_array
|
create Result.make_array
|
||||||
from
|
from
|
||||||
c := l.new_cursor
|
c := l.new_cursor
|
||||||
c.start
|
|
||||||
until
|
until
|
||||||
c.after
|
c.after
|
||||||
loop
|
loop
|
||||||
@@ -257,7 +221,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Change
|
feature -- Change
|
||||||
|
|
||||||
add_converter (jc: JSON_CONVERTER) is
|
add_converter (jc: JSON_CONVERTER)
|
||||||
-- Add the converter `jc'.
|
-- Add the converter `jc'.
|
||||||
require
|
require
|
||||||
jc_not_void: jc /= Void
|
jc_not_void: jc /= Void
|
||||||
@@ -269,7 +233,7 @@ feature -- Change
|
|||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
converters: DS_HASH_TABLE [JSON_CONVERTER, STRING] is
|
converters: HASH_TABLE [JSON_CONVERTER, STRING]
|
||||||
-- Converters hashed by generator (base class)
|
-- Converters hashed by generator (base class)
|
||||||
once
|
once
|
||||||
create Result.make (10)
|
create Result.make (10)
|
||||||
@@ -277,9 +241,9 @@ feature {NONE} -- Implementation
|
|||||||
|
|
||||||
feature {NONE} -- Implementation (Exceptions)
|
feature {NONE} -- Implementation (Exceptions)
|
||||||
|
|
||||||
exception_prefix: STRING is "eJSON exception: "
|
exception_prefix: STRING = "eJSON exception: "
|
||||||
|
|
||||||
exception_failed_to_convert_to_eiffel (a_value: JSON_VALUE; base_class: ?STRING): STRING is
|
exception_failed_to_convert_to_eiffel (a_value: JSON_VALUE; base_class: detachable STRING): STRING
|
||||||
-- Exception message for failing to convert a JSON_VALUE to an instance of `a'.
|
-- Exception message for failing to convert a JSON_VALUE to an instance of `a'.
|
||||||
do
|
do
|
||||||
Result := exception_prefix + "Failed to convert JSON_VALUE to an Eiffel object: " + a_value.generator
|
Result := exception_prefix + "Failed to convert JSON_VALUE to an Eiffel object: " + a_value.generator
|
||||||
@@ -288,15 +252,18 @@ feature {NONE} -- Implementation (Exceptions)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
exception_failed_to_convert_to_json (an_object: ?ANY): STRING is
|
exception_failed_to_convert_to_json (an_object: detachable ANY): STRING
|
||||||
-- Exception message for failing to convert `a' to a JSON_VALUE.
|
-- Exception message for failing to convert `a' to a JSON_VALUE.
|
||||||
do
|
do
|
||||||
Result := exception_prefix + "Failed to convert Eiffel object to a JSON_VALUE: " + an_object.generator
|
Result := exception_prefix + "Failed to convert Eiffel object to a JSON_VALUE"
|
||||||
|
if an_object /= Void then
|
||||||
|
Result := ": " + an_object.generator
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation (JSON parser)
|
feature {NONE} -- Implementation (JSON parser)
|
||||||
|
|
||||||
json_parser: JSON_PARSER is
|
json_parser: JSON_PARSER
|
||||||
once
|
once
|
||||||
create Result.make_parser ("")
|
create Result.make_parser ("")
|
||||||
end
|
end
|
||||||
@@ -325,21 +292,21 @@ feature {NONE} -- Implementation (Basic Eiffel objects)
|
|||||||
|
|
||||||
a_real_64: REAL_64
|
a_real_64: REAL_64
|
||||||
|
|
||||||
an_array: ARRAY [ANY] is
|
an_array: ARRAY [ANY]
|
||||||
once
|
once
|
||||||
Result := <<>>
|
Result := <<>>
|
||||||
end
|
end
|
||||||
|
|
||||||
a_character: CHARACTER
|
a_character: CHARACTER
|
||||||
|
|
||||||
a_string_8: STRING_8 is
|
a_string_8: STRING_8
|
||||||
once
|
once
|
||||||
Result := ""
|
Result := ""
|
||||||
end
|
end
|
||||||
|
|
||||||
a_uc_string: UC_STRING is
|
a_string_32: STRING_32
|
||||||
once
|
once
|
||||||
create Result.make_from_string ("")
|
Result := {STRING_32} ""
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class EJSON
|
end -- class EJSON
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "[
|
description: "[
|
||||||
JSON_ARRAY represent an array in JSON.
|
JSON_ARRAY represent an array in JSON.
|
||||||
An array in JSON is an ordered set of names.
|
An array in JSON is an ordered set of names.
|
||||||
@@ -25,7 +25,7 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make_array is
|
make_array
|
||||||
-- Initialize JSON Array
|
-- Initialize JSON Array
|
||||||
do
|
do
|
||||||
create values.make (10)
|
create values.make (10)
|
||||||
@@ -33,7 +33,7 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
i_th alias "[]" (i: INTEGER): JSON_VALUE is
|
i_th alias "[]" (i: INTEGER): JSON_VALUE
|
||||||
-- Item at `i'-th position
|
-- Item at `i'-th position
|
||||||
require
|
require
|
||||||
is_valid_index: valid_index (i)
|
is_valid_index: valid_index (i)
|
||||||
@@ -41,7 +41,7 @@ feature -- Access
|
|||||||
Result := values.i_th (i)
|
Result := values.i_th (i)
|
||||||
end
|
end
|
||||||
|
|
||||||
representation: STRING is
|
representation: STRING
|
||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
do
|
do
|
||||||
@@ -62,7 +62,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR) is
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_array' procedure on `a_visitor'.)
|
-- (Call `visit_json_array' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
@@ -71,7 +71,7 @@ feature -- Visitor pattern
|
|||||||
|
|
||||||
feature -- Mesurement
|
feature -- Mesurement
|
||||||
|
|
||||||
count: INTEGER is
|
count: INTEGER
|
||||||
-- Number of items.
|
-- Number of items.
|
||||||
do
|
do
|
||||||
Result := values.count
|
Result := values.count
|
||||||
@@ -79,7 +79,7 @@ feature -- Mesurement
|
|||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
valid_index (i: INTEGER): BOOLEAN is
|
valid_index (i: INTEGER): BOOLEAN
|
||||||
-- Is `i' a valid index?
|
-- Is `i' a valid index?
|
||||||
do
|
do
|
||||||
Result := (1 <= i) and (i <= count)
|
Result := (1 <= i) and (i <= count)
|
||||||
@@ -87,11 +87,11 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
|
|
||||||
add (value: JSON_VALUE) is
|
add (value: JSON_VALUE)
|
||||||
require
|
require
|
||||||
value_not_null: value /= void
|
value_not_null: value /= void
|
||||||
do
|
do
|
||||||
values.extend(value)
|
values.extend (value)
|
||||||
ensure
|
ensure
|
||||||
has_new_value: old values.count + 1 = values.count and
|
has_new_value: old values.count + 1 = values.count and
|
||||||
values.has (value)
|
values.has (value)
|
||||||
@@ -99,7 +99,7 @@ feature -- Change Element
|
|||||||
|
|
||||||
feature -- Report
|
feature -- Report
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
from
|
from
|
||||||
@@ -116,7 +116,7 @@ feature -- Report
|
|||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
array_representation: ARRAYED_LIST [JSON_VALUE] is
|
array_representation: ARRAYED_LIST [JSON_VALUE]
|
||||||
-- Representation as a sequences of values
|
-- Representation as a sequences of values
|
||||||
do
|
do
|
||||||
Result := values
|
Result := values
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "JSON Truth values"
|
description: "JSON Truth values"
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "2008/08/24"
|
date: "2008/08/24"
|
||||||
@@ -15,7 +15,7 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make_boolean (an_item: BOOLEAN) is
|
make_boolean (an_item: BOOLEAN)
|
||||||
--Initialize.
|
--Initialize.
|
||||||
do
|
do
|
||||||
item := an_item
|
item := an_item
|
||||||
@@ -26,13 +26,13 @@ feature -- Access
|
|||||||
item: BOOLEAN
|
item: BOOLEAN
|
||||||
-- Content
|
-- Content
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
Result := item.hash_code
|
Result := item.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
representation: STRING is
|
representation: STRING
|
||||||
do
|
do
|
||||||
if item then
|
if item then
|
||||||
Result := "true"
|
Result := "true"
|
||||||
@@ -43,7 +43,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR) is
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_boolean' procedure on `a_visitor'.)
|
-- (Call `visit_json_boolean' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "JSON Null Values"
|
description: "JSON Null Values"
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "2008/08/24"
|
date: "2008/08/24"
|
||||||
@@ -12,20 +12,20 @@ inherit
|
|||||||
|
|
||||||
feature --Access
|
feature --Access
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
Result := null_value.hash_code
|
Result := null_value.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
representation: STRING is
|
representation: STRING
|
||||||
do
|
do
|
||||||
Result := "null"
|
Result := "null"
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR) is
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_element_a' procedure on `a_visitor'.)
|
-- (Call `visit_element_a' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
@@ -42,6 +42,6 @@ feature -- Status report
|
|||||||
|
|
||||||
feature {NONE}-- Implementation
|
feature {NONE}-- Implementation
|
||||||
|
|
||||||
null_value: STRING is "null"
|
null_value: STRING = "null"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
|
|
||||||
description: "JSON Numbers, octal and hexadecimal formats are not used."
|
description: "JSON Numbers, octal and hexadecimal formats are not used."
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
@@ -22,21 +22,21 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- initialization
|
feature {NONE} -- initialization
|
||||||
|
|
||||||
make_integer (an_argument: INTEGER_64) is
|
make_integer (an_argument: INTEGER_64)
|
||||||
-- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'.
|
-- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'.
|
||||||
do
|
do
|
||||||
item := an_argument.out
|
item := an_argument.out
|
||||||
numeric_type := INTEGER_TYPE
|
numeric_type := INTEGER_TYPE
|
||||||
end
|
end
|
||||||
|
|
||||||
make_natural (an_argument: NATURAL_64) is
|
make_natural (an_argument: NATURAL_64)
|
||||||
-- Initialize an instance of JSON_NUMBER from the unsigned integer value of `an_argument'.
|
-- Initialize an instance of JSON_NUMBER from the unsigned integer value of `an_argument'.
|
||||||
do
|
do
|
||||||
item := an_argument.out
|
item := an_argument.out
|
||||||
numeric_type := NATURAL_TYPE
|
numeric_type := NATURAL_TYPE
|
||||||
end
|
end
|
||||||
|
|
||||||
make_real (an_argument: DOUBLE) is
|
make_real (an_argument: DOUBLE)
|
||||||
-- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'.
|
-- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'.
|
||||||
do
|
do
|
||||||
item := an_argument.out
|
item := an_argument.out
|
||||||
@@ -48,20 +48,20 @@ feature -- Access
|
|||||||
item: STRING
|
item: STRING
|
||||||
-- Content
|
-- Content
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER
|
||||||
--Hash code value
|
--Hash code value
|
||||||
do
|
do
|
||||||
Result := item.hash_code
|
Result := item.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
representation: STRING is
|
representation: STRING
|
||||||
do
|
do
|
||||||
Result := item
|
Result := item
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR) is
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_number' procedure on `a_visitor'.)
|
-- (Call `visit_json_number' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
@@ -70,7 +70,7 @@ feature -- Visitor pattern
|
|||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
is_equal (other: like Current): BOOLEAN is
|
is_equal (other: like Current): BOOLEAN
|
||||||
-- Is `other' attached to an object of the same type
|
-- Is `other' attached to an object of the same type
|
||||||
-- as current object and identical to it?
|
-- as current object and identical to it?
|
||||||
do
|
do
|
||||||
@@ -87,9 +87,9 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
|
|
||||||
INTEGER_TYPE: INTEGER is 1
|
INTEGER_TYPE: INTEGER = 1
|
||||||
DOUBLE_TYPE: INTEGER is 2
|
DOUBLE_TYPE: INTEGER = 2
|
||||||
NATURAL_TYPE: INTEGER is 3
|
NATURAL_TYPE: INTEGER = 3
|
||||||
|
|
||||||
numeric_type: INTEGER
|
numeric_type: INTEGER
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
|
|
||||||
description: "[
|
description: "[
|
||||||
An JSON_OBJECT represent an object in JSON.
|
An JSON_OBJECT represent an object in JSON.
|
||||||
@@ -27,7 +27,7 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make is
|
make
|
||||||
-- Initialize
|
-- Initialize
|
||||||
do
|
do
|
||||||
create object.make (10)
|
create object.make (10)
|
||||||
@@ -35,13 +35,13 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
|
|
||||||
put (value: ?JSON_VALUE; key: JSON_STRING) is
|
put (value: detachable JSON_VALUE; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
require
|
require
|
||||||
key_not_present: not has_key (key)
|
key_not_present: not has_key (key)
|
||||||
local
|
local
|
||||||
l_value: ?JSON_VALUE
|
l_value: detachable JSON_VALUE
|
||||||
do
|
do
|
||||||
l_value := value
|
l_value := value
|
||||||
if l_value = Void then
|
if l_value = Void then
|
||||||
@@ -52,31 +52,31 @@ feature -- Change Element
|
|||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
has_key (key: JSON_STRING): BOOLEAN is
|
has_key (key: JSON_STRING): BOOLEAN
|
||||||
-- has the JSON_OBJECT contains a specific key 'key'.
|
-- has the JSON_OBJECT contains a specific key 'key'.
|
||||||
do
|
do
|
||||||
Result := object.has (key)
|
Result := object.has (key)
|
||||||
end
|
end
|
||||||
|
|
||||||
has_item (value: JSON_VALUE): BOOLEAN is
|
has_item (value: JSON_VALUE): BOOLEAN
|
||||||
-- has the JSON_OBJECT contain a specfic item 'value'
|
-- has the JSON_OBJECT contain a specfic item 'value'
|
||||||
do
|
do
|
||||||
Result := object.has_item (value)
|
Result := object.has_item (value)
|
||||||
end
|
end
|
||||||
|
|
||||||
item (key: JSON_STRING): ?JSON_VALUE is
|
item (key: JSON_STRING): detachable JSON_VALUE
|
||||||
-- the json_value associated with a key.
|
-- the json_value associated with a key.
|
||||||
do
|
do
|
||||||
Result := object.item (key)
|
Result := object.item (key)
|
||||||
end
|
end
|
||||||
|
|
||||||
current_keys: ARRAY [JSON_STRING] is
|
current_keys: ARRAY [JSON_STRING]
|
||||||
-- array containing actually used keys
|
-- array containing actually used keys
|
||||||
do
|
do
|
||||||
Result := object.current_keys
|
Result := object.current_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
representation: STRING is
|
representation: STRING
|
||||||
local
|
local
|
||||||
t: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
t: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||||
do
|
do
|
||||||
@@ -100,7 +100,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR) is
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_object' procedure on `a_visitor'.)
|
-- (Call `visit_json_object' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
@@ -109,7 +109,7 @@ feature -- Visitor pattern
|
|||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING] is
|
map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||||
--A representation that maps keys to values
|
--A representation that maps keys to values
|
||||||
do
|
do
|
||||||
Result := object
|
Result := object
|
||||||
@@ -117,7 +117,7 @@ feature -- Conversion
|
|||||||
|
|
||||||
feature -- Report
|
feature -- Report
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
from
|
from
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
indexing
|
note
|
||||||
|
|
||||||
description:"[
|
description: "[
|
||||||
A JSON_STRING represent a string in JSON.
|
A JSON_STRING represent a string in JSON.
|
||||||
A string is a collection of zero or more Unicodes characters, wrapped in double
|
A string is a collection of zero or more Unicodes characters, wrapped in double
|
||||||
quotes, using blackslash espaces.
|
quotes, using blackslash espaces.
|
||||||
@@ -26,7 +26,7 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make_json (an_item: STRING) is
|
make_json (an_item: STRING)
|
||||||
-- Initialize.
|
-- Initialize.
|
||||||
require
|
require
|
||||||
item_not_void: an_item /= Void
|
item_not_void: an_item /= Void
|
||||||
@@ -39,7 +39,7 @@ feature -- Access
|
|||||||
item: STRING
|
item: STRING
|
||||||
-- Contents
|
-- Contents
|
||||||
|
|
||||||
representation: STRING is
|
representation: STRING
|
||||||
do
|
do
|
||||||
Result := "%""
|
Result := "%""
|
||||||
Result.append (item)
|
Result.append (item)
|
||||||
@@ -48,7 +48,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR) is
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_string' procedure on `a_visitor'.)
|
-- (Call `visit_json_string' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
@@ -57,7 +57,7 @@ feature -- Visitor pattern
|
|||||||
|
|
||||||
feature -- Comparison
|
feature -- Comparison
|
||||||
|
|
||||||
is_equal (other: like Current): BOOLEAN is
|
is_equal (other: like Current): BOOLEAN
|
||||||
-- Is JSON_STRING made of same character sequence as `other'
|
-- Is JSON_STRING made of same character sequence as `other'
|
||||||
-- (possibly with a different capacity)?
|
-- (possibly with a different capacity)?
|
||||||
do
|
do
|
||||||
@@ -66,7 +66,7 @@ feature -- Comparison
|
|||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
|
|
||||||
append (a_string: STRING)is
|
append (a_string: STRING)
|
||||||
-- Add an_item
|
-- Add an_item
|
||||||
require
|
require
|
||||||
a_string_not_void: a_string /= Void
|
a_string_not_void: a_string /= Void
|
||||||
@@ -76,7 +76,7 @@ feature -- Change Element
|
|||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
Result := item.hash_code
|
Result := item.hash_code
|
||||||
@@ -92,7 +92,7 @@ feature -- Status report
|
|||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
escaped_json_string (s: STRING): STRING is
|
escaped_json_string (s: STRING): STRING
|
||||||
-- JSON string with '"' and '\' characters escaped
|
-- JSON string with '"' and '\' characters escaped
|
||||||
require
|
require
|
||||||
s_not_void: s /= Void
|
s_not_void: s /= Void
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description:"[
|
description:"[
|
||||||
JSON_VALUE represent a value in JSON.
|
JSON_VALUE represent a value in JSON.
|
||||||
A value can be
|
A value can be
|
||||||
@@ -25,14 +25,14 @@ inherit
|
|||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
representation: STRING is
|
representation: STRING
|
||||||
-- UTF-8 encoded Unicode string representation of Current
|
-- UTF-8 encoded Unicode string representation of Current
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR) is
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_*' procedure on `a_visitor'.)
|
-- (Call `visit_*' procedure on `a_visitor'.)
|
||||||
require
|
require
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
|
|
||||||
description: "Parse serialized JSON data"
|
description: "Parse serialized JSON data"
|
||||||
author: "jvelilla"
|
author: "jvelilla"
|
||||||
@@ -17,7 +17,7 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialize
|
feature {NONE} -- Initialize
|
||||||
|
|
||||||
make_parser (a_json: STRING) is
|
make_parser (a_json: STRING)
|
||||||
-- Initialize.
|
-- Initialize.
|
||||||
require
|
require
|
||||||
json_not_empty: a_json /= Void and then not a_json.is_empty
|
json_not_empty: a_json /= Void and then not a_json.is_empty
|
||||||
@@ -51,7 +51,7 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Element change
|
feature -- Element change
|
||||||
|
|
||||||
report_error (e: STRING) is
|
report_error (e: STRING)
|
||||||
-- Report error `e'
|
-- Report error `e'
|
||||||
require
|
require
|
||||||
e_not_void: e /= Void
|
e_not_void: e /= Void
|
||||||
@@ -61,7 +61,7 @@ feature -- Element change
|
|||||||
|
|
||||||
feature -- Commands
|
feature -- Commands
|
||||||
|
|
||||||
parse_json: ?JSON_VALUE is
|
parse_json: detachable JSON_VALUE
|
||||||
-- Parse JSON data `representation'
|
-- Parse JSON data `representation'
|
||||||
-- start ::= object | array
|
-- start ::= object | array
|
||||||
do
|
do
|
||||||
@@ -76,7 +76,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parse: ?JSON_VALUE is
|
parse: detachable JSON_VALUE
|
||||||
-- Parse JSON data `representation'
|
-- Parse JSON data `representation'
|
||||||
local
|
local
|
||||||
c: CHARACTER
|
c: CHARACTER
|
||||||
@@ -121,14 +121,14 @@ feature -- Commands
|
|||||||
is_parsed_implies_result_not_void: is_parsed implies Result /= Void
|
is_parsed_implies_result_not_void: is_parsed implies Result /= Void
|
||||||
end
|
end
|
||||||
|
|
||||||
parse_object: JSON_OBJECT is
|
parse_object: JSON_OBJECT
|
||||||
-- object
|
-- object
|
||||||
-- {}
|
-- {}
|
||||||
-- {"key" : "value" [,]}
|
-- {"key" : "value" [,]}
|
||||||
local
|
local
|
||||||
has_more: BOOLEAN
|
has_more: BOOLEAN
|
||||||
l_json_string: ?JSON_STRING
|
l_json_string: detachable JSON_STRING
|
||||||
l_value: ?JSON_VALUE
|
l_value: detachable JSON_VALUE
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
-- check if is an empty object {}
|
-- check if is an empty object {}
|
||||||
@@ -174,7 +174,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parse_string: ?JSON_STRING is
|
parse_string: detachable JSON_STRING
|
||||||
-- Parsed string
|
-- Parsed string
|
||||||
local
|
local
|
||||||
has_more: BOOLEAN
|
has_more: BOOLEAN
|
||||||
@@ -200,7 +200,7 @@ feature -- Commands
|
|||||||
create l_unicode.make_from_string ("\u")
|
create l_unicode.make_from_string ("\u")
|
||||||
l_unicode.append (read_unicode)
|
l_unicode.append (read_unicode)
|
||||||
c := actual
|
c := actual
|
||||||
if is_a_valid_unicode (l_unicode) then
|
if is_valid_unicode (l_unicode) then
|
||||||
l_json_string.append (l_unicode)
|
l_json_string.append (l_unicode)
|
||||||
else
|
else
|
||||||
has_more := False
|
has_more := False
|
||||||
@@ -231,13 +231,13 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parse_array: JSON_ARRAY is
|
parse_array: JSON_ARRAY
|
||||||
-- array
|
-- array
|
||||||
-- []
|
-- []
|
||||||
-- [elements [,]]
|
-- [elements [,]]
|
||||||
local
|
local
|
||||||
flag: BOOLEAN
|
flag: BOOLEAN
|
||||||
l_value: ?JSON_VALUE
|
l_value: detachable JSON_VALUE
|
||||||
c: like actual
|
c: like actual
|
||||||
do
|
do
|
||||||
create Result.make_array
|
create Result.make_array
|
||||||
@@ -276,7 +276,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parse_number: ?JSON_NUMBER is
|
parse_number: detachable JSON_NUMBER
|
||||||
-- Parsed number
|
-- Parsed number
|
||||||
local
|
local
|
||||||
sb: STRING
|
sb: STRING
|
||||||
@@ -304,7 +304,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_a_valid_number (sb) then
|
if is_valid_number (sb) then
|
||||||
if sb.is_integer then
|
if sb.is_integer then
|
||||||
create Result.make_integer (sb.to_integer)
|
create Result.make_integer (sb.to_integer)
|
||||||
is_integer := True
|
is_integer := True
|
||||||
@@ -317,7 +317,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
is_null: BOOLEAN is
|
is_null: BOOLEAN
|
||||||
-- Word at index represents null?
|
-- Word at index represents null?
|
||||||
local
|
local
|
||||||
l_null: STRING
|
l_null: STRING
|
||||||
@@ -330,7 +330,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
is_false: BOOLEAN is
|
is_false: BOOLEAN
|
||||||
-- Word at index represents false?
|
-- Word at index represents false?
|
||||||
local
|
local
|
||||||
l_false: STRING
|
l_false: STRING
|
||||||
@@ -343,7 +343,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
is_true: BOOLEAN is
|
is_true: BOOLEAN
|
||||||
-- Word at index represents true?
|
-- Word at index represents true?
|
||||||
local
|
local
|
||||||
l_true: STRING
|
l_true: STRING
|
||||||
@@ -356,7 +356,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
read_unicode: STRING is
|
read_unicode: STRING
|
||||||
-- Read unicode and return value
|
-- Read unicode and return value
|
||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
@@ -375,27 +375,83 @@ feature -- Commands
|
|||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
is_a_valid_number (a_number: STRING): BOOLEAN is
|
is_valid_number (a_number: STRING): BOOLEAN
|
||||||
-- is 'a_number' a valid number based on this regular expression
|
-- is 'a_number' a valid number based on this regular expression
|
||||||
-- "-?(?: 0|[1-9]\d+)(?: \.\d+)?(?: [eE][+-]?\d+)?\b"?
|
-- "-?(?: 0|[1-9]\d+)(?: \.\d+)?(?: [eE][+-]?\d+)?\b"?
|
||||||
local
|
local
|
||||||
word_set: RX_CHARACTER_SET
|
s: detachable STRING
|
||||||
regexp: RX_PCRE_REGULAR_EXPRESSION
|
c: CHARACTER
|
||||||
number_regex: STRING
|
i,n: INTEGER
|
||||||
do
|
do
|
||||||
create regexp.make
|
create s.make_empty
|
||||||
create word_set.make_empty
|
n := a_number.count
|
||||||
a_number.right_adjust
|
if n = 0 then
|
||||||
a_number.left_adjust
|
Result := False
|
||||||
word_set.add_string ("0123456789.eE+-")
|
else
|
||||||
regexp.set_word_set (word_set)
|
Result := True
|
||||||
number_regex := "-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?\b"
|
i := 1
|
||||||
regexp.compile (number_regex)
|
--| "-?"
|
||||||
if regexp.matches (a_number) then
|
c := a_number[i]
|
||||||
Result := a_number.is_equal (regexp.captured_substring (0))
|
if c = '-' then
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
|
end
|
||||||
|
--| "0|[1-9]\d*
|
||||||
|
if c.is_digit then
|
||||||
|
if c = '0' then
|
||||||
|
--| "0"
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
|
else
|
||||||
|
--| "[1-9]"
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
|
--| "\d*"
|
||||||
|
from until i > n or not c.is_digit loop
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
is_a_valid_unicode (a_unicode: STRING): BOOLEAN is
|
end
|
||||||
|
end
|
||||||
|
if Result then
|
||||||
|
--| "(\.\d+)?"
|
||||||
|
if c = '.' then
|
||||||
|
--| "\.\d+" = "\.\d\d*"
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
|
if c.is_digit then
|
||||||
|
from until i > n or not c.is_digit loop
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := False --| expecting digit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if Result then --| "(?:[eE][+-]?\d+)?\b"
|
||||||
|
if c = 'e' or c = 'E' then
|
||||||
|
--| "[eE][+-]?\d+"
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
|
if c = '+' or c = '-' then
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
|
end
|
||||||
|
if c.is_digit then
|
||||||
|
from until i > n or not c.is_digit loop
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := False --| expecting digit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if Result then --| "\b"
|
||||||
|
from until i > n or not c.is_space loop
|
||||||
|
s.extend (c); i := i + 1; c := a_number[i]
|
||||||
|
end
|
||||||
|
Result := i > n
|
||||||
|
if Result then
|
||||||
|
Result := s.same_string (a_number)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
is_valid_unicode (a_unicode: STRING): BOOLEAN
|
||||||
-- is 'a_unicode' a valid unicode based on this regular expression
|
-- is 'a_unicode' a valid unicode based on this regular expression
|
||||||
-- "\\u[0-9a-fA-F]{4}"
|
-- "\\u[0-9a-fA-F]{4}"
|
||||||
local
|
local
|
||||||
@@ -423,7 +479,7 @@ feature {NONE} -- Implementation
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
extra_elements: BOOLEAN is
|
extra_elements: BOOLEAN
|
||||||
-- has more elements?
|
-- has more elements?
|
||||||
local
|
local
|
||||||
c: like actual
|
c: like actual
|
||||||
@@ -449,11 +505,11 @@ feature {NONE} -- Implementation
|
|||||||
|
|
||||||
feature {NONE} -- Constants
|
feature {NONE} -- Constants
|
||||||
|
|
||||||
false_id: STRING is "false"
|
false_id: STRING = "false"
|
||||||
|
|
||||||
true_id: STRING is "true"
|
true_id: STRING = "true"
|
||||||
|
|
||||||
null_id: STRING is "null"
|
null_id: STRING = "null"
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "Objects that ..."
|
description: "Objects that ..."
|
||||||
author: "jvelilla"
|
author: "jvelilla"
|
||||||
date: "2008/08/24"
|
date: "2008/08/24"
|
||||||
@@ -12,7 +12,7 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_json: STRING) is
|
make (a_json: STRING)
|
||||||
-- Initialize Reader
|
-- Initialize Reader
|
||||||
do
|
do
|
||||||
set_representation (a_json)
|
set_representation (a_json)
|
||||||
@@ -20,7 +20,7 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
feature -- Commands
|
feature -- Commands
|
||||||
|
|
||||||
set_representation (a_json: STRING) is
|
set_representation (a_json: STRING)
|
||||||
-- Set `representation'.
|
-- Set `representation'.
|
||||||
do
|
do
|
||||||
a_json.left_adjust
|
a_json.left_adjust
|
||||||
@@ -29,7 +29,7 @@ feature -- Commands
|
|||||||
index := 1
|
index := 1
|
||||||
end
|
end
|
||||||
|
|
||||||
read: CHARACTER is
|
read: CHARACTER
|
||||||
-- Read character
|
-- Read character
|
||||||
do
|
do
|
||||||
if not representation.is_empty then
|
if not representation.is_empty then
|
||||||
@@ -37,7 +37,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
next is
|
next
|
||||||
-- Move to next index
|
-- Move to next index
|
||||||
require
|
require
|
||||||
has_more_elements: has_next
|
has_more_elements: has_next
|
||||||
@@ -47,7 +47,7 @@ feature -- Commands
|
|||||||
incremented: old index + 1 = index
|
incremented: old index + 1 = index
|
||||||
end
|
end
|
||||||
|
|
||||||
previous is
|
previous
|
||||||
-- Move to previous index
|
-- Move to previous index
|
||||||
require
|
require
|
||||||
not_is_first: has_previous
|
not_is_first: has_previous
|
||||||
@@ -57,7 +57,7 @@ feature -- Commands
|
|||||||
incremented: old index - 1 = index
|
incremented: old index - 1 = index
|
||||||
end
|
end
|
||||||
|
|
||||||
skip_white_spaces is
|
skip_white_spaces
|
||||||
-- Remove white spaces
|
-- Remove white spaces
|
||||||
local
|
local
|
||||||
c: like actual
|
c: like actual
|
||||||
@@ -72,7 +72,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
json_substring (start_index, end_index: INTEGER_32): STRING is
|
json_substring (start_index, end_index: INTEGER_32): STRING
|
||||||
-- JSON representation between `start_index' and `end_index'
|
-- JSON representation between `start_index' and `end_index'
|
||||||
do
|
do
|
||||||
Result := representation.substring (start_index, end_index)
|
Result := representation.substring (start_index, end_index)
|
||||||
@@ -80,13 +80,13 @@ feature -- Commands
|
|||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
has_next: BOOLEAN is
|
has_next: BOOLEAN
|
||||||
-- Has a next character?
|
-- Has a next character?
|
||||||
do
|
do
|
||||||
Result := index <= representation.count
|
Result := index <= representation.count
|
||||||
end
|
end
|
||||||
|
|
||||||
has_previous: BOOLEAN is
|
has_previous: BOOLEAN
|
||||||
-- Has a previous character?
|
-- Has a previous character?
|
||||||
do
|
do
|
||||||
Result := index >= 1
|
Result := index >= 1
|
||||||
@@ -99,7 +99,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
actual: CHARACTER is
|
actual: CHARACTER
|
||||||
-- Current character or '%U' if none
|
-- Current character or '%U' if none
|
||||||
do
|
do
|
||||||
if index > representation.count then
|
if index > representation.count then
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: ""
|
description: ""
|
||||||
author: "jvelilla"
|
author: "jvelilla"
|
||||||
date: "2008/08/24"
|
date: "2008/08/24"
|
||||||
@@ -9,19 +9,19 @@ class
|
|||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
j_OBJECT_OPEN: CHARACTER is '{'
|
j_OBJECT_OPEN: CHARACTER = '{'
|
||||||
j_ARRAY_OPEN: CHARACTER is '['
|
j_ARRAY_OPEN: CHARACTER = '['
|
||||||
j_OBJECT_CLOSE: CHARACTER is '}'
|
j_OBJECT_CLOSE: CHARACTER = '}'
|
||||||
j_ARRAY_CLOSE: CHARACTER is ']'
|
j_ARRAY_CLOSE: CHARACTER = ']'
|
||||||
|
|
||||||
j_STRING: CHARACTER is '"'
|
j_STRING: CHARACTER = '"'
|
||||||
j_PLUS: CHARACTER is '+'
|
j_PLUS: CHARACTER = '+'
|
||||||
j_MINUS: CHARACTER is '-'
|
j_MINUS: CHARACTER = '-'
|
||||||
j_DOT: CHARACTER is '.'
|
j_DOT: CHARACTER = '.'
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
is_open_token (c: CHARACTER): BOOLEAN is
|
is_open_token (c: CHARACTER): BOOLEAN
|
||||||
-- Characters which open a type
|
-- Characters which open a type
|
||||||
do
|
do
|
||||||
inspect c
|
inspect c
|
||||||
@@ -32,7 +32,7 @@ feature -- Status report
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
is_close_token (c: CHARACTER): BOOLEAN is
|
is_close_token (c: CHARACTER): BOOLEAN
|
||||||
-- Characters which close a type
|
-- Characters which close a type
|
||||||
do
|
do
|
||||||
inspect c
|
inspect c
|
||||||
@@ -43,7 +43,7 @@ feature -- Status report
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
is_special_character (c: CHARACTER): BOOLEAN is
|
is_special_character (c: CHARACTER): BOOLEAN
|
||||||
-- Control Characters
|
-- Control Characters
|
||||||
-- %F Form feed
|
-- %F Form feed
|
||||||
-- %H backslasH
|
-- %H backslasH
|
||||||
@@ -62,7 +62,7 @@ feature -- Status report
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
is_special_control (c: CHARACTER): BOOLEAN is
|
is_special_control (c: CHARACTER): BOOLEAN
|
||||||
--Control Characters
|
--Control Characters
|
||||||
-- \b\f\n\r\t
|
-- \b\f\n\r\t
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
indexing
|
note
|
||||||
description: "[
|
description: "[
|
||||||
Shared factory class for creating JSON objects. Maps JSON
|
Shared factory class for creating JSON objects. Maps JSON
|
||||||
objects to ELKS HASH_TABLEs and JSON arrays to ELKS
|
objects to ELKS HASH_TABLEs and JSON arrays to ELKS
|
||||||
@@ -15,7 +15,7 @@ class SHARED_EJSON
|
|||||||
|
|
||||||
feature
|
feature
|
||||||
|
|
||||||
json: EJSON is
|
json: EJSON
|
||||||
-- A shared EJSON instance with default converters for
|
-- A shared EJSON instance with default converters for
|
||||||
-- DS_LINKED_LIST [ANY] and DS_HASH_TABLE [ANY, HASHABLE]
|
-- DS_LINKED_LIST [ANY] and DS_HASH_TABLE [ANY, HASHABLE]
|
||||||
local
|
local
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ feature {NONE} -- Events
|
|||||||
|
|
||||||
feature -- Tests Pass
|
feature -- Tests Pass
|
||||||
|
|
||||||
test_json_pass1 is
|
test_json_pass1
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir + "pass1.json")
|
json_file:=file_reader.read_json_from (test_dir + "pass1.json")
|
||||||
@@ -36,7 +36,7 @@ feature -- Tests Pass
|
|||||||
assert ("pass1.json",parse_json.is_parsed = True)
|
assert ("pass1.json",parse_json.is_parsed = True)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_pass2 is
|
test_json_pass2
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"pass2.json")
|
json_file:=file_reader.read_json_from (test_dir +"pass2.json")
|
||||||
@@ -45,7 +45,7 @@ feature -- Tests Pass
|
|||||||
assert ("pass2.json",parse_json.is_parsed = True)
|
assert ("pass2.json",parse_json.is_parsed = True)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_pass3 is
|
test_json_pass3
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"pass3.json")
|
json_file:=file_reader.read_json_from (test_dir +"pass3.json")
|
||||||
@@ -55,7 +55,7 @@ feature -- Tests Pass
|
|||||||
end
|
end
|
||||||
|
|
||||||
feature -- Tests Failures
|
feature -- Tests Failures
|
||||||
test_json_fail1 is
|
test_json_fail1
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail1.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail1.json")
|
||||||
@@ -64,7 +64,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail1.json",parse_json.is_parsed = False)
|
assert ("fail1.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail2 is
|
test_json_fail2
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail2.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail2.json")
|
||||||
@@ -73,7 +73,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail2.json",parse_json.is_parsed = False)
|
assert ("fail2.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail3 is
|
test_json_fail3
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail3.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail3.json")
|
||||||
@@ -82,7 +82,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail3.json",parse_json.is_parsed = False)
|
assert ("fail3.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail4 is
|
test_json_fail4
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail4.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail4.json")
|
||||||
@@ -91,7 +91,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail4.json",parse_json.is_parsed = False)
|
assert ("fail4.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail5 is
|
test_json_fail5
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail5.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail5.json")
|
||||||
@@ -101,7 +101,7 @@ feature -- Tests Failures
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail6 is
|
test_json_fail6
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail6.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail6.json")
|
||||||
@@ -110,7 +110,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail6.json",parse_json.is_parsed = False )
|
assert ("fail6.json",parse_json.is_parsed = False )
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail7 is
|
test_json_fail7
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail7.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail7.json")
|
||||||
@@ -119,7 +119,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail7.json",parse_json.is_parsed = False)
|
assert ("fail7.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail8 is
|
test_json_fail8
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail8.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail8.json")
|
||||||
@@ -129,7 +129,7 @@ feature -- Tests Failures
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail9 is
|
test_json_fail9
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail9.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail9.json")
|
||||||
@@ -139,7 +139,7 @@ feature -- Tests Failures
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail10 is
|
test_json_fail10
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail10.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail10.json")
|
||||||
@@ -148,7 +148,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail10.json",parse_json.is_parsed = False)
|
assert ("fail10.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail11 is
|
test_json_fail11
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail11.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail11.json")
|
||||||
@@ -157,7 +157,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail11.json",parse_json.is_parsed = False)
|
assert ("fail11.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail12 is
|
test_json_fail12
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail12.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail12.json")
|
||||||
@@ -166,7 +166,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail12.json",parse_json.is_parsed = False)
|
assert ("fail12.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail13 is
|
test_json_fail13
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail13.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail13.json")
|
||||||
@@ -175,7 +175,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail13.json",parse_json.is_parsed = False)
|
assert ("fail13.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail14 is
|
test_json_fail14
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail14.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail14.json")
|
||||||
@@ -184,7 +184,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail14.json",parse_json.is_parsed = False)
|
assert ("fail14.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail15 is
|
test_json_fail15
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail15.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail15.json")
|
||||||
@@ -193,7 +193,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail15.json",parse_json.is_parsed = False)
|
assert ("fail15.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail16 is
|
test_json_fail16
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail16.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail16.json")
|
||||||
@@ -202,7 +202,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail16.json",parse_json.is_parsed = False)
|
assert ("fail16.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail17 is
|
test_json_fail17
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail17.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail17.json")
|
||||||
@@ -211,7 +211,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail17.json",parse_json.is_parsed = False)
|
assert ("fail17.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail18 is
|
test_json_fail18
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail18.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail18.json")
|
||||||
@@ -220,7 +220,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail18.json",parse_json.is_parsed = True)
|
assert ("fail18.json",parse_json.is_parsed = True)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail19 is
|
test_json_fail19
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail19.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail19.json")
|
||||||
@@ -229,7 +229,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail19.json",parse_json.is_parsed = False)
|
assert ("fail19.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail20 is
|
test_json_fail20
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail20.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail20.json")
|
||||||
@@ -238,7 +238,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail20.json",parse_json.is_parsed = False)
|
assert ("fail20.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail21 is
|
test_json_fail21
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail21.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail21.json")
|
||||||
@@ -248,7 +248,7 @@ feature -- Tests Failures
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail22 is
|
test_json_fail22
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail22.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail22.json")
|
||||||
@@ -257,7 +257,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail22.json",parse_json.is_parsed = False)
|
assert ("fail22.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail23 is
|
test_json_fail23
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail23.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail23.json")
|
||||||
@@ -266,7 +266,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail23.json",parse_json.is_parsed = False)
|
assert ("fail23.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail24 is
|
test_json_fail24
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail24.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail24.json")
|
||||||
@@ -275,7 +275,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail24.json",parse_json.is_parsed = False)
|
assert ("fail24.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail25 is
|
test_json_fail25
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail25.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail25.json")
|
||||||
@@ -285,7 +285,7 @@ feature -- Tests Failures
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail26 is
|
test_json_fail26
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail26.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail26.json")
|
||||||
@@ -295,7 +295,7 @@ feature -- Tests Failures
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail27 is
|
test_json_fail27
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail27.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail27.json")
|
||||||
@@ -305,7 +305,7 @@ feature -- Tests Failures
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail28 is
|
test_json_fail28
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail28.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail28.json")
|
||||||
@@ -315,7 +315,7 @@ feature -- Tests Failures
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail29 is
|
test_json_fail29
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail29.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail29.json")
|
||||||
@@ -325,7 +325,7 @@ feature -- Tests Failures
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail30 is
|
test_json_fail30
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail30.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail30.json")
|
||||||
@@ -334,7 +334,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail30.json",parse_json.is_parsed = False)
|
assert ("fail30.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail31 is
|
test_json_fail31
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail31.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail31.json")
|
||||||
@@ -343,7 +343,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail31.json",parse_json.is_parsed = False)
|
assert ("fail31.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail32 is
|
test_json_fail32
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail32.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail32.json")
|
||||||
@@ -352,7 +352,7 @@ feature -- Tests Failures
|
|||||||
assert ("fail32.json",parse_json.is_parsed = False)
|
assert ("fail32.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail33 is
|
test_json_fail33
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
json_file:=file_reader.read_json_from (test_dir +"fail33.json")
|
json_file:=file_reader.read_json_from (test_dir +"fail33.json")
|
||||||
@@ -360,15 +360,36 @@ feature -- Tests Failures
|
|||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail33.json",parse_json.is_parsed = False)
|
assert ("fail33.json",parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- JSON_FROM_FILE
|
feature -- JSON_FROM_FILE
|
||||||
|
|
||||||
json_file:STRING
|
json_file : STRING
|
||||||
parse_json:JSON_PARSER
|
parse_json : JSON_PARSER
|
||||||
json_object:JSON_OBJECT
|
json_object : JSON_OBJECT
|
||||||
file_reader:JSON_FILE_READER
|
file_reader : JSON_FILE_READER
|
||||||
json_value : JSON_VALUE
|
json_value : JSON_VALUE
|
||||||
test_dir : STRING is "/home/jvelilla/work/project/Eiffel/ejson_dev/trunk/test/autotest/test_suite/"
|
test_dir : STRING
|
||||||
|
local
|
||||||
|
i: INTEGER
|
||||||
|
do
|
||||||
|
Result := (create {EXECUTION_ENVIRONMENT}).current_working_directory
|
||||||
|
Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
|
||||||
|
-- The should looks like
|
||||||
|
-- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json
|
||||||
|
from
|
||||||
|
i := 5
|
||||||
|
until
|
||||||
|
i = 0
|
||||||
|
loop
|
||||||
|
Result.append_character ('.')
|
||||||
|
Result.append_character ('.')
|
||||||
|
Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
|
||||||
|
i := i - 1
|
||||||
|
end
|
||||||
|
-- Result := "/home/jvelilla/work/project/Eiffel/ejson_dev/trunk/test/autotest/test_suite/"
|
||||||
|
end
|
||||||
|
invariant
|
||||||
|
file_reader /= Void
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
19
test/autotest/test_suite/test_suite-safe.ecf
Normal file
19
test/autotest/test_suite/test_suite-safe.ecf
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="test_suite" uuid="EA141B17-6A21-4781-8B5F-E9939BAE968A">
|
||||||
|
<target name="test_suite">
|
||||||
|
<root cluster="test_suite" class="APPLICATION" feature="make"/>
|
||||||
|
<option warning="true" void_safety="all" syntax="standard">
|
||||||
|
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||||
|
</option>
|
||||||
|
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||||
|
<library name="json" location="..\..\..\library\json-safe.ecf"/>
|
||||||
|
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||||
|
<cluster name="test_suite" location=".\" recursive="true">
|
||||||
|
<file_rule>
|
||||||
|
<exclude>/EIFGENs$</exclude>
|
||||||
|
<exclude>/CVS$</exclude>
|
||||||
|
<exclude>/.svn$</exclude>
|
||||||
|
</file_rule>
|
||||||
|
</cluster>
|
||||||
|
</target>
|
||||||
|
</system>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-5-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-5-0 http://www.eiffel.com/developers/xml/configuration-1-5-0.xsd" name="test_suite" uuid="EA141B17-6A21-4781-8B5F-E9939BAE968A">
|
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-5-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-5-0 http://www.eiffel.com/developers/xml/configuration-1-5-0.xsd" name="test_suite" uuid="EA141B17-6A21-4781-8B5F-E9939BAE968A">
|
||||||
<target name="test_suite">
|
<target name="test_suite">
|
||||||
<root class="APPLICATION" feature="make"/>
|
<root cluster="test_suite" class="APPLICATION" feature="make"/>
|
||||||
<option warning="true">
|
<option warning="true">
|
||||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user