Lambda the Ultimate

inactiveTopic Languages or tools to play with rewrite rules?
started 12/9/2001; 2:38:47 PM - last post 12/10/2001; 1:11:07 PM
Ramon M. Felciano - Languages or tools to play with rewrite rules?  blueArrow
12/9/2001; 2:38:47 PM (reads: 301, responses: 2)
Hi --

I'm looking for tools or libraries to help play with rewrite rules to process XML files. FWIW, a number of these XML files are XMLized versions of Prolog / Lisp-ish query expressions of the form (:AND (MyClass1 ?instance) (MyField1 ?instance ?fieldvalue)), so my guess is I should be looking at query optimization toolkits from DB fields as well as languages.

This is primarily a learning experience for me, and I would like to try rewrite rules for a number of different purposes:

- Optimization (path expressions, - Translation (convert 1 XML file to another) - Pretty-printing (formatting, infix/prefix conversions, and other syntactic sugar) - Pretty-reading (rewrite in more easily understandable, tho possibly less efficient, form)

The obvious thing to look at purely from a data type standpoint is XSLT, but it isn't really a full-fledged rule system. Still, I'm looking to try *using* such a system, not building one, so XSLT might win just from the standpoint of availability.

Any other suggestions?

Ramon

Noel Welsh - Re: Languages or tools to play with rewrite rules?  blueArrow
12/10/2001; 6:22:08 AM (reads: 331, responses: 0)
I've had some success using PLT Scheme and the syntax-case pattern matching system. You'll need PLT Scheme v200 for this (download.plt-scheme.org). Although syntax-case is designed for writing macros it makes an excellent general purpose tool for pattern matching on tree. The xml library in PLT Scheme allows you to read in XML as s-expression so they are easy to manipulate.

Oleg - Re: Languages or tools to play with rewrite rules?  blueArrow
12/10/2001; 1:11:07 PM (reads: 316, responses: 0)
You might be interested in SXML, which is specifically designed to facilitate processing via re-write rules.

http://pobox.com/~oleg/ftp/Scheme/SXML-short-paper.html http://pobox.com/~oleg/ftp/Scheme/xml.html

The site offers two re-write processors: post-order and apply-templates. The post-order processor has been used for "denormalization" of XML and for pretty-printing of SXML into XML, HTML or LaTeX. The SXML specification is the example of such translations. There are several ways of implementing your "(:AND (MyClass1 ?instance) (MyField1 ?instance ?fieldvalue))" query with post-order. In fact, SXML->HTML translator runs a similar query to generate hierarchical TOCs.

SXML is amenable to queries using SXML-ized forms of XPath. SXML tools run on a variety of Scheme systems (PLT Scheme, Gambit, Bigloo, Guile, RScheme, Chicken, etc).