Hi,
I am trying to develop a JSON parser using spirit/qi so far it is not
going bad but I am having serious problem with on_error and error
handler. This is my code:
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace phoenix = boost::phoenix;
template <typename Iterator>
struct error_handler
{
template
struct result
{
typedef void type;
};
void operator()(Iterator first, Iterator last, Iterator err_pos,
const boost::spirit::info& info) const
{
std::cout << "never called";
}
};
template <class Iterator>
struct JsonGrammar : public qi::grammar
{
JsonGrammar() : JsonGrammar::base_type(json, "json"),
error(error_handler<Iterator>())
{
using qi::double_;
using qi::lexeme;
using qi::char_;
using qi::int_;
using qi::on_error;
using qi::fail;
using phoenix::construct;
using phoenix::val;
using namespace qi::labels;
qi::on_errorqi::fail(json, error(_1, _2, _3, _4));
string %= lexeme['"' >> +(char_ - '"') >> '"'];
number = int_;
member = string >> ':' >> value;
array = '[' >> value % ',' >> ']';
object = '{' >> member >> *(',' >> member) >> '}';
value = array | object | number | string | qi::bool_ | "null";
json = array | object;
json.name("json");
}
phoenix::function const error;
qi::rule string;
qi::rule number;
qi::rule json;
qi::rule array;
qi::rule value;
qi::rule object;
qi::rule(),
ascii::space_type> member;
};
now when i try to parse
std::string json = "[1, 2, 3, 4, t]";
parising result is false. but error handelr is never called. What am I
doing wrong?
Regards,
Simon
--
Szymon Gatner
The Lordz Games Studio
www.thelordzgamesstudio.com