From 03ee21e34a4829644cc07b4fc6378b2f5e1de937 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 16 Nov 2015 11:42:38 +0200 Subject: Redo map parser to use sub-parsers for key, value --- cli/runtime-source.cxx | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/cli/runtime-source.cxx b/cli/runtime-source.cxx index cff4e7b..36d5e3f 100644 --- a/cli/runtime-source.cxx +++ b/cli/runtime-source.cxx @@ -595,50 +595,34 @@ generate_runtime_source (context& ctx, bool complete) << "parse (std::map& m, " << (sp ? "bool& xs, " : "") << "scanner& s)" << "{" - << "std::string o (s.next ());" + << "const char* o (s.next ());" << endl << "if (s.more ())" << "{" << "std::string ov (s.next ());" << "std::string::size_type p = ov.find ('=');" << endl - << "if (p == std::string::npos)" - << "{" - << "K k = K ();" - << endl - << "if (!ov.empty ())" - << "{" - << "std::istringstream ks (ov);" - << endl - << "if (!(ks >> k && ks.eof ()))" << endl - << "throw invalid_value (o, ov);" - << "}" - << "m[k] = V ();" - << "}" - << "else" - << "{" << "K k = K ();" << "V v = V ();" << "std::string kstr (ov, 0, p);" - << "std::string vstr (ov, p + 1);" + << "std::string vstr (ov, (p != std::string::npos ? p + 1 : ov.size ()));" << endl + << "int ac (2);" + << "char* av[] = {const_cast (o), 0};" << "if (!kstr.empty ())" << "{" - << "std::istringstream ks (kstr);" - << endl - << "if (!(ks >> k && ks.eof ()))" << endl - << "throw invalid_value (o, ov);" + << "av[1] = const_cast (kstr.c_str ());" + << "argv_scanner s (0, ac, av);" + << "parser::parse (k, s);" << "}" << "if (!vstr.empty ())" << "{" - << "std::istringstream vs (vstr);" - << endl - << "if (!(vs >> v && vs.eof ()))" << endl - << "throw invalid_value (o, ov);" + << "av[1] = const_cast (vstr.c_str ());" + << "argv_scanner s (0, ac, av);" + << "parser::parse (v, s);" << "}" << "m[k] = v;" << "}" - << "}" << "else" << endl << "throw missing_value (o);"; -- cgit v1.1