diff --git a/runtime/json.cpp b/runtime/json.cpp index c677beb..18f7e8a 100644 --- a/runtime/json.cpp +++ b/runtime/json.cpp @@ -1,6 +1,7 @@ #include "json.hpp" #include #include +#include #include #include #include @@ -165,7 +166,7 @@ auto Parser::parse_val() -> Res> } 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> } 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> if (curtyp() != TokTyp::RBrace) { return unexpected_tok_err(TokTyp::RBrace, "malformed object"); } + step(); return Res>( std::make_unique(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::make_unique(std::move(values))); } diff --git a/runtime/json.hpp b/runtime/json.hpp index e0bc595..7a0eb52 100644 --- a/runtime/json.hpp +++ b/runtime/json.hpp @@ -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; }