From cfb91e263c22f6f81ae05a2027a2befac6d41e06 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 4 Oct 2009 10:50:50 +0200 Subject: Add --reserved-name option --- cli/context.cxx | 2 +- cli/context.hxx | 4 +--- cli/options.cli | 3 +++ cli/options.cxx | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- cli/options.hxx | 6 +++++ cli/options.ixx | 6 +++++ 6 files changed, 86 insertions(+), 8 deletions(-) (limited to 'cli') diff --git a/cli/context.cxx b/cli/context.cxx index 1af10e8..b82a318 100644 --- a/cli/context.cxx +++ b/cli/context.cxx @@ -16,7 +16,7 @@ context (ostream& os_, semantics::cli_unit& unit_, options_type const& ops) unit (unit_), options (ops), inl (data_->inl_), - reserved_name_map (data_->reserved_name_map_) + reserved_name_map (options.reserved_name ()) { if (!options.suppress_inline ()) inl = "inline "; diff --git a/cli/context.hxx b/cli/context.hxx index 8063f59..f57ac7f 100644 --- a/cli/context.hxx +++ b/cli/context.hxx @@ -38,14 +38,12 @@ public: string& inl; typedef std::map reserved_name_map_type; - reserved_name_map_type& reserved_name_map; + reserved_name_map_type const& reserved_name_map; private: struct data { string inl_; - - reserved_name_map_type reserved_name_map_; }; public: diff --git a/cli/options.cli b/cli/options.cli index 28f6495..8c7bdda 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -7,6 +7,7 @@ // before modifying this file. // +include ; include ; include ; @@ -25,4 +26,6 @@ class options bool --include-with-brackets; std::string --include-prefix; std::string --guard-prefix; + + std::map --reserved-name; }; diff --git a/cli/options.cxx b/cli/options.cxx index 803e22b..b47a5c8 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -4,6 +4,7 @@ #include "options.hxx" +#include #include #include #include @@ -146,6 +147,64 @@ namespace cli } }; + template + struct parser > + { + static int + parse (std::map& m, char** argv, int n) + { + if (n > 1) + { + std::string s (argv[1]); + std::string::size_type p (s.find ('=')); + + if (p == std::string::npos) + { + K k = K (); + + if (!s.empty ()) + { + std::istringstream ks (s); + + if (!(ks >> k && ks.eof ())) + throw invalid_value (argv[0], argv[1]); + } + + m[k] = V (); + } + else + { + K k = K (); + V v = V (); + std::string kstr (s, 0, p); + std::string vstr (s, p + 1); + + if (!kstr.empty ()) + { + std::istringstream ks (kstr); + + if (!(ks >> k && ks.eof ())) + throw invalid_value (argv[0], argv[1]); + } + + if (!vstr.empty ()) + { + std::istringstream vs (vstr); + + if (!(vs >> v && vs.eof ())) + throw invalid_value (argv[0], argv[1]); + } + + m[k] = v; + } + + return 2; + } + else + throw missing_value (argv[0]); + } + }; + template int thunk (X& x, char** argv, int n) @@ -174,7 +233,8 @@ options (int argc, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - guard_prefix_ () + guard_prefix_ (), + reserved_name_ () { _parse (1, argc, argv, opt, arg); } @@ -194,7 +254,8 @@ options (int start, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - guard_prefix_ () + guard_prefix_ (), + reserved_name_ () { _parse (start, argc, argv, opt, arg); } @@ -214,7 +275,8 @@ options (int argc, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - guard_prefix_ () + guard_prefix_ (), + reserved_name_ () { end = _parse (1, argc, argv, opt, arg); } @@ -235,7 +297,8 @@ options (int start, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - guard_prefix_ () + guard_prefix_ (), + reserved_name_ () { end = _parse (start, argc, argv, opt, arg); } @@ -270,6 +333,8 @@ struct _cli_options_map_init &::cli::thunk; _cli_options_map_["--guard-prefix"] = &::cli::thunk; + _cli_options_map_["--reserved-name"] = + &::cli::thunk, &options::reserved_name_>; } } _cli_options_map_init_; diff --git a/cli/options.hxx b/cli/options.hxx index e2c0109..2906344 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -168,6 +168,8 @@ namespace cli }; } +#include + #include #include @@ -234,6 +236,9 @@ class options std::string const& guard_prefix () const; + std::map const& + reserved_name () const; + private: int _parse (int start, @@ -253,6 +258,7 @@ class options bool include_with_brackets_; std::string include_prefix_; std::string guard_prefix_; + std::map reserved_name_; }; #include "options.ixx" diff --git a/cli/options.ixx b/cli/options.ixx index 11a1776..12cb277 100644 --- a/cli/options.ixx +++ b/cli/options.ixx @@ -65,3 +65,9 @@ guard_prefix () const return guard_prefix_; } +inline std::map const& options:: +reserved_name () const +{ + return reserved_name_; +} + -- cgit v1.1