1 //http://www.boost.org/libs/libraries.htm
6 #include <zypp/base/Logger.h>
7 #include <zypp/base/Exception.h>
8 #include <zypp/base/PtrTypes.h>
9 #include <zypp/parser/tagfile/Tags.h>
11 #include <zypp/NVRA.h>
13 ///////////////////////////////////////////////////////////////////
15 { /////////////////////////////////////////////////////////////////
16 ///////////////////////////////////////////////////////////////////
18 { /////////////////////////////////////////////////////////////////
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
23 void echoOn( std::ostream & str,
24 iterator_t first, const iterator_t last,
28 str << first.get_position() << last.get_position();
30 while ( first != last )
32 str << "<< " << std::endl;
35 void echo( iterator_t first, const iterator_t last, const char* s = "" )
37 echoOn( DBG, first, last, s );
39 void xecho( const char * first, const char *const last, const char* s = "" )
41 DBG << ">>" << std::string(first,last) << "<< " << std::endl;
43 void mecho( iterator_t first, const iterator_t last, const char* s = "" )
45 echoOn( MIL, first, last, s );
48 /////////////////////////////////////////////////////////////////
49 } // namespace tagfile
50 ///////////////////////////////////////////////////////////////////
51 /////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////////////////////
61 ////////////////////////////////////////////////////////////////////////////
66 using namespace zypp::parser::tagfile;
67 typedef scanner<iterator_t> scanner_t;
68 typedef rule<scanner_t> rule_t;
69 ////////////////////////////////////////////////////////////////////////////
73 ////////////////////////////////////////////////////////////////////////////
78 : _begin( time(NULL) )
80 USR << "START MEASURE..." << endl;
84 USR << "DURATION: " << (time(NULL)-_begin) << " sec." << endl;
87 ////////////////////////////////////////////////////////////////////////////
89 NVRA parseNVRA( const std::string & value )
95 parse_info<> info = parse( value.c_str(),
97 lexeme_d[(+~space_p)] [assign_a(n)]
98 >> lexeme_d[(+(~space_p & ~ch_p('-')))] [assign_a(v)]
99 >> lexeme_d[(+(~space_p & ~ch_p('-')))] [assign_a(r)]
100 >> lexeme_d[(+~space_p)] [assign_a(a)]
107 data = NVRA( n, Edition(v,r), Arch(a) );
111 ERR << "parseNVRA failed on " << value << std::endl;
120 static bool isTag( const Tag & tag_r, const std::string & ident_r )
122 return tag_r.ident == ident_r && tag_r.ext.empty();
124 static bool isLangTag( const Tag & tag_r, const std::string & ident_r )
126 return tag_r.ident == ident_r && ! tag_r.ext.empty();
129 bool newPkg( const std::string & value )
131 NVRA data( parseNVRA( value ) );
136 PConsume & operator=( const STag & stag_r )
138 if ( isTag( stag_r.stag, "Pkg" ) )
140 newPkg( stag_r.value );
141 MIL << stag_r << endl;
145 PConsume & operator=( const MTag & mtag_r )
150 scoped_ptr<NVRA> _nvra;
155 template <typename Item>
161 template <typename Item>
162 rule_t operator<<( const Item & stag_r ) const
164 return eps_p;//error_report_p( "neither empty nor comment" );
167 //const phoenix::function<X_impl> XX = X_impl();
169 ////////////////////////////////////////////////////////////////////////////
173 ////////////////////////////////////////////////////////////////////////////
174 int main( int argc, char* argv[] )
176 INT << "===[START]==========================================" << endl;
177 string infile( "p" );
181 // Create a file iterator for this file
182 fiterator_t first(infile);
185 ERR << "Unable to open file!\n";
188 // Create an EOF iterator
189 fiterator_t last = first.make_end();
191 // Create position iterators
192 iterator_t begin( first, last, infile );
203 rule_t a = nothing_p;
204 rule_t x = error_report_p( "abort" );
207 | ( stag //[var(consume)=arg1]
209 | mtag [var(consume)=arg1]
212 >> *(anychar_p - eol_p)
216 | error_report_p( "neither empty nor comment" )
221 shared_ptr<Measure> duration( new Measure );
222 parse_info<iterator_t> info
223 = parse( begin, end, file );
228 USR << "Parse succeeded!\n";
231 ERR << "Parse partial!\n";
232 ERR << " at pos " << info.length << endl;
236 ERR << "Parse failed!\n";
237 ERR << " at pos " << info.length << endl;
240 INT << "===[END]============================================" << endl;