mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-29 21:40:50 +00:00
fix json
This commit is contained in:
parent
1640915ddb
commit
9221f62f92
@ -1,6 +1,7 @@
|
||||
#include "json.hpp"
|
||||
#include <cstdlib>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@ -165,7 +166,7 @@ auto Parser::parse_val() -> Res<std::unique_ptr<Value>>
|
||||
}
|
||||
step();
|
||||
auto value = parse_val();
|
||||
if (value.ok()) {
|
||||
if (not value.ok()) {
|
||||
return value.err();
|
||||
}
|
||||
fields.insert_or_assign(key, std::move(value.val()));
|
||||
@ -183,7 +184,7 @@ auto Parser::parse_val() -> Res<std::unique_ptr<Value>>
|
||||
}
|
||||
step();
|
||||
auto value = parse_val();
|
||||
if (value.ok()) {
|
||||
if (not value.ok()) {
|
||||
return value.err();
|
||||
}
|
||||
fields.insert_or_assign(key, std::move(value.val()));
|
||||
@ -192,30 +193,32 @@ auto Parser::parse_val() -> Res<std::unique_ptr<Value>>
|
||||
if (curtyp() != TokTyp::RBrace) {
|
||||
return unexpected_tok_err(TokTyp::RBrace, "malformed object");
|
||||
}
|
||||
step();
|
||||
return Res<std::unique_ptr<Value>>(
|
||||
std::make_unique<Object>(std::move(fields)));
|
||||
}
|
||||
case TokTyp::LBracket: {
|
||||
step();
|
||||
ArrayValues values;
|
||||
if (curtyp() != TokTyp::RBrace) {
|
||||
if (curtyp() != TokTyp::RBracket) {
|
||||
auto value = parse_val();
|
||||
if (value.ok()) {
|
||||
if (not value.ok()) {
|
||||
return value.err();
|
||||
}
|
||||
values.push_back(std::move(value.val()));
|
||||
while (curtyp() == TokTyp::Comma) {
|
||||
step();
|
||||
auto value = parse_val();
|
||||
if (value.ok()) {
|
||||
if (not value.ok()) {
|
||||
return value.err();
|
||||
}
|
||||
values.push_back(std::move(value.val()));
|
||||
}
|
||||
}
|
||||
if (curtyp() != TokTyp::RBrace) {
|
||||
return unexpected_tok_err(TokTyp::RBrace, "malformed object");
|
||||
if (curtyp() != TokTyp::RBracket) {
|
||||
return unexpected_tok_err(TokTyp::RBracket, "malformed array");
|
||||
}
|
||||
step();
|
||||
return Res<std::unique_ptr<Value>>(
|
||||
std::make_unique<Array>(std::move(values)));
|
||||
}
|
||||
|
@ -311,6 +311,7 @@ private:
|
||||
auto tok = this->lexer.next();
|
||||
if (not tok.ok())
|
||||
return tok.err();
|
||||
this->cur = tok;
|
||||
return {};
|
||||
}
|
||||
inline auto curtyp() const -> TokTyp { return this->cur.val().typ; }
|
||||
|
Loading…
Reference in New Issue
Block a user