libjsonincpp/src/library/jsonincpp/parser.h

73 lines
1.9 KiB
C++

#ifndef TEST_WEBSITE_SRC_MODULE_JSON_LIBJSONINCPP_PARSER_H
#define TEST_WEBSITE_SRC_MODULE_JSON_LIBJSONINCPP_PARSER_H
/* DO NOT EXPORT THIS FILE! User parser API is in string_representation.h */
#include "jsonobj.h"
#include <memory>
#include <assert.h>
namespace json {
constexpr int endOfFile = 999999;
struct bad_syntax: public std::exception {
inline bad_syntax() {
assert(false);
}
};
struct ParserContext {
const std::string& text;
size_t pos = 0;
size_t line = 0;
size_t column = 0;
explicit ParserContext(const std::string& text);
};
bool isEof(ParserContext& pctx);
int peep(ParserContext& pctx);
int skip(ParserContext& pctx);
void demandSkip(ParserContext& pctx, char ch);
bool isWhitespace(int vch);
void skipWhitespaces(ParserContext& pctx);
/* Function that parses string value */
std::string demandStringJson(ParserContext& pctx);
struct ParsingCall {
virtual std::unique_ptr<ParsingCall> here(ParserContext& pctx);
virtual ~ParsingCall() = default;
};
struct ValueParseCall: public ParsingCall {
JSON& result;
bool got_him = false;
std::unique_ptr<ParsingCall> here(ParserContext& pctx) override;
ValueParseCall(JSON& result);
};
struct ArrayParseCall : public ParsingCall {
std::vector<JSON>& result;
bool got_one = false;
explicit ArrayParseCall(std::vector<JSON>& result);
std::unique_ptr<ParsingCall> here(ParserContext& pctx) override;
};
struct DictionaryParseCall: public ParsingCall {
std::map<std::string, JSON>& result;
bool got_one = false;
explicit DictionaryParseCall(std::map<std::string, JSON>& result);
std::unique_ptr<ParsingCall> here(ParserContext& pctx) override;
};
}
#endif