https://github.com/akkartik/mu/blob/master/017parse_tree.cc
  1 // So far instructions can only contain linear lists of properties. Now we add
  2 // support for more complex trees of properties in dilated reagents. This will
  3 // come in handy later for expressing complex types, like "a dictionary from
  4 // (address to array of charaters) to (list of numbers)".
  5 //
  6 // Type trees aren't as general as s-expressions even if they look like them:
  7 // the first element of a type tree is always an atom, and it can never be
  8 // dotted (right->right->right->...->right is always NULL).
  9 //
 10 // For now you can't use the simpler 'colon-based' representation inside type
 11 // trees. Once you start typing parens, keep on typing parens.
 12 
 13 :(scenarios load)
 14 :(scenario dilated_reagent_with_nested_brackets)
 15 def main [
 16   {1: number, foo: (bar (baz quux))} <- copy 34
 17 ]
 18 +parse:   product: {1: "number", "foo": ("bar" ("baz" "quux"))}
 19 
 20 :(before "End Parsing Dilated Reagent Property(value)")
 21 value = parse_string_tree(value);
 22 :(before "End Parsing Dilated Reagent Type Property(type_names)")
 23 type_names = parse_string_tree(type_names);
 24 
 25 :(code)
 26 string_tree* parse_string_tree(string_tree* s) {
 27   assert(s->atom);
 28   if (!starts_with(s->value, "(")) return s;
 29   string_tree* result = parse_string_tree(s->value);
 30   delete s;
 31   return result;
 32 }
 33 
 34 string_tree* parse_string_tree(const string& s) {
 35   istringstream in(s);
 36   in >> std::noskipws;
 37   return parse_string_tree(in);
 38 }
 39 
 40 string_tree* parse_string_tree(istream& in) {
 41   skip_whitespace_but_not_newline(in);
 42   if (!has_data(in)) return NULL;
 43   if (in.peek() == ')') {
 44     in.get();
 45     return NULL;
 46   }
 47   if (in.peek() != '(') {
 48     string s = next_word(in);
 49     if (s.empty())<
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.gui.ui</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href=&quo