📄 cpp_grammar.hpp
字号:
= no_node_d [ ch_p(T_PP_UNDEF) [ store_found_directive_type(self.found_directive) ] >> +ppsp ] >> ( ch_p(T_IDENTIFIER) | pattern_p(KeywordTokenType, TokenTypeMask) | pattern_p(OperatorTokenType|AltExtTokenType, ExtTokenTypeMask) // and, bit_and etc. | pattern_p(BoolLiteralTokenType, TokenTypeMask) // true/false ) ; // #ifdef et.al. ppifdef = no_node_d [ ch_p(T_PP_IFDEF) [ store_found_directive_type(self.found_directive) ] >> +ppsp ] >> ppqualifiedname ; ppifndef = no_node_d [ ch_p(T_PP_IFNDEF) [ store_found_directive_type(self.found_directive) ] >> +ppsp ] >> ppqualifiedname ; ppif = no_node_d [ ch_p(T_PP_IF) [ store_found_directive_type(self.found_directive) ] >> *ppsp ] >> +( anychar_p - (ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF)) ) ;// ppelse// = no_node_d// [// ch_p(T_PP_ELSE)// [ store_found_directive_type(self.found_directive) ]// ]// ; ppelif = no_node_d [ ch_p(T_PP_ELIF) [ store_found_directive_type(self.found_directive) ] >> *ppsp ] >> +( anychar_p - (ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF)) ) ;// ppendif// = no_node_d// [// ch_p(T_PP_ENDIF)// [ store_found_directive_type(self.found_directive) ]// ]// ; // #line ... ppline = no_node_d [ ch_p(T_PP_LINE) [ store_found_directive_type(self.found_directive) ] >> *ppsp ] >> +( anychar_p - (ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF)) ) ; #if BOOST_WAVE_SUPPORT_MS_EXTENSIONS != 0 // #region ... ppregion = no_node_d [ ch_p(T_MSEXT_PP_REGION) [ store_found_directive_type(self.found_directive) ] >> +ppsp ] >> ppqualifiedname ; // #endregion ppendregion = no_node_d [ ch_p(T_MSEXT_PP_ENDREGION) [ store_found_directive_type(self.found_directive) ] ] ;#endif // # something else (ill formed preprocessor directive) illformed // for error reporting = no_node_d [ pattern_p(T_POUND, MainTokenMask) >> *ppsp ] >> ( anychar_p - (ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF)) ) >> no_node_d [ *( anychar_p - (ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF)) ) ] ; // #error pperror = no_node_d [ ch_p(T_PP_ERROR) [ store_found_directive_type(self.found_directive) ] >> *ppsp ] >> *( anychar_p - (ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF)) ) ; // #warning ppwarning = no_node_d [ ch_p(T_PP_WARNING) [ store_found_directive_type(self.found_directive) ] >> *ppsp ] >> *( anychar_p - (ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF)) ) ; // #pragma ... pppragma = no_node_d [ ch_p(T_PP_PRAGMA) [ store_found_directive_type(self.found_directive) ] ] >> *( anychar_p - (ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF)) ) ; ppqualifiedname = no_node_d[*ppsp] >> ( ch_p(T_IDENTIFIER) | pattern_p(KeywordTokenType, TokenTypeMask) | pattern_p(OperatorTokenType|AltExtTokenType, ExtTokenTypeMask) // and, bit_and etc. | pattern_p(BoolLiteralTokenType, TokenTypeMask) // true/false ) ; // auxiliary helper rules ppsp // valid space in a line with a preprocessor directive = ch_p(T_SPACE) | ch_p(T_CCOMMENT) ; // end of line tokens eol_tokens = no_node_d [ *( ch_p(T_SPACE) | ch_p(T_CCOMMENT) ) >> ( ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF) [ store_found_eof_type(self.found_eof) ] ) ] ; BOOST_SPIRIT_DEBUG_TRACE_RULE(pp_statement, TRACE_CPP_GRAMMAR);// BOOST_SPIRIT_DEBUG_TRACE_RULE(include_file, TRACE_CPP_GRAMMAR);// BOOST_SPIRIT_DEBUG_TRACE_RULE(system_include_file, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_include_file, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(plain_define, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_definition, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_parameters, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(undefine, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(ppifdef, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(ppifndef, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(ppif, TRACE_CPP_GRAMMAR);// BOOST_SPIRIT_DEBUG_TRACE_RULE(ppelse, TRACE_CPP_GRAMMAR);// BOOST_SPIRIT_DEBUG_TRACE_RULE(ppelif, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(ppendif, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(ppline, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(pperror, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(ppwarning, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(illformed, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(ppsp, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(ppqualifiedname, TRACE_CPP_GRAMMAR);#if BOOST_WAVE_SUPPORT_MS_EXTENSIONS != 0 BOOST_SPIRIT_DEBUG_TRACE_RULE(ppregion, TRACE_CPP_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(ppendregion, TRACE_CPP_GRAMMAR);#endif } // start rule of this grammar rule_type const& start() const { return pp_statement; } }; bool &found_eof; TokenT &found_directive; ContainerT &found_eoltokens; cpp_grammar(bool &found_eof_, TokenT &found_directive_, ContainerT &found_eoltokens_) : found_eof(found_eof_), found_directive(found_directive_), found_eoltokens(found_eoltokens_) { BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "cpp_grammar", TRACE_CPP_GRAMMAR); }#if BOOST_WAVE_DUMP_PARSE_TREE != 0// helper function and data to get readable names of the rules known to us struct map_ruleid_to_name : public std::map<boost::spirit::classic::parser_id, std::string> { typedef std::map<boost::spirit::classic::parser_id, std::string> base_type; void init_rule_id_to_name_map(cpp_grammar const &self) { struct { int parser_id; char const *rule_name; } init_ruleid_name_map[] = { { BOOST_WAVE_PP_STATEMENT_ID, "pp_statement" },// { BOOST_WAVE_INCLUDE_FILE_ID, "include_file" },// { BOOST_WAVE_SYSINCLUDE_FILE_ID, "system_include_file" }, { BOOST_WAVE_MACROINCLUDE_FILE_ID, "macro_include_file" }, { BOOST_WAVE_PLAIN_DEFINE_ID, "plain_define" }, { BOOST_WAVE_MACRO_PARAMETERS_ID, "macro_parameters" }, { BOOST_WAVE_MACRO_DEFINITION_ID, "macro_definition" }, { BOOST_WAVE_UNDEFINE_ID, "undefine" }, { BOOST_WAVE_IFDEF_ID, "ppifdef" }, { BOOST_WAVE_IFNDEF_ID, "ppifndef" }, { BOOST_WAVE_IF_ID, "ppif" }, { BOOST_WAVE_ELIF_ID, "ppelif" },// { BOOST_WAVE_ELSE_ID, "ppelse" },// { BOOST_WAVE_ENDIF_ID, "ppendif" }, { BOOST_WAVE_LINE_ID, "ppline" }, { BOOST_WAVE_ERROR_ID, "pperror" }, { BOOST_WAVE_WARNING_ID, "ppwarning" }, { BOOST_WAVE_PRAGMA_ID, "pppragma" }, { BOOST_WAVE_ILLFORMED_ID, "illformed" }, { BOOST_WAVE_PPSPACE_ID, "ppspace" }, { BOOST_WAVE_PPQUALIFIEDNAME_ID, "ppqualifiedname" },#if BOOST_WAVE_SUPPORT_MS_EXTENSIONS != 0 { BOOST_WAVE_REGION_ID, "ppregion" }, { BOOST_WAVE_ENDREGION_ID, "ppendregion" },#endif { 0 } }; // initialize parser_id to rule_name map for (int i = 0; 0 != init_ruleid_name_map[i].parser_id; ++i) base_type::insert(base_type::value_type( boost::spirit::classic::parser_id(init_ruleid_name_map[i].parser_id), std::string(init_ruleid_name_map[i].rule_name)) ); } }; mutable map_ruleid_to_name map_rule_id_to_name;#endif // WAVE_DUMP_PARSE_TREE != 0};///////////////////////////////////////////////////////////////////////////////#undef TRACE_CPP_GRAMMAR/////////////////////////////////////////////////////////////////////////////////// Special parse function generating a parse tree using a given node_factory./////////////////////////////////////////////////////////////////////////////////template <typename NodeFactoryT, typename IteratorT, typename ParserT>inline boost::spirit::classic::tree_parse_info<IteratorT, NodeFactoryT>parsetree_parse(IteratorT const& first_, IteratorT const& last, boost::spirit::classic::parser<ParserT> const& p){ using namespace boost::spirit::classic; typedef pt_match_policy<IteratorT, NodeFactoryT> pt_match_policy_type; typedef scanner_policies<iteration_policy, pt_match_policy_type> scanner_policies_type; typedef scanner<IteratorT, scanner_policies_type> scanner_type; scanner_policies_type policies; IteratorT first = first_; scanner_type scan(first, last, policies); tree_match<IteratorT, NodeFactoryT> hit = p.derived().parse(scan); return tree_parse_info<IteratorT, NodeFactoryT>( first, hit, hit && (first == last), hit.length(), hit.trees);}///////////////////////////////////////////////////////////////////////////////// // The following parse function is defined here, to allow the separation of // the compilation of the cpp_grammar from the function using it.// ///////////////////////////////////////////////////////////////////////////////#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0#define BOOST_WAVE_GRAMMAR_GEN_INLINE#else#define BOOST_WAVE_GRAMMAR_GEN_INLINE inline#endif template <typename LexIteratorT, typename TokenContainerT>BOOST_WAVE_GRAMMAR_GEN_INLINE boost::spirit::classic::tree_parse_info< LexIteratorT, typename cpp_grammar_gen<LexIteratorT, TokenContainerT>::node_factory_type>cpp_grammar_gen<LexIteratorT, TokenContainerT>::parse_cpp_grammar ( LexIteratorT const &first, LexIteratorT const &last, position_type const &act_pos, bool &found_eof, token_type &found_directive, token_container_type &found_eoltokens){ using namespace boost::spirit::classic; using namespace boost::wave; cpp_grammar<token_type, TokenContainerT> g(found_eof, found_directive, found_eoltokens); tree_parse_info<LexIteratorT, node_factory_type> hit = parsetree_parse<node_factory_type>(first, last, g); #if BOOST_WAVE_DUMP_PARSE_TREE != 0 if (hit.match) { tree_to_xml (BOOST_WAVE_DUMP_PARSE_TREE_OUT, hit.trees, "", g.map_rule_id_to_name, &token_type::get_token_id, &token_type::get_token_value); }#endif return hit;}#undef BOOST_WAVE_GRAMMAR_GEN_INLINE///////////////////////////////////////////////////////////////////////////////} // namespace grammars} // namespace wave} // namespace boost // the suffix header occurs after all of the code#ifdef BOOST_HAS_ABI_HEADERS#include BOOST_ABI_SUFFIX#endif#endif // !defined(CPP_GRAMMAR_HPP_FEAEBC2E_2734_428B_A7CA_85E5A415E23E_INCLUDED)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -