diff options
Diffstat (limited to 'libjsonpp/jsonFlexLexer.cpp')
-rw-r--r-- | libjsonpp/jsonFlexLexer.cpp | 71 |
1 files changed, 8 insertions, 63 deletions
diff --git a/libjsonpp/jsonFlexLexer.cpp b/libjsonpp/jsonFlexLexer.cpp index 0964c1c..df29d8f 100644 --- a/libjsonpp/jsonFlexLexer.cpp +++ b/libjsonpp/jsonFlexLexer.cpp @@ -1,87 +1,32 @@ -#include "jsonFlexLexer.h" +#include "jsonValueFlexLexer.h" #include <glibmm/convert.h> namespace json { - const std::string UTF8 { "utf-8" }; - - jsonFlexLexer::jsonFlexLexer(std::istream & in, std::string enc, Value & v) : + jsonFlexLexer::jsonFlexLexer(std::istream & in, std::string enc) : yyFlexLexer(&in, nullptr), - encoding(enc != UTF8 ? std::move(enc) : std::string()) + encoding(enc != utf8 ? std::move(enc) : std::string()) { yy_push_state(0); - acceptValues.push([&v](auto && value) { - v = std::forward<Value>(value); - return &v; - }); } std::string jsonFlexLexer::encodeBuf() const { if (!encoding.empty()) { - return Glib::convert(buf, UTF8, encoding); + return Glib::convert(buf, utf8, encoding); } return buf; } void - jsonFlexLexer::BeginObject() - { - auto object = std::get_if<Object>(acceptValues.top()(Object())); - acceptValues.push([object,this](auto && value) { - return &object->emplace(std::move(name), std::forward<Value>(value)).first->second; - }); - } - - void - jsonFlexLexer::BeginArray() - { - auto array = std::get_if<Array>(acceptValues.top()(Array())); - acceptValues.push([array](auto && value) { - return &array->emplace_back(std::forward<Value>(value)); - }); - } - - void - jsonFlexLexer::PushNull() - { - acceptValues.top()(Null()); - } - - void - jsonFlexLexer::PushBoolean(bool value) - { - acceptValues.top()(value); - } - - void - jsonFlexLexer::PushNumber(double value) - { - acceptValues.top()(value); - } - - void - jsonFlexLexer::PushText(std::string && value) - { - acceptValues.top()(std::move(value)); - } - - void - jsonFlexLexer::EndArray() - { - acceptValues.pop(); - } - - void - jsonFlexLexer::EndObject() + jsonFlexLexer::LexerError(const char * msg) { - acceptValues.pop(); + throw ParseError(msg, 0, 0); } - void - jsonFlexLexer::LexerError(const char * msg) + ParseError::ParseError(const char * at, int l, int s) : + std::invalid_argument(Glib::ustring::compose("Parse error at or near %1 (line %2, state %3)", at, l, s)) { - throw ParseError(msg, 0, 0); } } |