title: how to write a simple peg grammar for a liquid-like templating language?
body: <p>edit: you can follow the progress here: <a href="https://github.com/simple-updates/template" rel="nofollow noreferrer">https://github.com/simple-updates/template</a></p>
  
  <p>I'm using <a href="https://pegjs.org/" rel="nofollow noreferrer">peg.js</a> and trying to write something that could interpret a template like:</p>
  
  <pre><code>hello {{ "world" }}
  {% if a %}
    good {{ a }}
  {% else %}
    bad
  {% endif %}
  </code></pre>
  
  <p>I've tried many things but let's say this is my starting point:</p>
  
  <pre><code>Template
    = ws markup ws
  
  ws = " "*
  
  open_interpolation = "{{"
  close_interpolation = "}}"
  open_tag = "{%"
  close_tag = "%}"
  
  char = . // ?
  
  markup =
    (open_tag tag:char* close_tag)
    { return { 'tag': tag.join('') } } /
    (open_interpolation interpolation:char* close_interpolation)
    { return { 'interpolation': interpolation.join('') } } /
    chars:char*
    { return { 'chars': chars.join('') } }
  </code></pre>
  
  <p>when I try on the string <code>{{ test }}</code> for instance it will just interpret it as chars instead of an interpolation.</p>
  
  <p>any idea of how I could do it?</p>
  
  <p>(obviously it would be more complex with nested "markups")</p>