From f8edfd22cb45b554a573d2722900196758e9e958 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Dec 2009 09:47:29 +0200 Subject: Scanner-based parsing with support for element erasing Also implement argv_file_scanner which provides support for reading command line arguments from the argv array as well as files specified with command line options. New examples: file. New tests: ctor, erase, file. --- cli/runtime-header.cxx | 82 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'cli/runtime-header.cxx') diff --git a/cli/runtime-header.cxx b/cli/runtime-header.cxx index cf3ebd3..5da33c0 100644 --- a/cli/runtime-header.cxx +++ b/cli/runtime-header.cxx @@ -12,6 +12,9 @@ generate_runtime_header (context& ctx) { ostream& os (ctx.os); + if (ctx.options.generate_file_scanner ()) + os << "#include " << endl; + os << "#include " << endl << "#include " << endl << "#include " << endl @@ -155,6 +158,30 @@ generate_runtime_header (context& ctx) << "what () const throw ();" << "};"; + if (ctx.options.generate_file_scanner ()) + { + os << "class file_io_failure: public exception" + << "{" + << "public:" << endl + << "virtual" << endl + << "~file_io_failure () throw ();" + << endl + << "file_io_failure (const std::string& file);" + << endl + << "const std::string&" << endl + << "file () const;" + << endl + << "virtual void" << endl + << "print (std::ostream&) const;" + << endl + << "virtual const char*" << endl + << "what () const throw ();" + << endl + << "private:" << endl + << "std::string file_;" + << "};"; + } + // scanner // os << "class scanner" @@ -181,8 +208,8 @@ generate_runtime_header (context& ctx) os << "class argv_scanner: public scanner" << "{" << "public:" << endl - << "argv_scanner (int argc, char** argv);" - << "argv_scanner (int start, int argc, char** argv);" + << "argv_scanner (int& argc, char** argv, bool erase = false);" + << "argv_scanner (int start, int& argc, char** argv, bool erase = false);" << endl << "int" << endl << "end () const;" @@ -199,11 +226,58 @@ generate_runtime_header (context& ctx) << "virtual void" << endl << "skip ();" << endl - << "private:" + << "private:" << endl << "int i_;" - << "int argc_;" + << "int& argc_;" << "char** argv_;" + << "bool erase_;" << "};"; + // argv_file_scanner + // + if (ctx.options.generate_file_scanner ()) + { + os << "class argv_file_scanner: public argv_scanner" + << "{" + << "public:" << endl + << "argv_file_scanner (int& argc," << endl + << "char** argv," << endl + << "const std::string& file_option," << endl + << "bool erase = false);" + << endl + << "argv_file_scanner (int start," << endl + << "int& argc," << endl + << "char** argv," << endl + << "const std::string& file_option," << endl + << "bool erase = false);" + << endl + << "virtual bool" << endl + << "more ();" + << endl + << "virtual const char*" << endl + << "peek ();" + << endl + << "virtual const char*" << endl + << "next ();" + << endl + << "virtual void" << endl + << "skip ();" + << endl + << "private:" << endl + << "void" << endl + << "load (const char* file);" + << endl + << "typedef argv_scanner base;" + << endl + << "const std::string option_;" + << "std::string hold_;" + << "std::deque args_;"; + + if (!ctx.opt_sep.empty ()) + os << "bool skip_;"; + + os << "};"; + } + os << "}"; // namespace cli } -- cgit v1.1