mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
AK: Add a GenericLexer and extend the JsonParser with it (#2696)
This commit is contained in:
parent
1222be7e3a
commit
7b356c33cb
Notes:
sideshowbarker
2024-07-19 04:08:50 +09:00
Author: https://github.com/benit8 🔰
Commit: 7b356c33cb
Pull-request: https://github.com/SerenityOS/serenity/pull/2696
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/Dexesttp
Reviewed-by: https://github.com/stelar7
5 changed files with 476 additions and 96 deletions
|
|
@ -27,13 +27,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/GenericLexer.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
class JsonParser {
|
||||
class JsonParser : private GenericLexer {
|
||||
public:
|
||||
explicit JsonParser(const StringView& input)
|
||||
: m_input(input)
|
||||
: GenericLexer(input)
|
||||
{
|
||||
}
|
||||
~JsonParser()
|
||||
|
|
@ -45,12 +46,7 @@ public:
|
|||
private:
|
||||
Optional<JsonValue> parse_helper();
|
||||
|
||||
char peek() const;
|
||||
char consume();
|
||||
void consume_whitespace();
|
||||
bool consume_specific(char expected_ch);
|
||||
bool consume_string(const char*);
|
||||
String consume_quoted_string();
|
||||
String consume_and_unescape_string();
|
||||
Optional<JsonValue> parse_array();
|
||||
Optional<JsonValue> parse_object();
|
||||
Optional<JsonValue> parse_number();
|
||||
|
|
@ -59,12 +55,6 @@ private:
|
|||
Optional<JsonValue> parse_true();
|
||||
Optional<JsonValue> parse_null();
|
||||
|
||||
template<typename C>
|
||||
void consume_while(C);
|
||||
|
||||
StringView m_input;
|
||||
size_t m_index { 0 };
|
||||
|
||||
String m_last_string_starting_with_character[256];
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue