00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00029
00030
00031 #ifndef _XML_PARSER_H_INCLUDED_
00032 #define _XML_PARSER_H_INCLUDED_
00033
00045 template< typename UniverseT >
00046 struct parser {
00047
00049 typedef UniverseT universe_T;
00050
00052 typedef typename UniverseT::strict_edge_T strict_universe_T;
00053
00055 typedef typename UniverseT::node_T node_T;
00056
00058 typedef typename UniverseT::char_T char_T;
00059
00061 std::vector< std::string > vect_xml_names;
00062
00064 std::map< std::string, size_t > map_xml_names;
00065
00066
00067 std::pair< std::vector< std::string >*, std::map< std::string, size_t >* > xml_name_dictionary;
00068
00070 std::vector< std::string > vect_xml_text;
00071
00073 std::stack< size_t > xml_offset_stack;
00074
00076 std::vector< int > vect_xml_tree;
00077
00079 parser()
00080 :
00081 xml_name_dictionary( &vect_xml_names, &map_xml_names ),
00082 vect_xml_tree( 1 )
00083 {
00084 }
00085
00086 public:
00088 void error_show( universe_T& universe_, char_T const* message_ )
00089 {
00090 #ifndef SUPPRESS_VERBOSE_ERRORS
00091 size_t offset_from_ = offset_stack_guard< universe_T >::offset( universe_, xml_offset_stack.top() );
00092 size_t offset_to_ = universe_.first.offset();
00093
00094 if ( offset_from_ < offset_to_ )
00095 std::cout
00096 << "..."
00097 << universe_.parent().container().text_absolute_substring( offset_from_, std::min( offset_to_, offset_from_ + 50 ) )
00098 << "..."
00099 ;
00100
00101 std::cout
00102 << std::endl
00103 << "*** Error: "
00104 #ifdef DISPOSE_CONSUMED_DATA
00105 << '@'
00106 << offset_from_
00107 << '-'
00108 << offset_to_
00109 #else
00110 << "line "
00111 << universe_.first.line()
00112 #endif
00113 << '\t'
00114 << message_
00115 << std::endl
00116 ;
00117 #endif // SUPPRESS_VERBOSE_ERRORS
00118 }
00119
00121 size_t error_parser_failed( universe_T& universe_ )
00122 {
00123 error_show(
00124 universe_,
00125 "error_parser_failed"
00126 );
00127 return universe_T::string_T::npos;
00128 }
00129
00131 size_t error_bad_pi( universe_T& universe_ )
00132 {
00133 error_show(
00134 universe_,
00135 "missing PI name"
00136 );
00137 return universe_T::string_T::npos;
00138 }
00139
00141 size_t error_missing_close_element( universe_T& universe_ )
00142 {
00143 error_show(
00144 universe_,
00145 "error_missing_close_element"
00146 );
00147 return universe_T::string_T::npos;
00148 }
00149
00151 size_t error_missing_pi_close( universe_T& universe_ )
00152 {
00153 error_show(
00154 universe_,
00155 "error_missing_pi_close"
00156 );
00157 return universe_T::string_T::npos;
00158 }
00159
00161 size_t error_missing_comment_close( universe_T& universe_ )
00162 {
00163 error_show(
00164 universe_,
00165 "error_missing_comment_close"
00166 );
00167 return universe_T::string_T::npos;
00168 }
00169
00171 size_t error_bad_attr_format( universe_T& universe_ )
00172 {
00173 error_show(
00174 universe_,
00175 "error_bad_attr_format"
00176 );
00177 return universe_T::string_T::npos;
00178 }
00179
00180 };
00181
00182
00183 #endif //_XML_PARSER_H_INCLUDED_