Drop (chibi sxml) dependency on let-optionals

let-optionals can be provided by the (chibi optional) library or by
SRFI 227. Either dependency is non-trivial and makes it tricky to
incorporate (chibi sxml) into outside projects. Since (chibi sxml)
only makes trivial use of let-optionals, expand the macro by hand.
This commit is contained in:
Lassi Kortela 2023-04-21 16:42:03 +03:00
parent 2dc7dd5b68
commit 561fc1bae0
2 changed files with 7 additions and 4 deletions

View file

@ -91,9 +91,12 @@
;;> Render (valid, expanded) \var{sxml} as html. ;;> Render (valid, expanded) \var{sxml} as html.
;;> \var{@raw} tag is considered safe text and not processed or escaped. ;;> \var{@raw} tag is considered safe text and not processed or escaped.
(define (sxml-display-as-html sxml . o) (define (sxml-display-as-html sxml . args)
(let-optionals o ((out (current-output-port)) (let* ((out (if (null? args) (current-output-port) (car args)))
(indent? #false)) (args (if (null? args) args (cdr args)))
(indent? (if (null? args) #f (car args)))
(args (if (null? args) args (cdr args))))
(unless (null? args) (error "too many args"))
(let lp ((sxml (if (and (pair? sxml) (eq? '*TOP* (car sxml))) (let lp ((sxml (if (and (pair? sxml) (eq? '*TOP* (car sxml)))
(cdr sxml) (cdr sxml)
sxml)) sxml))

View file

@ -4,5 +4,5 @@
(define-library (chibi sxml) (define-library (chibi sxml)
(export sxml->xml sxml-display-as-html sxml-display-as-text sxml-strip (export sxml->xml sxml-display-as-html sxml-display-as-text sxml-strip
html-escape html-tag->string) html-escape html-tag->string)
(import (chibi optional) (scheme base) (scheme write)) (import (scheme base) (scheme write))
(include "sxml.scm")) (include "sxml.scm"))