Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Stream parsing support for JSON #37

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Tests/Json/JsonTest.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// This file is UTF-8
// The program uses WCHAR Unicode representation (either UTF-32 or UTF-16 on Windows)

#include <Extra/Json.hpp>
#include <Io.hpp>
#include <cassert>
#include <cstdlib>

using namespace hsd::string_view_literals;

Expand Down Expand Up @@ -40,9 +42,9 @@ int main()
lexer.lex(s_test_string).unwrap();
lexer.push_eot().unwrap();

hsd::JsonParser parser = lexer;
hsd::JsonParser parser(lexer);
// Parse the string
auto value = parser.parse_next().unwrap();
auto value = parser.parse_all().unwrap();

// Assert that the whole object is complete
assert(value->is_complete());
Expand Down Expand Up @@ -93,12 +95,17 @@ void print_value(hsd::vector<hsd::wstring_view>& path, hsd::JsonValue& v)
case hsd::JsonValueType::Object:
hsd_print(L"object");
break;
case hsd::JsonValueType::StreamingArray:
case hsd::JsonValueType::StreamingObject:
// Uh, oh
hsd_println_err("Unexcpected streaming object");
abort();
}
hsd_println(L"");

if (type == hsd::JsonValueType::Array)
{
auto& vec = v.as<hsd::JsonArray>().values();
auto& vec = v.as_array();

for (hsd::usize idx = 0; auto& it : vec)
{
Expand All @@ -111,7 +118,7 @@ void print_value(hsd::vector<hsd::wstring_view>& path, hsd::JsonValue& v)
}
else if (type == hsd::JsonValueType::Object)
{
auto& map = v.as<hsd::JsonObject<hsd::wchar>>().values();
auto& map = v.as_object<hsd::wchar>();

for (auto& kv : map)
{
Expand Down
6 changes: 3 additions & 3 deletions Tests/Json/JsonTestFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ int main()
lexer.lex_file(test_filename).unwrap();
lexer.push_eot().unwrap();

hsd::JsonParser parser = lexer;
hsd::JsonParser parser(lexer);
// Parse the string
auto value = parser.parse_next().unwrap();
auto value = parser.parse_all().unwrap();

// Assert that the whole object is complete
assert(value->is_complete());

hsd_println("Price {}", (*value)["price"_sv].as_num<hsd::f32>().unwrap());
}
}
Loading