Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <string>
- #include <boost/spirit/home/x3.hpp>
- #include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
- #include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
- #include "SchematicLibraryGrammar.hpp"
- #include <map>
- namespace client { namespace KicadParser_grammar
- {
- namespace x3 = boost::spirit::x3;
- // struct error_handler
- // {
- // // Our error handler
- // template <typename Iterator, typename Exception, typename Context>
- // x3::error_handler_result
- // on_error(Iterator&, Iterator const& last, Exception const& x, Context const& context)
- // {
- // std::cout
- // << "Error! Expecting: "
- // << x.which()
- // << " here: \""
- // << std::string(x.where(), last)
- // << "\""
- // << std::endl
- // ;
- // return x3::error_handler_result::fail;
- // }
- // };
- ////////////////////////////////////////////////////////////////////////////
- // Our error handler
- ////////////////////////////////////////////////////////////////////////////
- // ERROR_HANDLER1_VISIT_BEGIN
- // X3 Error Handler Utility
- template <typename Iterator>
- using error_handler = x3::error_handler<Iterator>;
- // tag used to get our error handler from the context
- using x3::error_handler_tag;
- struct error_handler_base
- {
- error_handler_base();
- template <typename Iterator, typename Exception, typename Context>
- x3::error_handler_result on_error(
- Iterator& first, Iterator const& last
- , Exception const& x, Context const& context);
- std::map<std::string, std::string> id_map;
- };
- // ERROR_HANDLER1_VISIT_END
- ////////////////////////////////////////////////////////////////////////////
- // Implementation
- ////////////////////////////////////////////////////////////////////////////
- // ERROR_HANDLER2_VISIT_BEGIN
- inline error_handler_base::error_handler_base()
- {
- id_map["schematicLibrary"] = "schematicLibrary";
- id_map["schematicSymbolDefinition"] = "schematicSymbolDefinition";
- id_map["arcShape"] = "arcShape";
- id_map["circleShape"] = "circleShape";
- id_map["symbolAlias"] = "symbolAlias";
- id_map["rectangleShape"] = "rectangleShape";
- id_map["symbolField"] = "symbolField";
- id_map["textShape"] = "textShape";
- id_map["footprintFilterList"] = "footprintFilterList";
- id_map["polygonShape"] = "polygonShape";
- id_map["pinShape"] = "pinShape";
- id_map["bezierShape"] = "bezierShape";
- id_map["schematicSymbol"] = "schematicSymbol";
- id_map["symbolShape"] = "symbolShape";
- id_map["nonQuotedString"] = "nonQuotedString";
- id_map["nonQuotedStringMultiWord"] = "nonQuotedStringMultiWord";
- id_map["optionalChar"] = "optionalChar";
- id_map["quotedString"] = "quotedString";
- }
- // ERROR_HANDLER2_VISIT_END
- // ERROR_HANDLER3_VISIT_BEGIN
- template <typename Iterator, typename Exception, typename Context>
- inline x3::error_handler_result
- error_handler_base::on_error(
- Iterator& first, Iterator const& last
- , Exception const& x, Context const& context)
- {
- std::string which = x.which();
- auto iter = id_map.find(which);
- if (iter != id_map.end())
- which = iter->second;
- std::string message = "Error! Expecting: " + which + " here:";
- auto& error_handler = x3::get<error_handler_tag>(context).get();
- error_handler(x.where(), message);
- return x3::error_handler_result::fail;
- }
- // ERROR_HANDLER3_VISIT_END
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement