Using Relax NG as a grammar

Random thought of the day…

I was reading over Tim B.'s blog [1] regarding Relax NG and looking
over an example of it from wikipedia [2] and I thought to myself,
“Self, couldn’t you use this for a language specification? Say, for
Ruby even?”

Thoughts? Beyond, “XML is evil!” or “Use YAML instead!”, I mean.

  • Dan

[1] ongoing by Tim Bray · Choose RELAX Now
[2] RELAX NG - Wikipedia

Daniel B. wrote:

Random thought of the day…

I was reading over Tim B.'s blog [1] regarding Relax NG and looking
over an example of it from wikipedia [2] and I thought to myself,
“Self, couldn’t you use this for a language specification? Say, for
Ruby even?”

Do you mean instead of BNF, for example?


James B.

http://www.rubyaz.org - Hacking in the Desert
http://www.jamesbritt.com - Playing with Better Toys

!! http://barcamp.org/BarCampPhoenix 9 Dec 2006 !!

Daniel B. wrote:

Random thought of the day…

I was reading over Tim B.'s blog [1] regarding Relax NG and looking
over an example of it from wikipedia [2] and I thought to myself,
“Self, couldn’t you use this for a language specification? Say, for
Ruby even?”

It is meant to be used for language specification, so that’s why it
looks suitable. It’s only that it’s meant for specifying grammars for
languages using XML syntax, and so it’s (rightly) very limited in terms
of tokenization etc. which makes it unsuitable for more general
languages like Ruby.

Vidar

James B. wrote:

Daniel B. wrote:

Random thought of the day…

I was reading over Tim B.'s blog [1] regarding Relax NG and looking
over an example of it from wikipedia [2] and I thought to myself,
“Self, couldn’t you use this for a language specification? Say, for
Ruby even?”

Do you mean instead of BNF, for example?

Yes.

  • Dan

On 12/6/06, Vidar H. [email protected] wrote:

It is meant to be used for language specification, so that’s why it
looks suitable. It’s only that it’s meant for specifying grammars for
languages using XML syntax, and so it’s (rightly) very limited in terms
of tokenization etc. which makes it unsuitable for more general
languages like Ruby.

Ah, but after you’re done tokenizing and have generated an abstract
syntax tree, what have you got? You could output the syntax tree into
Lisp S-Expressions, which are isomorphic to XML in a very real way. It
would, of course, be trivial if your source language was a Lisp
dialect. Relax-NG might be useful for defining the higher-level
semantics of a language, but the lower-level (and generally less
interesting) work of defining the syntactic details of the language
you need to do yourself.

syntax tree, what have you got? You could output the syntax tree into
Lisp S-Expressions, which are isomorphic to XML in a very real way. It

Sorry if this is madness, but does that mean it is theoretically
possible to implement Lisp as XML?

On Dec 6, 2006, at 4:10 PM, Giles B. wrote:

syntax tree, what have you got? You could output the syntax tree into
Lisp S-Expressions, which are isomorphic to XML in a very real
way. It

Sorry if this is madness, but does that mean it is theoretically
possible to implement Lisp as XML?

I’m sure I will be shot for this, but that almost strikes me as a fun
Ruby Q…

James Edward G. II

It’s already kindof been done:
http://thedailywtf.com/forums/56328/ShowPost.aspx
Warning: contains some bad language.

The whole concept is bad language.

That’s a great site, though.

“XSL was shown to be Turing complete shortly after it’s proposal in
1999.”

On 12/7/06, Giles B. [email protected] wrote:

syntax tree, what have you got? You could output the syntax tree into
Lisp S-Expressions, which are isomorphic to XML in a very real way. It

Sorry if this is madness, but does that mean it is theoretically
possible to implement Lisp as XML?

Yes, it is madness, and yes, unfortunately, it has been done. There’s
that language called XSLT which you may remember… Frankly, I find
S-Expressions far easier to read than XML, so much so that I actually
wrote a small utility once upon a time to convert S-expression input
into XML output (and I did it mainly to make XSLT programs I once
wrote when I was experimenting with it easier to read! I don’t have
the code anymore, but I remember that it wasn’t difficult to do with
Ruby). There’s also this little project:

http://weitz.de/cl-who/

that generates HTML/XML from Common Lisp.