about summary refs log blame commit diff stats
path: root/mu-init.subx
blob: feab920f2ecf93949c86ae6218805240c2bc094b (plain) (tree)
ringstream result; char c; list<char> open_brackets; while (in >> c) { if (c == '(') open_brackets.push_back(c); if (c == ')') { if (open_brackets.empty() || open_brackets.back() != '(') { raise << "unbalanced ')'\n" << end(); continue; } assert(open_brackets.back() == '('); open_brackets.pop_back(); } if (c == '[') open_brackets.push_back(c); if (c == ']') { if (open_brackets.empty() || open_brackets.back() != '[') { raise << "unbalanced ']'\n" << end(); continue; } open_brackets.pop_back(); } if (c == '{') open_brackets.push_back(c); if (c == '}') { if (open_brackets.empty() || open_brackets.back() != '{') { raise << "unbalanced '}'\n" << end(); continue; } open_brackets.pop_back(); } result << c; if (open_brackets.empty()) break; } skip_whitespace_and_comments_but_not_newline(in); return result.str(); } :(after "Parsing reagent(string s)") if (starts_with(s, "{")) { assert(properties.empty()); istringstream in(s); in >> std::noskipws; in.get(); // skip '{' name = slurp_key(in); if (name.empty()) { raise << "invalid reagent '" << s << "' without a name\n" << end(); return; } if (name == "}") { raise << "invalid empty reagent '" << s << "'\n" << end(); return; } { string s = next_word(in); if (s.empty()) { assert(!has_data(in)); raise << "incomplete dilated reagent at end of file (0)\n" << end(); return; } string_tree* type_names = new string_tree(s); // End Parsing Dilated Reagent Type Property(type_names) type = new_type_tree(type_names); delete type_names; } while (has_data(in)) { string key = slurp_key(in); if (key.empty()) continue; if (key == "}") continue; string s = next_word(in); if (s.empty()) { assert(!has_data(in)); raise << "incomplete dilated reagent at end of file (1)\n" << end(); return; } string_tree* value = new string_tree(s); // End Parsing Dilated Reagent Property(value) properties.push_back(pair<string, string_tree*>(key, value)); } return; } :(code) string slurp_key(istream& in) { string result = next_word(in); if (result.empty()) { assert(!has_data(in)); raise << "incomplete dilated reagent at end of file (2)\n" << end(); return result; } while (!result.empty() && *result.rbegin() == ':') strip_last(result); while (isspace(in.peek()) || in.peek() == ':') in.get(); return result; }