#include "ParseJSON.h"
#include "Parser.h"
#include "ParserIdDef.h"
#include "Scanner.h"
#include <sstream>
namespace json {
value parse(std::istream &in, std::ostream *log)
{
std::ostringstream nul_out;
if (!log)
log = &nul_out;
C_Parser parser{*log};
bux::C_Screener preparser(parser, [](
auto token){
return token == TID_LEX_Spaces || token ==
'\n'; });
C_JSONScanner scanner(preparser);
if (const auto n_errs = parser.m_context.getCount(LL_FATAL) + parser.m_context.getCount(LL_ERROR))
if (!parser.accepted())
}
std::optional<jint> parse_int(std::string_view s, std::ostream *log)
{
const auto v = parse(in, log);
if (auto i = get_if<ALT_INT>(&v))
return *i;
return std::nullopt;
}
std::optional<jfloat> parse_float(std::string_view s, std::ostream *log)
{
const auto v = parse(in, log);
switch (v.index())
{
case ALT_FLOAT:
return get<ALT_FLOAT>(v);
case ALT_INT:
return get<ALT_INT>(v);
}
return std::nullopt;
}
}
#define RUNTIME_ERROR(fmtStr,...)
Wrap FILE(DATE)#__LINE__ FUNCTION: msg into std::runtime_error.
auto & unlex(I_LexAttr &lex)
void scanFile(std::string_view filename, std::istream &in, I_Scanner< T_Char > &scanner, T_LexID endToken=TID_EOF, T_Encoding encoding=0)