test_parser.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 68 行

HPP
68
字号
/*=============================================================================    Copyright (c) 2001-2008 Hartmut Kaiser    Distributed under the Boost Software License, Version 1.0. (See accompanying    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)=============================================================================*/#if !defined(BOOST_SPIRIT_TEST_PARSER_SEP_24_2007_0558PM)#define BOOST_SPIRIT_TEST_PARSER_SEP_24_2007_0558PM#include <boost/spirit/include/qi_parse.hpp>#include <boost/spirit/include/qi_what.hpp>namespace spirit_test{    template <typename Char, typename Parser, typename Tokens>    bool test_parser(Char const* in, Parser const& p, Tokens& tokens,         bool full_match = true)    {        boost::spirit::lex::lexer<Tokens> lex(tokens);        // we don't care about the result of the "what" function.        // we only care that all parsers have it:        boost::spirit::qi::what(p);        std::string str (in);        std::string::iterator it_in = str.begin();        std::string::iterator end_in = str.end();        typedef typename             boost::spirit::lex::lexer<Tokens>::iterator_type         iterator_type;                iterator_type iter = lex.begin(it_in, end_in);        iterator_type end = lex.end();                    return boost::spirit::qi::parse(iter, end, p)            && (!full_match || (iter == end));    }    template <typename Char, typename Parser, typename Tokens, typename Skipper>    bool test_parser(Char const* in, Parser const& p, Tokens& tokens,          Skipper const& s, bool full_match = true)    {        boost::spirit::lex::lexer<Tokens> lex(tokens);        // we don't care about the result of the "what" function.        // we only care that all parsers have it:        boost::spirit::qi::what(p);        std::string str (in);        std::string::iterator it_in = str.begin();        std::string::iterator end_in = str.end();        typedef typename             boost::spirit::lex::lexer<Tokens>::iterator_type         iterator_type;                iterator_type iter = lex.begin(it_in, end_in);        iterator_type end = lex.end();        return boost::spirit::qi::phrase_parse(iter, end, p, s)            && (!full_match || (iter == end));    }}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?