title: Parsing S-expressions with arbitrary delimiters in LISP
body: <p>(I'm new enough to Lisp not to know how to do this, but familiar enough to know there just <em>must</em> be a simple way.)</p>
  
  <p>I was intrigued by an article that I read recently which advocated storing log files as Lisp-style S-expressions, so that the log files could be turned into a DSL easily. This got me thinking about similar grammars for other DSLs, but I've run into a snag.</p>
  
  <p>Parsing s-expressions where the delimiters are parentheses is easy </p>
  
  <pre><code>"(my-function foo bar)"
  </code></pre>
  
  <p>can be read from a file/stream and evaluated trivially.</p>
  
  <p>And if XML is really just an S-expression, shouldn't there be an easy way to transform something as simple as</p>
  
  <pre><code>&lt;function&gt;foo bar etc-1 etc-2&lt;/function&gt;
  </code></pre>
  
  <p>into</p>
  
  <pre><code>(function foo bar etc-1 etc-2)
  </code></pre>
  
  <p>I can fake this behavior with string manipulation techniques (heck, a regex could take care of this, really). But that seems like Lisp blasphemy - these are just S-expressions! The same applies for the Lisp-based versions of lex/yacc - I can see the need for more complex syntax, but really, this is just Lisp syntax disguised in a less efficient manner.</p>
  
  <p>This should, in theory, extend beyond XML, to any context-free grammar that is a homomorphism of the Lisp grammar. (I know that Lisp is supposedly not perfectly defined by a context-free grammar as simple as the S-expression, but obviously the latter is a strict subset of the former, so my statement still stands).</p>
  
  <p><strong>So, in short:</strong> Is there a simple way to define the syntax for a context-free grammar homomorphic to S-expressions (like XML, for example) and parse that grammar within Lisp (or a Lisp-based DSL)?</p>