(I'm new enough to Lisp not to know how to do this, but familiar enough to know there just must be a simple way.)
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.
Parsing s-expressions where the delimiters are parentheses is easy
"(my-function foo bar)"
can be read from a file/stream and evaluated trivially.
And if XML is really just an S-expression, shouldn't there be an easy way to transform something as simple as
<function>foo bar etc-1 etc-2</function>
into
(function foo bar etc-1 etc-2)
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.
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).
So, in short: 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)?