// Copyright (c) 2018-2020 configor - Nomango // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. #pragma once #include "configor_encoding.hpp" #include "configor_stream.hpp" #include "configor_token.hpp" #include "configor_value.hpp" #include // std::initializer_list #include // std::basic_istream #include // std::locale namespace configor { namespace detail { template class basic_parser { public: using value_type = _ValTy; using source_char_type = _SourceCharTy; using target_char_type = typename value_type::char_type; basic_parser(std::basic_istream& is) : is_(is.rdbuf()) , err_handler_(nullptr) , source_decoder_(nullptr) , target_encoder_(nullptr) { is_.unsetf(std::ios_base::skipws); is_.imbue(std::locale(std::locale::classic(), is.getloc(), std::locale::collate | std::locale::ctype)); } virtual void parse(value_type& c) { try { do_parse(c, token_type::uninitialized); if (scan() != token_type::end_of_input) fail(token_type::end_of_input); } catch (...) { if (err_handler_) err_handler_->handle(std::current_exception()); else throw; } } inline void set_error_handler(configor::error_handler* eh) { err_handler_ = eh; } template