Reformatted code to Gobo standard.
This commit is contained in:
@@ -52,8 +52,6 @@ feature -- Change Element
|
|||||||
add(value:JSON_VALUE) is
|
add(value:JSON_VALUE) is
|
||||||
require
|
require
|
||||||
not_null:value /= void
|
not_null:value /= void
|
||||||
local
|
|
||||||
l_json_value:JSON_VALUE
|
|
||||||
do
|
do
|
||||||
values.extend(value)
|
values.extend(value)
|
||||||
ensure
|
ensure
|
||||||
|
|||||||
@@ -5,36 +5,40 @@ indexing
|
|||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
|
|
||||||
JSON_BOOLEAN
|
JSON_BOOLEAN
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_VALUE
|
JSON_VALUE
|
||||||
|
|
||||||
create
|
create
|
||||||
|
|
||||||
make_boolean
|
make_boolean
|
||||||
|
|
||||||
feature -- Initialization
|
feature -- Initialization
|
||||||
|
|
||||||
make_boolean(a_value:BOOLEAN) is
|
make_boolean (an_item: BOOLEAN) is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
value:=a_value
|
item := an_item
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
|
item: BOOLEAN
|
||||||
|
|
||||||
to_json: STRING is
|
to_json: STRING is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
Result:=value.out
|
Result := item.out
|
||||||
end
|
end
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
Result:=value.hash_code
|
Result := item.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
value:BOOLEAN
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
indexing
|
indexing
|
||||||
|
|
||||||
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"
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
@@ -7,36 +8,38 @@ indexing
|
|||||||
|
|
||||||
class
|
class
|
||||||
JSON_NUMBER
|
JSON_NUMBER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
JSON_VALUE
|
JSON_VALUE
|
||||||
rename is_equal as is_equal_json_value
|
rename
|
||||||
|
is_equal as is_equal_json_value
|
||||||
end
|
end
|
||||||
create
|
create
|
||||||
|
|
||||||
make_integer,
|
make_integer,
|
||||||
make_real
|
make_real
|
||||||
|
|
||||||
feature -- initialization
|
feature -- initialization
|
||||||
|
|
||||||
make_integer (argument: INTEGER) is
|
make_integer (argument: INTEGER) is
|
||||||
do
|
do
|
||||||
value:= argument.out
|
item:= argument.out
|
||||||
internal_hash_code:=argument.hash_code
|
internal_hash_code:=argument.hash_code
|
||||||
numeric_type:= "INTEGER"
|
numeric_type:= "INTEGER"
|
||||||
end
|
end
|
||||||
|
|
||||||
make_real (argument: REAL) is
|
make_real (argument: REAL) is
|
||||||
do
|
do
|
||||||
value:= argument.out
|
item:= argument.out
|
||||||
internal_hash_code:=argument.hash_code
|
internal_hash_code:=argument.hash_code
|
||||||
numeric_type:= "REAL"
|
numeric_type:= "REAL"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
to_json:STRING is
|
|
||||||
--
|
item: STRING
|
||||||
do
|
|
||||||
Result:=value
|
|
||||||
end
|
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER is
|
||||||
--
|
--
|
||||||
@@ -45,16 +48,33 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
feature -- Status
|
||||||
|
|
||||||
is_equal (other: like Current): BOOLEAN is
|
is_equal (other: like Current): BOOLEAN is
|
||||||
-- 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
|
||||||
Result:=value.is_equal(other.to_json)
|
Result:=item.is_equal (other.to_json)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Conversion
|
||||||
|
|
||||||
|
to_json: STRING is
|
||||||
|
--
|
||||||
|
do
|
||||||
|
Result := item
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
value:STRING
|
|
||||||
internal_hash_code: INTEGER
|
internal_hash_code: INTEGER
|
||||||
|
|
||||||
numeric_type: STRING -- REAL or INTEGER
|
numeric_type: STRING -- REAL or INTEGER
|
||||||
|
|
||||||
|
|
||||||
|
invariant
|
||||||
|
|
||||||
|
item_not_void: item /= Void
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
indexing
|
indexing
|
||||||
|
|
||||||
description: "[
|
description: "[
|
||||||
An JSON_OBJECT represent an object in JSON.
|
An JSON_OBJECT represent an object in JSON.
|
||||||
An object is an unordered set of name/value pairs
|
An object is an unordered set of name/value pairs
|
||||||
@@ -18,15 +19,19 @@ indexing
|
|||||||
|
|
||||||
|
|
||||||
class
|
class
|
||||||
|
|
||||||
JSON_OBJECT
|
JSON_OBJECT
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
JSON_VALUE
|
JSON_VALUE
|
||||||
|
|
||||||
create
|
create
|
||||||
|
|
||||||
make
|
make
|
||||||
|
|
||||||
feature -- Initialization
|
feature -- Initialization
|
||||||
|
|
||||||
make is
|
make is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
@@ -55,6 +60,7 @@ feature -- Change Element
|
|||||||
|
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
has_key (key: JSON_STRING):BOOLEAN is
|
has_key (key: JSON_STRING):BOOLEAN is
|
||||||
-- has the JSON_OBJECT contains a specific key 'key'.
|
-- has the JSON_OBJECT contains a specific key 'key'.
|
||||||
do
|
do
|
||||||
@@ -81,6 +87,7 @@ feature -- Access
|
|||||||
|
|
||||||
|
|
||||||
feature -- Report
|
feature -- Report
|
||||||
|
|
||||||
to_json: STRING is
|
to_json: STRING is
|
||||||
-- Printable json representation
|
-- Printable json representation
|
||||||
-- {} or {member}
|
-- {} or {member}
|
||||||
@@ -104,8 +111,6 @@ feature -- Report
|
|||||||
Result.append ("}")
|
Result.append ("}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER is
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
local
|
local
|
||||||
@@ -125,5 +130,7 @@ feature -- Report
|
|||||||
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
object: HASH_TABLE[JSON_VALUE,JSON_STRING]
|
object: HASH_TABLE[JSON_VALUE,JSON_STRING]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
indexing
|
indexing
|
||||||
|
|
||||||
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
|
||||||
@@ -10,28 +11,41 @@ indexing
|
|||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
|
|
||||||
|
|
||||||
class
|
class
|
||||||
|
|
||||||
JSON_STRING
|
JSON_STRING
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
JSON_VALUE
|
JSON_VALUE
|
||||||
redefine
|
redefine
|
||||||
is_equal
|
is_equal
|
||||||
end
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
|
|
||||||
make_json
|
make_json
|
||||||
|
|
||||||
feature -- Initialization
|
feature -- Initialization
|
||||||
make_json(value:STRING) is
|
|
||||||
--
|
make_json (an_item: STRING) is
|
||||||
|
-- Initialize.
|
||||||
|
require
|
||||||
|
item_not_void: an_item /= Void
|
||||||
do
|
do
|
||||||
create buffer.make(256)
|
item := an_item
|
||||||
buffer.append (value)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
|
item: STRING
|
||||||
|
-- Contents
|
||||||
|
|
||||||
|
|
||||||
feature -- Comparison
|
feature -- Comparison
|
||||||
|
|
||||||
is_equal (other: like Current): BOOLEAN is
|
is_equal (other: like Current): BOOLEAN is
|
||||||
-- 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)?
|
||||||
@@ -40,29 +54,33 @@ feature -- Comparison
|
|||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
append(value:STRING)is
|
|
||||||
|
append (an_item: STRING)is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
buffer.append (value)
|
item.append_string (an_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
to_json: STRING is
|
to_json: STRING is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
create Result.make_empty
|
create Result.make_empty
|
||||||
Result.append ("%"")
|
Result.append ("%"")
|
||||||
Result.append (buffer)
|
Result.append (item)
|
||||||
Result.append ("%"")
|
Result.append ("%"")
|
||||||
end
|
end
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
Result:= buffer.hash_code + buffer.count
|
Result := item.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
invariant
|
||||||
buffer:STRING
|
|
||||||
|
value_not_void: item /= Void
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,29 +1,42 @@
|
|||||||
indexing
|
indexing
|
||||||
description: "Objects that ..."
|
|
||||||
|
description: "Parse serialized JSON data"
|
||||||
author: ""
|
author: ""
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
|
|
||||||
JSON_PARSER
|
JSON_PARSER
|
||||||
inherit
|
inherit
|
||||||
JSON_READER
|
JSON_READER
|
||||||
JSON_TOKENS
|
JSON_TOKENS
|
||||||
|
|
||||||
create
|
create
|
||||||
|
|
||||||
make_parser
|
make_parser
|
||||||
|
|
||||||
|
feature {NONE} -- Initialize
|
||||||
|
|
||||||
|
make_parser (a_json: STRING) is
|
||||||
|
-- Initialize.
|
||||||
|
require
|
||||||
|
json_not_empty: a_json /= Void and then not a_json.is_empty
|
||||||
|
do
|
||||||
|
make (a_json)
|
||||||
|
is_parsed := True
|
||||||
|
create current_errors.make_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
is_parsed: BOOLEAN
|
is_parsed: BOOLEAN
|
||||||
|
|
||||||
current_errors: STRING
|
current_errors: STRING
|
||||||
|
|
||||||
make_parser(a_json:STRING) is
|
|
||||||
--
|
feature -- Commands
|
||||||
do
|
|
||||||
make(a_json)
|
|
||||||
is_parsed:=true
|
|
||||||
create current_errors.make_empty
|
|
||||||
end
|
|
||||||
|
|
||||||
parse_json: JSON_VALUE is
|
parse_json: JSON_VALUE is
|
||||||
--
|
--
|
||||||
@@ -53,13 +66,13 @@ feature -- Access
|
|||||||
elseif is_null then
|
elseif is_null then
|
||||||
--
|
--
|
||||||
Result := create {JSON_NULL}
|
Result := create {JSON_NULL}
|
||||||
next;next;next;
|
next;next;next
|
||||||
elseif is_true then
|
elseif is_true then
|
||||||
Result := create {JSON_BOOLEAN}.make_boolean (true)
|
Result := create {JSON_BOOLEAN}.make_boolean (true)
|
||||||
next;next;next;
|
next;next;next
|
||||||
elseif is_false then
|
elseif is_false then
|
||||||
Result := create {JSON_BOOLEAN}.make_boolean (false)
|
Result := create {JSON_BOOLEAN}.make_boolean (false)
|
||||||
next;next;next;next;
|
next;next;next;next
|
||||||
else
|
else
|
||||||
is_parsed := false
|
is_parsed := false
|
||||||
current_errors.append ("JSON is not well formed in parse")
|
current_errors.append ("JSON is not well formed in parse")
|
||||||
@@ -249,7 +262,7 @@ feature -- Access
|
|||||||
if is_a_valid_number (sb) then
|
if is_a_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
|
||||||
elseif sb.is_double and not is_integer then
|
elseif sb.is_double and not is_integer then
|
||||||
create Result.make_real (sb.to_double)
|
create Result.make_real (sb.to_double)
|
||||||
end
|
end
|
||||||
@@ -259,8 +272,6 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
is_null: BOOLEAN is
|
is_null: BOOLEAN is
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
@@ -317,17 +328,16 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE}
|
|
||||||
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
is_a_valid_number (a_number: STRING): BOOLEAN is
|
is_a_valid_number (a_number: STRING): BOOLEAN is
|
||||||
-- 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
|
||||||
case_mapping: RX_CASE_MAPPING
|
|
||||||
word_set: RX_CHARACTER_SET
|
word_set: RX_CHARACTER_SET
|
||||||
regexp: RX_PCRE_REGULAR_EXPRESSION
|
regexp: RX_PCRE_REGULAR_EXPRESSION
|
||||||
number_regex: STRING
|
number_regex: STRING
|
||||||
l_number:STRING
|
|
||||||
do
|
do
|
||||||
create regexp.make
|
create regexp.make
|
||||||
create word_set.make_empty
|
create word_set.make_empty
|
||||||
@@ -347,8 +357,6 @@ feature {NONE}
|
|||||||
-- 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
|
||||||
case_mapping: RX_CASE_MAPPING
|
|
||||||
word_set: RX_CHARACTER_SET
|
|
||||||
regexp: RX_PCRE_REGULAR_EXPRESSION
|
regexp: RX_PCRE_REGULAR_EXPRESSION
|
||||||
unicode_regex: STRING
|
unicode_regex: STRING
|
||||||
do
|
do
|
||||||
@@ -363,19 +371,16 @@ feature {NONE}
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extra_elements: BOOLEAN is
|
extra_elements: BOOLEAN is
|
||||||
--has more elements?
|
--has more elements?
|
||||||
local
|
|
||||||
l_string:STRING
|
|
||||||
do
|
do
|
||||||
|
|
||||||
if has_next then
|
if has_next then
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
from
|
from
|
||||||
until not actual.is_space or not actual.is_equal ('%R') or
|
until
|
||||||
|
not actual.is_space or not actual.is_equal ('%R') or
|
||||||
not actual.is_equal ('%U') or not actual.is_equal ('%T')
|
not actual.is_equal ('%U') or not actual.is_equal ('%T')
|
||||||
or not actual.is_equal ('%N') or not has_next
|
or not actual.is_equal ('%N') or not has_next
|
||||||
loop
|
loop
|
||||||
|
|||||||
Reference in New Issue
Block a user