Re: Portin SSAX/SXML

[email protected] Sat, 10 Jul 2004 00:32:31 -0700 (PDT)
Newsgroups gmane.lisp.scheme.ssax-sxml
Message-ID <[email protected]>
Hello!

	First of all I'd like to mention a few adjustments to the test
code and the myenv* files (for those who use them). These adjustments
made it possible to run all regression tests in SSAX/tests --
	on Gambit, Bigloo, SCM and Petite Chez.
As Mike has previously reported, the tests already run on Scheme48
(which is, in my experience, a pretty good indicator of the
portability of Scheme code). We only need to work on
SSAX/examples. They do run on Scheme48, as Mike reported. However, the
infrastructure to run the examples _easily_ on multiple systems is
lacking. 

> Guile's syntax-rules support sucks, though -- the module takes about a
> second to load up.

Perhaps you would like to use SSAX/lib/SSAX-expanded.scm then
(especially for simple.scm, which you enclosed). SSAX-expanded.scm is
the macro-expanded version of SSAX.scm. It is derived automatically,
using Al Petrofsky's portable macro-expander running under Gambit
(the latter does not support syntax-rules, btw). I'm enclosing the code for
reference. One may consider Scheme source with syntax-rules as being
the `source' language, the macro-expanded source to be sort of a CLI,
and the Scheme interpreter/compiler being akin to `VM' or `JIT'.

> The other guile-related bit that matters is input-parse.scm; next-token
> is MUCH MUCH MUCH faster with `read-delimited' from guile's
> (ice-9 rdelim).

I don't know about Guile's module system; some systems support
selected importing of code: you can import input-parse.scm and omit
the next-token function (because you would import it or an appropriate
stub from some other place). If all else fails, one can pre-process
the code being imported to selectively drop certain functions (or
macros). One can even do that on the fly. Just as a weird example of
that, here's the load-all-scm.scm file from kanren project:


> ; Load everything (for interactive use: SCM Scheme)
> ; $Id: load-all-scm.scm,v 1.1 2004/04/10 02:47:20 oleg Exp $
>
> ; For historical reasons, KANREN code uses square brackets, which
> ; SCM does not understand, natively. So, we have to modify load
> ; to cope with them.
>
> (define load
>   (let ((original-load load)
> 	(translated-fname
> 	  (string-append "/tmp/translated-"
> 	    (number->string (current-time))
> 	    ".scm")))
>     (lambda (file-name)
>       (call-with-output-file translated-fname
> 	(lambda (oport)
> 	  (call-with-input-file file-name
> 	    (lambda (iport)
> 	      (do ((c (read-char iport) (read-char iport)))
> 		((eof-object? c))
> 		(write-char
> 		  (case c
> 		    ((#\[) #\( )
> 		    ((#\]) #\) )
> 		    (else c))
> 		  oport))))))
>       (original-load translated-fname))))
>
> (load "lib/scm-specific.scm")
> (load "lib/kanren.ss")
> (load "examples/type-inference.scm")
> (load "examples/typeclasses.scm")
> (load "examples/zebra.scm")
> (load "examples/mirror.scm")
> (load "examples/mirror-equ.scm")
> (load "examples/deduction.scm")

It works, and quite decently.


> Right now I have modules (sxml ssax), (sxml transform) [the
> pre-post-order file], (sxml xpath), and (sxml apply-templates).

Sounds rather reasonable.


> (define* (xml->sxml #:optional (port (current-input-port)))
It should be possible then to define 'define-opt' to map to native
Guile's form define*. define-opt is specifically designed to be
compatible with DSSSL and DSSSL-like forms (as well to be
implementable in R5RS).

>   (let* ((str (symbol->string name))
>          (i (string-index str #\:))
>          (head (or (and i (substring str 0 i)) str))
>          (tail (and i (substring str (1+ i)))))
>     (and i (string-index (substring str (1+ i)) #\:)
>          (error "Invalid QName: more than one colon" name))

Perhaps you'd find (string-split str '(#\:)) to be convenient in the
above case. If str has at most one colon, the result of string-split
is a list of the length at most two. The latter fact is quite easy to
check.


Enclosure: code to `pre-compile' (i.e., macro-expand) SSAX.scm.
prologue.scm is a R5RS version of myenv.scm (based on myenv-chez.scm).
Actually we need only define-syntax forms from prologue.scm...

; macro-expand a source file
;
; We use Portable (or Al Petrofsky's) portable macro-expander
; $Id: expand-syntax.scm,v 1.1 2004/04/29 21:50:36 oleg Exp oleg $

(include "expander.scm")

; (define (pp x)
;     ;;(write x) (newline)    
;     (pretty-print x))

(define (expand-it store loc infile filter k)
  (call-with-input-file infile
    (lambda (iport)
      (let repl ((store store) (loc-n loc))
	(let ((sexp (read iport)))
	  (cond
	    ((eof-object? sexp)
	      (k store loc))
	    ((not (filter sexp)) (repl store loc))
	    (else
	      (expand-top-level sexp store loc-n
		(lambda (sexps store loc-n)
		  (for-each pp sexps)
		  (repl store loc-n))))))))))

(define (root prologue-file infile outfile)
  (with-output-to-file outfile
    (lambda ()
      (for-each pp null-output)
      (expand-it null-store null-loc-n prologue-file 
	(lambda (sexp)
	  (and (pair? sexp) (eq? (car sexp) 'define-syntax)))
	(lambda (store loc)
	  (expand-it store loc infile
	    (lambda (sexp) #t)
	    (lambda (store loc) #t)))))))


(root "lib/prologue.scm" "lib/SSAX.scm" "/tmp/a.scm")



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com