diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-16 11:42:38 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-16 11:42:38 +0200 |
commit | 03ee21e34a4829644cc07b4fc6378b2f5e1de937 (patch) | |
tree | 2b40334537708c72422789460976cbd87692285f | |
parent | a2d629536b8de88b6b0d0aa043fccd2938769eaa (diff) |
Redo map parser to use sub-parsers for key, value
-rw-r--r-- | cli/runtime-source.cxx | 36 |
1 files 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<K, V>& 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<char*> (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<char*> (kstr.c_str ());" + << "argv_scanner s (0, ac, av);" + << "parser<K>::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<char*> (vstr.c_str ());" + << "argv_scanner s (0, ac, av);" + << "parser<V>::parse (v, s);" << "}" << "m[k] = v;" << "}" - << "}" << "else" << endl << "throw missing_value (o);"; |