title: YAML preprocessor / macro processor
body: <p>Is there a simple way to use a preproccesor / macro-processor with YAML files?  (I.e. I'm thinking of something along the lines of the C preprocessor)?</p>
  
  <p>We have a lot of flat text-files that describes various data structures. They're currently in our own in-house format, and are read with an in-house parser. I'd like to switch to YAML files to make use of the various pre-existing libraries for reading and writing.</p>
  
  <p>However our files are hierarchical, in that we "include" master files into sub files, and using variable substitution generate new data structures.</p>
  
  <p>As a toy example I'd want something like:</p>
  
  <p><strong>country_master.yaml</strong></p>
  
  <pre><code>name: $COUNTRY$
  file: C:\data\$COUNTRY$
  </code></pre>
  
  <p><strong>UK_country.yaml</strong></p>
  
  <pre><code>#define $COUNTRY$ UK
  #include &lt;country_master.yaml&gt;
  </code></pre>
  
  <p><strong>USA_country.yaml</strong></p>
  
  <pre><code>#define $COUNTRY$ USA
  #include &lt;country_master.yaml&gt;
  </code></pre>
  
  <p>Then after preprocessing we'd get something like:</p>
  
  <pre><code>name: USA
  file: C:\data\USA
  </code></pre>
  
  <p>The C-preprocessor won't work with the # character used in YAML comments. Also, ideally we'd like to have loops which are expanded by the preprocessor, so in the above example we'd create UK and USA together with a loop (and I don't believe you can loop with <code>cpp</code>).</p>
  
  <p>Any ideas?</p>