title: Parsing a TCL-like text
body: <p>I have a configuration text that looks like this:</p>
  
  <pre><code>text="""
  key1 value1
  key2 { value1 value2 }
  key3 subkey1 {
      key1 1
      key2 2
      key3 {
          value1
      }
  }
  
  BLOBKEY name {
      dont {
          # comment
          parse { me }
      }
  }
  
  key3 subkey2 {
      key1 value1
  }
  
  """
  </code></pre>
  
  <p>The values are plain strings or quoted strings. The keys are just alphanum strings. I know before hand that <code>key2</code> and <code>key3.subkey1.key4</code> will hold sets, so I can treat those paths differently. Likewise, I know that <code>BLOBKEY</code> will contain an "escaped" configuration section. </p>
  
  <p>The goal is to convert it into a dictionary that looks like this:</p>
  
  <pre><code>{'key1': 'value1',
   'key2': set(['value1', 'value2']),
   'key3': {
      'subkey1': {
          'key1': 1,
          'key2': 2,
          'key3': set(['value1']),
      },
      'subkey2': {
          'key1': 'value1'
      }
   },
   'BLOBKEY': {
      'name': "    dont {\n        # comment\n        parse { me }\n    }\n"
   }
  }
  </code></pre>
  
  <p>This code below does a pretty good job at breaking it down to a bunch of nested lists.</p>
  
  <pre><code>import pyparsing
  string = pyparsing.CharsNotIn("{} \t\r\n")
  group = pyparsing.Forward()
  group &lt;&lt; ( 
             pyparsing.Group(pyparsing.Literal("{").suppress() + 
                             pyparsing.ZeroOrMore(group) + 
                             pyparsing.Literal("}").suppress()) |
             string
             )
  
  toplevel = pyparsing.OneOrMore(group)
  </code></pre>
  
  <p>What's the best way to get the result I want, in Python using pyparsing?</p>