Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:01:56

0001 /*=============================================================================
0002     Copyright (c) 2001-2003 Joel de Guzman
0003     Copyright (c) 2002-2003 Hartmut Kaiser
0004     http://spirit.sourceforge.net/
0005 
0006     Use, modification and distribution is subject to the Boost Software
0007     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0008     http://www.boost.org/LICENSE_1_0.txt)
0009 =============================================================================*/
0010 #if !defined(BOOST_SPIRIT_PARSER_NAMES_IPP)
0011 #define BOOST_SPIRIT_PARSER_NAMES_IPP
0012 
0013 #if defined(BOOST_SPIRIT_DEBUG)
0014 
0015 #include <string>
0016 #include <iostream>
0017 #include <map>
0018 
0019 #include <boost/config.hpp>
0020 #ifdef BOOST_NO_STRINGSTREAM
0021 #include <strstream>
0022 #define BOOST_SPIRIT_SSTREAM std::strstream
0023 std::string BOOST_SPIRIT_GETSTRING(std::strstream& ss)
0024 {
0025     ss << ends;
0026     std::string rval = ss.str();
0027     ss.freeze(false);
0028     return rval;
0029 }
0030 #else
0031 #include <sstream>
0032 #define BOOST_SPIRIT_GETSTRING(ss) ss.str()
0033 #define BOOST_SPIRIT_SSTREAM std::stringstream
0034 #endif
0035 
0036 namespace boost { namespace spirit {
0037 
0038 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0039 
0040 ///////////////////////////////////////////////////////////////////////////////
0041 //  from actions.hpp
0042     template <typename ParserT, typename ActionT>
0043     inline std::string
0044     parser_name(action<ParserT, ActionT> const& p)
0045     {
0046         return std::string("action")
0047             + std::string("[")
0048             + parser_name(p.subject())
0049             + std::string("]");
0050     }
0051 
0052 ///////////////////////////////////////////////////////////////////////////////
0053 //  from directives.hpp
0054     template <typename ParserT>
0055     inline std::string
0056     parser_name(contiguous<ParserT> const& p)
0057     {
0058         return std::string("contiguous")
0059             + std::string("[")
0060             + parser_name(p.subject())
0061             + std::string("]");
0062     }
0063 
0064     template <typename ParserT>
0065     inline std::string
0066     parser_name(inhibit_case<ParserT> const& p)
0067     {
0068         return std::string("inhibit_case")
0069             + std::string("[")
0070             + parser_name(p.subject())
0071             + std::string("]");
0072     }
0073 
0074     template <typename A, typename B>
0075     inline std::string
0076     parser_name(longest_alternative<A, B> const& p)
0077     {
0078         return std::string("longest_alternative")
0079             + std::string("[")
0080             + parser_name(p.left()) + std::string(", ") + parser_name(p.right())
0081             + std::string("]");
0082     }
0083 
0084     template <typename A, typename B>
0085     inline std::string
0086     parser_name(shortest_alternative<A, B> const& p)
0087     {
0088         return std::string("shortest_alternative")
0089             + std::string("[")
0090             + parser_name(p.left()) + std::string(", ") + parser_name(p.right())
0091             + std::string("]");
0092     }
0093 
0094 ///////////////////////////////////////////////////////////////////////////////
0095 //  from numerics.hpp
0096     template <typename T, int Radix, unsigned MinDigits, int MaxDigits>
0097     inline std::string
0098     parser_name(uint_parser<T, Radix, MinDigits, MaxDigits> const& /*p*/)
0099     {
0100         BOOST_SPIRIT_SSTREAM stream;
0101         stream << Radix << ", " << MinDigits << ", " << MaxDigits;
0102         return std::string("uint_parser<")
0103             + BOOST_SPIRIT_GETSTRING(stream)
0104             + std::string(">");
0105     }
0106 
0107     template <typename T, int Radix, unsigned MinDigits, int MaxDigits>
0108     inline std::string
0109     parser_name(int_parser<T, Radix, MinDigits, MaxDigits> const& /*p*/)
0110     {
0111         BOOST_SPIRIT_SSTREAM stream;
0112         stream << Radix << ", " << MinDigits << ", " << MaxDigits;
0113         return std::string("int_parser<")
0114             + BOOST_SPIRIT_GETSTRING(stream)
0115             + std::string(">");
0116     }
0117 
0118     template <typename T, typename RealPoliciesT>
0119     inline std::string
0120     parser_name(real_parser<T, RealPoliciesT> const& /*p*/)
0121     {
0122         return std::string("real_parser");
0123     }
0124 
0125 ///////////////////////////////////////////////////////////////////////////////
0126 //  from operators.hpp
0127     template <typename A, typename B>
0128     inline std::string
0129     parser_name(sequence<A, B> const& p)
0130     {
0131         return std::string("sequence")
0132             + std::string("[")
0133             + parser_name(p.left()) + std::string(", ") + parser_name(p.right())
0134             + std::string("]");
0135     }
0136 
0137     template <typename A, typename B>
0138     inline std::string
0139     parser_name(sequential_or<A, B> const& p)
0140     {
0141         return std::string("sequential_or")
0142             + std::string("[")
0143             + parser_name(p.left()) + std::string(", ") + parser_name(p.right())
0144             + std::string("]");
0145     }
0146 
0147     template <typename A, typename B>
0148     inline std::string
0149     parser_name(alternative<A, B> const& p)
0150     {
0151         return std::string("alternative")
0152             + std::string("[")
0153             + parser_name(p.left()) + std::string(", ") + parser_name(p.right())
0154             + std::string("]");
0155     }
0156 
0157     template <typename A, typename B>
0158     inline std::string
0159     parser_name(intersection<A, B> const& p)
0160     {
0161         return std::string("intersection")
0162             + std::string("[")
0163             + parser_name(p.left()) + std::string(", ") + parser_name(p.right())
0164             + std::string("]");
0165     }
0166 
0167     template <typename A, typename B>
0168     inline std::string
0169     parser_name(difference<A, B> const& p)
0170     {
0171         return std::string("difference")
0172             + std::string("[")
0173             + parser_name(p.left()) + std::string(", ") + parser_name(p.right())
0174             + std::string("]");
0175     }
0176 
0177     template <typename A, typename B>
0178     inline std::string
0179     parser_name(exclusive_or<A, B> const& p)
0180     {
0181         return std::string("exclusive_or")
0182             + std::string("[")
0183             + parser_name(p.left()) + std::string(", ") + parser_name(p.right())
0184             + std::string("]");
0185     }
0186 
0187     template <typename S>
0188     inline std::string
0189     parser_name(optional<S> const& p)
0190     {
0191         return std::string("optional")
0192             + std::string("[")
0193             + parser_name(p.subject())
0194             + std::string("]");
0195     }
0196 
0197     template <typename S>
0198     inline std::string
0199     parser_name(kleene_star<S> const& p)
0200     {
0201         return std::string("kleene_star")
0202             + std::string("[")
0203             + parser_name(p.subject())
0204             + std::string("]");
0205     }
0206 
0207     template <typename S>
0208     inline std::string
0209     parser_name(positive<S> const& p)
0210     {
0211         return std::string("positive")
0212             + std::string("[")
0213             + parser_name(p.subject())
0214             + std::string("]");
0215     }
0216 
0217 ///////////////////////////////////////////////////////////////////////////////
0218 //  from parser.hpp
0219     template <typename DerivedT>
0220     inline std::string
0221     parser_name(parser<DerivedT> const& /*p*/)
0222     {
0223         return std::string("parser");
0224     }
0225 
0226 ///////////////////////////////////////////////////////////////////////////////
0227 //  from primitives.hpp
0228     template <typename DerivedT>
0229     inline std::string
0230     parser_name(char_parser<DerivedT> const &/*p*/)
0231     {
0232         return std::string("char_parser");
0233     }
0234 
0235     template <typename CharT>
0236     inline std::string
0237     parser_name(chlit<CharT> const &p)
0238     {
0239         return std::string("chlit(\'")
0240             + std::string(1, p.ch)
0241             + std::string("\')");
0242     }
0243 
0244     template <typename CharT>
0245     inline std::string
0246     parser_name(range<CharT> const &p)
0247     {
0248         return std::string("range(")
0249             + std::string(1, p.first) + std::string(", ") + std::string(1, p.last)
0250             + std::string(")");
0251     }
0252 
0253     template <typename IteratorT>
0254     inline std::string
0255     parser_name(chseq<IteratorT> const &p)
0256     {
0257         return std::string("chseq(\"")
0258             + std::string(p.first, p.last)
0259             + std::string("\")");
0260     }
0261 
0262     template <typename IteratorT>
0263     inline std::string
0264     parser_name(strlit<IteratorT> const &p)
0265     {
0266         return std::string("strlit(\"")
0267             + std::string(p.seq.first, p.seq.last)
0268             + std::string("\")");
0269     }
0270 
0271     inline std::string
0272     parser_name(nothing_parser const&)
0273     {
0274         return std::string("nothing");
0275     }
0276 
0277     inline std::string
0278     parser_name(epsilon_parser const&)
0279     {
0280         return std::string("epsilon");
0281     }
0282 
0283     inline std::string
0284     parser_name(anychar_parser const&)
0285     {
0286         return std::string("anychar");
0287     }
0288 
0289     inline std::string
0290     parser_name(alnum_parser const&)
0291     {
0292         return std::string("alnum");
0293     }
0294 
0295     inline std::string
0296     parser_name(alpha_parser const&)
0297     {
0298         return std::string("alpha");
0299     }
0300 
0301     inline std::string
0302     parser_name(cntrl_parser const&)
0303     {
0304         return std::string("cntrl");
0305     }
0306 
0307     inline std::string
0308     parser_name(digit_parser const&)
0309     {
0310         return std::string("digit");
0311     }
0312 
0313     inline std::string
0314     parser_name(graph_parser const&)
0315     {
0316         return std::string("graph");
0317     }
0318 
0319     inline std::string
0320     parser_name(lower_parser const&)
0321     {
0322         return std::string("lower");
0323     }
0324 
0325     inline std::string
0326     parser_name(print_parser const&)
0327     {
0328         return std::string("print");
0329     }
0330 
0331     inline std::string
0332     parser_name(punct_parser const&)
0333     {
0334         return std::string("punct");
0335     }
0336 
0337     inline std::string
0338     parser_name(blank_parser const&)
0339     {
0340         return std::string("blank");
0341     }
0342 
0343     inline std::string
0344     parser_name(space_parser const&)
0345     {
0346         return std::string("space");
0347     }
0348 
0349     inline std::string
0350     parser_name(upper_parser const&)
0351     {
0352         return std::string("upper");
0353     }
0354 
0355     inline std::string
0356     parser_name(xdigit_parser const&)
0357     {
0358         return std::string("xdigit");
0359     }
0360 
0361     inline std::string
0362     parser_name(eol_parser const&)
0363     {
0364         return std::string("eol");
0365     }
0366 
0367     inline std::string
0368     parser_name(end_parser const&)
0369     {
0370         return std::string("end");
0371     }
0372 
0373 ///////////////////////////////////////////////////////////////////////////////
0374 //  from rule.hpp
0375     namespace impl {
0376         struct node_registry
0377         {
0378             typedef std::pair<std::string, bool> rule_info;
0379             typedef std::map<void const *, rule_info> rule_infos;
0380 
0381             std::string find_node(void const *r)
0382             {
0383                 rule_infos::const_iterator cit = infos.find(r);
0384                 if (cit != infos.end())
0385                     return (*cit).second.first;
0386                 return std::string("<unknown>");
0387             }
0388 
0389             bool trace_node(void const *r)
0390             {
0391                 rule_infos::const_iterator cit = infos.find(r);
0392                 if (cit != infos.end())
0393                     return (*cit).second.second;
0394                 return BOOST_SPIRIT_DEBUG_TRACENODE;
0395             }
0396 
0397             bool register_node(void const *r, char const *name_to_register,
0398                 bool trace_node)
0399             {
0400                 if (infos.find(r) != infos.end())
0401                     return false;
0402 
0403                 return infos.insert(rule_infos::value_type(r,
0404                     rule_info(std::string(name_to_register), trace_node))
0405                 ).second;
0406             }
0407 
0408             bool unregister_node(void const *r)
0409             {
0410                 if (infos.find(r) == infos.end())
0411                     return false;
0412                 return (1 == infos.erase(r));
0413             }
0414 
0415         private:
0416             rule_infos infos;
0417         };
0418 
0419         inline node_registry &
0420         get_node_registry()
0421         {
0422             static node_registry node_infos;
0423             return node_infos;
0424         }
0425     }   // namespace impl
0426 
0427     template<
0428         typename DerivedT, typename EmbedT, 
0429         typename T0, typename T1, typename T2
0430     >
0431     inline std::string
0432     parser_name(impl::rule_base<DerivedT, EmbedT, T0, T1, T2> const& p)
0433     {
0434         return std::string("rule_base")
0435             + std::string("(")
0436             + impl::get_node_registry().find_node(&p)
0437             + std::string(")");
0438     }
0439 
0440     template<typename T0, typename T1, typename T2>
0441     inline std::string
0442     parser_name(rule<T0, T1, T2> const& p)
0443     {
0444         return std::string("rule")
0445             + std::string("(")
0446             + impl::get_node_registry().find_node(&p)
0447             + std::string(")");
0448     }
0449 
0450 ///////////////////////////////////////////////////////////////////////////////
0451 //  from subrule.hpp
0452     template <typename FirstT, typename RestT>
0453     inline std::string
0454     parser_name(subrule_list<FirstT, RestT> const &p)
0455     {
0456         return std::string("subrule_list")
0457             + std::string("(")
0458             + impl::get_node_registry().find_node(&p)
0459             + std::string(")");
0460     }
0461 
0462     template <int ID, typename DefT, typename ContextT>
0463     inline std::string
0464     parser_name(subrule_parser<ID, DefT, ContextT> const &p)
0465     {
0466         return std::string("subrule_parser")
0467             + std::string("(")
0468             + impl::get_node_registry().find_node(&p)
0469             + std::string(")");
0470     }
0471 
0472     template <int ID, typename ContextT>
0473     inline std::string
0474     parser_name(subrule<ID, ContextT> const &p)
0475     {
0476         BOOST_SPIRIT_SSTREAM stream;
0477         stream << ID;
0478         return std::string("subrule<")
0479             + BOOST_SPIRIT_GETSTRING(stream)
0480             + std::string(">(")
0481             + impl::get_node_registry().find_node(&p)
0482             + std::string(")");
0483     }
0484 
0485 ///////////////////////////////////////////////////////////////////////////////
0486 //  from grammar.hpp
0487     template <typename DerivedT, typename ContextT>
0488     inline std::string
0489     parser_name(grammar<DerivedT, ContextT> const& p)
0490     {
0491         return std::string("grammar")
0492             + std::string("(")
0493             + impl::get_node_registry().find_node(&p)
0494             + std::string(")");
0495     }
0496 
0497 ///////////////////////////////////////////////////////////////////////////////
0498 //  decide, if a node is to be traced or not
0499     template<
0500         typename DerivedT, typename EmbedT, 
0501         typename T0, typename T1, typename T2
0502     >
0503     inline bool
0504     trace_parser(impl::rule_base<DerivedT, EmbedT, T0, T1, T2> 
0505         const& p)
0506     {
0507         return impl::get_node_registry().trace_node(&p);
0508     }
0509 
0510     template<typename T0, typename T1, typename T2>
0511     inline bool
0512     trace_parser(rule<T0, T1, T2> const& p)
0513     {
0514         return impl::get_node_registry().trace_node(&p);
0515     }
0516 
0517     template <typename DerivedT, typename ContextT>
0518     inline bool
0519     trace_parser(grammar<DerivedT, ContextT> const& p)
0520     {
0521         return impl::get_node_registry().trace_node(&p);
0522     }
0523 
0524     template <typename DerivedT, int N, typename ContextT>
0525     inline bool
0526     trace_parser(impl::entry_grammar<DerivedT, N, ContextT> const& p)
0527     {
0528         return impl::get_node_registry().trace_node(&p);
0529     }
0530 
0531     template <int ID, typename ContextT>
0532     bool
0533     trace_parser(subrule<ID, ContextT> const& p)
0534     {
0535         return impl::get_node_registry().trace_node(&p);
0536     }
0537 
0538     template <typename ParserT, typename ActorTupleT>
0539     bool
0540     trace_parser(init_closure_parser<ParserT, ActorTupleT> const& p)
0541     {
0542         return impl::get_node_registry().trace_node(&p);
0543     }
0544 
0545 ///////////////////////////////////////////////////////////////////////////////
0546 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0547 
0548 }} // namespace boost::spirit
0549 
0550 #undef BOOST_SPIRIT_SSTREAM
0551 #undef BOOST_SPIRIT_GETSTRING
0552 
0553 #endif // defined(BOOST_SPIRIT_DEBUG)
0554 
0555 #endif // !defined(BOOST_SPIRIT_PARSER_NAMES_IPP)