# var p = new JSONStringParser("""{"numbers": [1,23,3], "string": "string"}""")
# assert p.parse_entity isa JsonObject
# ~~~
- fun parse_entity: nullable Jsonable do
+ fun parse_entity: nullable Serializable do
var srclen = len
ignore_whitespaces
if pos >= srclen then return make_parse_error("Empty JSON")
end
# Parses a JSON Array
- fun parse_json_array: Jsonable do
+ fun parse_json_array: Serializable do
var max = len
if pos >= max then return make_parse_error("Incomplete JSON array")
var arr = new JsonArray
end
# Parses a JSON Object
- fun parse_json_object: Jsonable do
+ fun parse_json_object: Serializable do
var max = len
if pos >= max then return make_parse_error("Incomplete JSON object")
var obj = new JsonObject
end
# Parses an Int or Float
- fun parse_json_number: Jsonable do
+ fun parse_json_number: Serializable do
var max = len
var p = pos
var c = src[p]
private var parse_str_buf = new FlatBuffer
# Parses and returns a Nit string from a JSON String
- fun parse_json_string: Jsonable do
+ fun parse_json_string: Serializable do
var src = src
var ln = src.length
var p = pos
end
redef class JsonParseError
+ serialize
# Location of the error in source
var location: nullable Location = null
-
- # Get the JSON representation of `self`.
- #
- # ~~~
- # var err = new JsonParseError("foo", new Position(1, 2, 3, 4, 5, 6))
- # assert err.to_json == "Parsing error: foo"
- # ~~~
- redef fun to_json do
- var l = location
- var m = message
- return if l == null then "Parsing error: {m}" else "Parsing error at {l}: {m}"
- end
-
- redef fun to_s do return to_json
end