Re: guile's sxml-apply-templates and sxml-match in gauche?

Andreas Reuleaux <[email protected]> Tue, 04 Oct 2022 11:39:16 +0100
Newsgroups gmane.lisp.scheme.gauche
Message-ID <87wn9fhnzf.fsf@softland>
Hi Shiro,

OK, thanks so far already - for pointing in the right direction i.e.:
"rewritten in an er-macro for Gauche" - I may give it a try then myself
sometime (but then: I may get stuck at the very next corner).

If you could keep this in mind (as some wishlist item for Gauche), and
then actually implement it sometime, that would be very nice.

I may be able to do some testing then - I usually use Gauche from Debian
testing - which is a little behind git, but I may keep a Gauche development
version, too, if just for the testing (I think I had it compiled in the
past).

And I could (and maybe should) provide some examples: for testing
(and for other folks interested maybe). My (Guile-) code is actually well
structured: little well-tested pieces of code, building upon each other.
- But I guess, it needs some polishing / writing up (some
explanations i.e.) for other people to be useful.

Thanks again.

-Andreas


Shiro Kawai <[email protected]> writes:

> Hi Andreas,
> Good suggestion.
> The original sxml-match of PLT is under MIT License, so I have no problem
> porting it.  It uses syntax-case macro and needs to be rewritten in
> er-macro for Gauche, which may require quite a bit of surgery (but it
> depends... I have to actually do it to see how it goes.)
>
> --shiro
>
>
>
> On Mon, Oct 3, 2022 at 7:18 PM Andreas Reuleaux <[email protected]> wrote:
>
>> Hi,
>>
>> I have started to work with Scheme's (Gauche's / Guile's) sxml
>> modules/functions, to replace a former xslt / fo (fop) tool chain of mine
>> to create some pdfs:
>>
>> I still rely on fop, to create pdf's from fo files, but these fo
>> files I create with Scheme now, rather than with xslt.
>>
>> formerly:
>>    .xml ----<via xslt and some xslt processor>----> .fo ----<with
>> fop>----> .pdf
>>
>> now:
>>    .xml ----<via scheme / sxml>----> .fo ----<with fop>----> .pdf
>>
>>
>> (And by the way: while fop's real power is to do the last step: .fo -->
>> .pdf:
>>   fop -fo file.fo -pdf file.pdf
>> it can do the first step in the old chain: .xml -> .fo as well (given some
>> xslt style sheet):
>>   fop -xml file.xml -xsl style sheet.xsl -pdf file.pdf
>> but I have never used that: because I rely on
>>   xincludes in my xslt - if I remember right - and fop does not know them).
>>
>>
>> Anyway, my scheme file is about 1/4th of the size of the xslt file, and
>> much more manageable, in that I can use any scheme functions that I like
>> therein (rather than xslt). - And I guess that is some progress /
>> success!! (I have heard other criticism of xslt: that functions are
>> not composable, e.g.)
>>
>> Anyway, my scheme / fop tool chain works fine now - BUT: I use
>> guile-Scheme, not gauche (even though in general I prefer gauche over
>> guile).
>>
>> One (minor) reason:
>> -------------------
>>
>> I rely on apply-templates
>>
>> (as originally defined in
>> https://okmij.org/ftp/Scheme/xml.html
>> https://okmij.org/ftp/Scheme/xml.html#SXSLT-examples
>> and from there:
>> https://okmij.org/ftp/Scheme/apply-templates.scm)
>>
>> And Guile makes that easy to use: it is already included in
>> sxml/apply-templates.scm, thus available with
>>
>>   (use-modules
>>    (sxml apply-templates)
>>   )
>>
>>
>> That is a no-brainer: this apply-templates.scm file is relatively
>> short, and I can just include it by hand.
>> (But it would be useful, if it was included in Gauche, too)!
>>
>> The other, more serious reason, why I rely on Guile for now:
>> ------------------------------------------------------------
>>
>> I rely heavily on sxml-match:
>>
>> https://www.gnu.org/software/guile/manual/html_node/sxml_002dmatch.html
>>
>>   (use-modules
>>    (sxml match)
>>   )
>>
>>
>> sxml/match.scm in guile's source code, which is only a small wrapper /
>> compatibility layer to include PLT scheme's sxml-match.ss.
>>
>>
>>
>> guile's sxml/match.scm
>> -----
>> ;;; -*- mode: scheme; coding: utf-8; -*-
>> ;;;
>> ;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
>> ;;;
>> ;;; This library is free software; you can redistribute it and/or modify it
>> ;;; under the terms of the GNU Lesser General Public License as published
>> by
>> ;;; the Free Software Foundation; either version 3 of the License, or (at
>> ;;; your option) any later version.
>> ;;;
>> ;;; This library is distributed in the hope that it will be useful, but
>> ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
>> ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> Lesser
>> ;;; General Public License for more details.
>> ;;;
>> ;;; You should have received a copy of the GNU Lesser General Public
>> License
>> ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
>>
>> (define-module (sxml match)
>>   #:export (sxml-match
>>             sxml-match-let
>>             sxml-match-let*)
>>   #:use-module (srfi srfi-1)
>>   #:use-module (srfi srfi-11)
>>   #:use-module (ice-9 control))
>>
>>
>> ;;; Commentary:
>> ;;;
>> ;;; This module provides an SXML pattern matcher, written by Jim Bender.
>> This
>> ;;; allows application code to match on SXML nodes and attributes without
>> having
>> ;;; to deal with the details of s-expression matching, without worrying
>> about
>> ;;; the order of attributes, etc.
>> ;;;
>> ;;; It is fully documented in the Guile Reference Manual.
>> ;;;
>> ;;; Code:
>>
>>
>>
>> ;;;
>> ;;; PLT compatibility layer.
>> ;;;
>>
>> (define-syntax-rule (syntax-object->datum stx)
>>   (syntax->datum stx))
>>
>> (define-syntax-rule (void)
>>   *unspecified*)
>>
>> (define (raise-syntax-error x msg obj sub)
>>   (throw 'sxml-match-error x msg obj sub))
>>
>> (define-syntax module
>>   (syntax-rules (provide require)
>>     ((_ name lang (provide p_ ...) (require r_ ...)
>>         body ...)
>>      (begin body ...))))
>>
>>
>> ;;;
>> ;;; Include upstream source file.
>> ;;;
>>
>> ;; This file was taken from
>> ;; <http://planet.plt-scheme.org/package-source/jim/sxml-match.plt/1/1/>
>> on
>> ;; 2010-05-24.  It was written by Jim Bender <[email protected]> and
>> released
>> ;; under the MIT/X11 license
>> ;; <http://www.gnu.org/licenses/license-list.html#X11License>.
>> ;;
>> ;; Modified the `sxml-match1' macro to allow multiple-value returns
>> (upstream
>> ;; was notified.)
>>
>> (include-from-path "sxml/sxml-match.ss")
>>
>> ;;; match.scm ends here
>> --
>>
>>
>>
>> PLT's sxml/sxml-match.ss is the real work horse (much longer,
>> and therefore not shown here).
>>
>>
>> Just including these same match.scm and sxml-match.ss files
>> in gauche, fails for me, however. - And it is a little beyond my current
>> Gauche
>> abilities, to understand how this compatibility macro layer has to be
>> modified for Gauche [?]
>>
>> Maybe (sxml-apply-templates and) sxml-match could be included in
>> future versions of Gauche ?
>>
>> Thanks in advance.
>>   -A
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Gauche-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/gauche-devel
>>
>
> _______________________________________________
> Gauche-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gauche-devel