ladybird/AK/JsonParser.h
Andreas Kling 587f9af960 AK: Make JSON parser return ErrorOr<JsonValue> (instead of Optional)
Also add slightly richer parse errors now that we can include a string
literal with returned errors.

This will allow us to use TRY() when working with JSON data.
2021-11-17 00:21:10 +01:00

41 lines
823 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/GenericLexer.h>
#include <AK/JsonValue.h>
namespace AK {
class JsonParser : private GenericLexer {
public:
explicit JsonParser(StringView input)
: GenericLexer(input)
{
}
ErrorOr<JsonValue> parse();
private:
ErrorOr<JsonValue> parse_helper();
ErrorOr<String> consume_and_unescape_string();
ErrorOr<JsonValue> parse_array();
ErrorOr<JsonValue> parse_object();
ErrorOr<JsonValue> parse_number();
ErrorOr<JsonValue> parse_string();
ErrorOr<JsonValue> parse_false();
ErrorOr<JsonValue> parse_true();
ErrorOr<JsonValue> parse_null();
String m_last_string_starting_with_character[256];
};
}
using AK::JsonParser;