From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Dr. Arne Babenhauserheide" Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] add SRFI-119 / language/wisp to Guile? (new patch, squashed) Date: Fri, 18 Aug 2023 19:50:52 +0200 Message-ID: <87wmxsck60.fsf@web.de> References: <87h6w2fkz8.fsf@web.de> <87357ldqaq.fsf@web.de> <1a70460e-11fb-9f5d-0d5f-1eb507d5af0d@telenet.be> <87ilg4j65e.fsf@web.de> <87edqsj5vt.fsf@web.de> <01212259-37dd-5d67-7bbc-101e01d96d01@telenet.be> <1a6c8dda-0124-124c-f932-937a11386ced@gmail.com> <87fsb5i912.fsf@web.de> <87ttzc7gwa.fsf@gnu.org> <1e0d07bc-dcf8-fe56-7f16-a72e5df0c20d@telenet.be> <875ybr2hk9.fsf@gnu.org> <87v8jrdmk5.fsf@web.de> <87jzzr7cba.fsf@web.de> <87v8hc8i8v.fsf@web.de> <87legrs23a.fsf@gnu.org> <209e68fd-b010-8213-6c9b-a0d1b8f0f72c@telenet.be> <87o7jf2slw.fsf@web.de> <875y5h8j04.fsf@web.de> <87il9ctzhl.fsf@gnu.org> <875y5cdyvt.fsf@web.de> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28389"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.10.5; emacs 29.0.92 Cc: Ludovic =?utf-8?Q?Court=C3=A8s?= , guile-devel@gnu.org To: "Dr. Arne Babenhauserheide" Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Aug 18 19:53:10 2023 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qX3eo-000786-HR for guile-devel@m.gmane-mx.org; Fri, 18 Aug 2023 19:53:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qX3eT-0000PX-0h; Fri, 18 Aug 2023 13:52:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qX3eQ-0000P4-Qd for guile-devel@gnu.org; Fri, 18 Aug 2023 13:52:46 -0400 Original-Received: from mout.web.de ([212.227.15.3]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qX3eM-0002cu-Rx; Fri, 18 Aug 2023 13:52:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1692381161; x=1692985961; i=arne_bab@web.de; bh=o+X0eJDF7Nwu3ObQ5YFF1L2B0xav3hQY5pYoP/timo8=; h=X-UI-Sender-Class:References:From:To:Cc:Subject:Date:In-reply-to; b=BhvGPv0QrB5XILWQkXk3zQhIUb8V63mu9MxHuEU2hNjlwuOQZCEQen7rSVtTRP0KcPo1zEZ nA+/kHlRcfIf3SUUkL6PulH5k/cyShUqqfdc0WuQyvxzyAwD0htZmRiWjq3U7V8cBCiyCnsh0 CiXD2jZ5rSIOnB0+IHj9dj/kaBYQYMvYPYeRAYFcRn+yMxIz6mcsAaQ7g4LtSZnwFo0QFZzO4 +ec0LG+Q0ZmbMfJfkjUbv5PSAA8+mkf6MGHE5bm+ToN4Wyz8KDZI5d7hFC1NwEJUmtDTDLYRo dArQR/Xicn1NZA5RzU/3XJy8u3AZLuK+8qxoQWiwYugK2PYhzLkA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from fluss ([84.165.27.117]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MumJD-1pfMbL2ks7-00rV9J; Fri, 18 Aug 2023 19:52:40 +0200 In-reply-to: <875y5cdyvt.fsf@web.de> X-Provags-ID: V03:K1:y4XN7kOjBl3OykXsXrptCOY5WlmLUb3kt38IKUShxgllrkr1RCW l5RWpSNxCUXK9LJy+UdvcLL1GFagNM7FnlblI5ozpUDapoRtkX4G8XsxLenebaPoQuM3YGA wdXBJ2N4YFyMvLaZYsBmQVJaomiLuMfznzIcsVdRRscDOwLBtonigQFgOSumWErYEdaK/o3 uyh3XAL0UItA+7CQVoOQA== UI-OutboundReport: notjunk:1;M01:P0:wQWPFNYsKFQ=;v2OXC/UEIROrfDD3Nb+98JchzHG YKGf4ANnezcOf+sMgqcVqibvWkyLdBICDFPHq5jiPlFAUh+OkXwWaw25NIYq9ogH8tdeJ/2JJ +5YNl9vuC/bLH3M4qzBMWWIoNGpZitWDiPUZydw7yUoMVYhdi2uw3vIeePbr6cmUlvpkTh8eA 1jHLJKOuT1ybXKGF0lX9jbtEGYQX1buR3hOPl6zi5Mcom1LwXnw5zOleIYi+G6am3uZyLoS8T C6FuOWHLPu4XuVBFKMS0collH/w7uOSwbJh9se6GVLsNYlmdhzWzBv2Y53uqfvOLi9U8BTJvI SKG90J7AN/nB+not/CSWdvU3+/6Ms6LiUAPhfcxYBi74Qg0gB9z9TELj+iNIBye1+RCp/hTzm bynBc1oWeaMqDUxNoe0mFSusJjFzjrCgU5kA1HVPnMhal6ubIv75J06R+FhhsFKhbd2j9j5ZA p2FMpSl9GjshNmngCnYAexEsiB3c+U2Phl7hSKhl3Gtt18o0q58PZ+Gtp9HD+tR71RDVJxRIe hutsfjAO4JRhvQ+leVTrT70BJjjME4rqOCbYWOXFtcIdZduot3UTwE+0ZkefUg+JwOj0F47bu 5Je4BiVY3otzXFWTBDE0oc9/Rro8O/LTibYXvxq2SOYMRlqZJhJpFbUIK5izLocIhXcrjpl3j DNQ6tyFGahARMtY77kD/qgLFEcBI06aljsJKatolfQoMTPMc3nFLNIuugqPvkCxbCKqiOyDLo 3uchRGkvJXhiSa7zpah6mkamHMH+w5yPWUZCcXXbL46R5Mj20ZPE3STIcAGtyz0gF1dXheRS Received-SPF: pass client-ip=212.227.15.3; envelope-from=arne_bab@web.de; helo=mout.web.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:21919 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable "Dr. Arne Babenhauserheide" writes: > I=E2=80=99m attaching the new squashed patch again here and will add the = patches > for the review changes to a second email. Attached are the promised patches of the additional review changes. Thank you for your review! --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0012-SRFI-119-Wisp-Fix-capitalize-Wisp.patch Content-Transfer-Encoding: quoted-printable From=203d9b452137911e1948586657edb1ea614d8a70c0 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Tue, 15 Aug 2023 00:43:53 +0200 Subject: [PATCH 12/21] SRFI-119 (Wisp): Fix: capitalize Wisp * doc/ref/srfi-modules.texi (srfi-119): capitalize Wisp =2D-- doc/ref/srfi-modules.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi index 5b82f8070..0ffc01252 100644 =2D-- a/doc/ref/srfi-modules.texi +++ b/doc/ref/srfi-modules.texi @@ -5686,7 +5686,7 @@ define : factorial n @result{} (define (fa= ctorial n) * n : factorial @{n - 1@} @result{} (* n (factorial @{n - 1@})))) @end example =20 =2DTo execute a file with wisp code, select the language and filename +To execute a file with Wisp code, select the language and filename extension @code{.w} vie @code{guile --language=3Dwisp -x .w}. =20 In files using Wisp, @xref{SRFI-105} (Curly Infix) is always activated. =2D-=20 2.41.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0013-SRFI-119-Wisp-Fix-capitalize-Scheme.patch Content-Transfer-Encoding: quoted-printable From=20d8585c6380cbdba2ad0f6c56aaf6637826cd5b93 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Tue, 15 Aug 2023 00:46:53 +0200 Subject: [PATCH 13/21] SRFI-119 (Wisp): Fix: capitalize Scheme * modules/language/wisp.scm (comments): capitalize Scheme =2D-- module/language/wisp.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/language/wisp.scm b/module/language/wisp.scm index b4e885eec..f3127c9d3 100644 =2D-- a/module/language/wisp.scm +++ b/module/language/wisp.scm @@ -21,7 +21,7 @@ ;;; Commentary: =20 ;; Scheme-only implementation of a wisp-preprocessor which output a =2D;; scheme code tree to feed to a scheme interpreter instead of a +;; Scheme code tree to feed to a Scheme interpreter instead of a ;; preprocessed file. =20 ;; Limitations: =2D-=20 2.41.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0014-SRFI-119-Wisp-Fix-capitalize-Wisp.patch Content-Transfer-Encoding: quoted-printable From=2044344fa738cb51b034bb03791a6e1ee828390a42 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Tue, 15 Aug 2023 00:56:07 +0200 Subject: [PATCH 14/21] SRFI-119 (Wisp): Fix: capitalize Wisp * modules/language/wisp/spec.scm (define-language): capitalize Wisp =2D-- module/language/wisp/spec.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/language/wisp/spec.scm b/module/language/wisp/spec.scm index 1efd3e8b2..5f8feca9a 100644 =2D-- a/module/language/wisp/spec.scm +++ b/module/language/wisp/spec.scm @@ -57,7 +57,7 @@ #:compilers `((tree-il . ,compile-tree-il)) #:decompilers `((tree-il . ,decompile-tree-il)) #:evaluator (lambda (x module) (primitive-eval x)) =2D #:printer write ; TODO: backtransform to wisp? Use source-properties? + #:printer write ; TODO: backtransform to Wisp? Use source-properties? #:make-default-environment (lambda () ;; Ideally we'd duplicate the whole module hierarchy so that `set!', =2D-=20 2.41.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0015-SRFI-119-Wisp-cleanup-char-list-cond.patch Content-Transfer-Encoding: quoted-printable From=2016967e979262f7f3d86e194295a1a3f5a7f68cd0 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Fri, 18 Aug 2023 19:06:23 +0200 Subject: [PATCH 15/21] SRFI-119 (Wisp): cleanup char-list cond * module/language/wisp.scm (match-charlist-to-repr): use helper and re-inde= nt =2D-- module/language/wisp.scm | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/module/language/wisp.scm b/module/language/wisp.scm index f3127c9d3..3ac128df2 100644 =2D-- a/module/language/wisp.scm +++ b/module/language/wisp.scm @@ -97,30 +97,22 @@ ;; TODO: wrap the reader to return the repr of the syntax reader ;; additions =20 =2D(define (match-charlist-to-repr charlist) =2D (let =2D ((chlist (reverse charlist))) +(define (equal-rest? chars . args) + (equal? chars args)) + +(define (match-charlist-to-repr char-list) + (let ((chars (reverse char-list))) (cond =2D ((equal? chlist (list #\.)) =2D repr-dot) =2D ((equal? chlist (list #\')) =2D repr-quote) =2D ((equal? chlist (list #\,)) =2D repr-unquote) =2D ((equal? chlist (list #\`)) =2D repr-quasiquote) =2D ((equal? chlist (list #\, #\@)) =2D repr-unquote-splicing) =2D ((equal? chlist (list #\# #\')) =2D repr-syntax) =2D ((equal? chlist (list #\# #\,)) =2D repr-unsyntax) =2D ((equal? chlist (list #\# #\`)) =2D repr-quasisyntax) =2D ((equal? chlist (list #\# #\, #\@)) =2D repr-unsyntax-splicing) =2D (else =2D #f)))) + ((equal-rest? chars #\.) repr-dot) + ((equal-rest? chars #\') repr-quote) + ((equal-rest? chars #\,) repr-unquote) + ((equal-rest? chars #\`) repr-quasiquote) + ((equal-rest? chars #\, #\@) repr-unquote-splicing) + ((equal-rest? chars #\# #\') repr-syntax) + ((equal-rest? chars #\# #\,) repr-unsyntax) + ((equal-rest? chars #\# #\`) repr-quasisyntax) + ((equal-rest? chars #\# #\, #\@) repr-unsyntax-splicing) + (else #f)))) =20 (define (wisp-read port) "wrap read to catch list prefixes." =2D-=20 2.41.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0016-SRFI-119-Wisp-improve-docstring.patch Content-Transfer-Encoding: quoted-printable From=20a74e63f65e6f02c9aeff76bf1d6a93043fa95c45 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Fri, 18 Aug 2023 19:10:07 +0200 Subject: [PATCH 16/21] SRFI-119 (Wisp): improve docstring * module/language/wisp.scm (wisp-read): improve docstring =2D-- module/language/wisp.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/language/wisp.scm b/module/language/wisp.scm index 3ac128df2..96429218d 100644 =2D-- a/module/language/wisp.scm +++ b/module/language/wisp.scm @@ -115,7 +115,7 @@ (else #f)))) =20 (define (wisp-read port) =2D "wrap read to catch list prefixes." + "Wrap read to catch list prefixes: read one or several chars from PORT a= nd return read symbols or replacement-symbols as representation for special= forms." (let ((prefix-maxlen 4)) (let longpeek ((peeked '()) =2D-=20 2.41.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0017-SRFI-119-Wisp-improve-let-and-let-formatting.patch Content-Transfer-Encoding: quoted-printable From=20361c00fc77a3cd8621be47a37fca18265ae59310 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Fri, 18 Aug 2023 19:14:07 +0200 Subject: [PATCH 17/21] SRFI-119 (Wisp): improve let and let* formatting * module/language/wisp.scm (wisp-read, wisp-scheme-read-chunk-lines): clean up let and let* arguments =2D-- module/language/wisp.scm | 133 +++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 69 deletions(-) diff --git a/module/language/wisp.scm b/module/language/wisp.scm index 96429218d..3b14eba54 100644 =2D-- a/module/language/wisp.scm +++ b/module/language/wisp.scm @@ -117,15 +117,15 @@ (define (wisp-read port) "Wrap read to catch list prefixes: read one or several chars from PORT a= nd return read symbols or replacement-symbols as representation for special= forms." (let ((prefix-maxlen 4)) =2D (let longpeek =2D ((peeked '()) =2D (repr-symbol #f)) + (let longpeek ((peeked '()) (repr-symbol #f)) (cond =2D ((or (< prefix-maxlen (length peeked)) (eof-object? (peek-char po= rt)) (equal? #\space (peek-char port)) (equal? #\newline (peek-char port))) + ((or (< prefix-maxlen (length peeked)) + (eof-object? (peek-char port)) + (equal? #\space (peek-char port)) + (equal? #\newline (peek-char port))) (if repr-symbol ; found a special symbol, return it. repr-symbol =2D (let unpeek =2D ((remaining peeked)) + (let unpeek ((remaining peeked)) (cond ((equal? '() remaining) (read port)); let read to the work @@ -133,9 +133,8 @@ (unread-char (car remaining) port) (unpeek (cdr remaining))))))) (else =2D (let* =2D ((next-char (read-char port)) =2D (peeked (cons next-char peeked))) + (let* ((next-char (read-char port)) + (peeked (cons next-char peeked))) (longpeek peeked (match-charlist-to-repr peeked)))))))) @@ -172,9 +171,8 @@ =20 (define (indent-level-reduction indentation-levels level select-fun) "Reduce the INDENTATION-LEVELS to the given LEVEL and return the value s= elected by SELECT-FUN" =2D (let loop =2D ((newlevels indentation-levels) =2D (diff 0)) + (let loop ((newlevels indentation-levels) + (diff 0)) (cond ((=3D level (car newlevels)) (select-fun (list diff indentation-levels))) @@ -230,7 +228,14 @@ (set-source-property! line 'filename (port-filename port)) (set-source-property! line 'line (port-line port)) (append indent-and-symbols (list line)))) =2D ((and in-indent? (zero? currentindent) (not in-comment?) (not (= null? indent-and-symbols)) (not in-underscoreindent?) (not (or (equal? #\sp= ace next-char) (equal? #\newline next-char) (equal? (string-ref ";" 0) next= -char)))) + ((and in-indent? + (zero? currentindent) + (not in-comment?) + (not (null? indent-and-symbols)) + (not in-underscoreindent?) + (not (or (equal? #\space next-char) + (equal? #\newline next-char) + (equal? (string-ref ";" 0) next-char)))) (append indent-and-symbols)); top-level form ends chunk ((chunk-ends-with-period currentsymbols next-char) ;; the line ends with a period. This is forbidden in @@ -259,9 +264,10 @@ emptylines)) ;; any char but whitespace *after* underscoreindent is ;; an error. This is stricter than the current wisp =2D ;; syntax definition. TODO: Fix the definition. Better =2D ;; start too strict. FIXME: breaks on lines with only =2D ;; underscores which should be empty lines. + ;; syntax definition. + ;; TODO: Fix the definition. Better start too strict. + ;; FIXME: breaks on lines with only underscores which should be + ;; empty lines. ((and in-underscoreindent? (and (not (equal? #\space next-char)) = (not (equal? #\newline next-char)))) (raise-exception (make-exception-from-throw 'wisp-syntax-error (= list "initial underscores without following whitespace at beginning of the = line after" (last indent-and-symbols))))) ((equal? #\newline next-char) @@ -351,9 +357,8 @@ (define (line-code-replace-inline-colons line) "Replace inline colons by opening parens which close at the end of the l= ine" ;; format #t "replace inline colons for line ~A\n" line =2D (let loop =2D ((processed '()) =2D (unprocessed line)) + (let loop ((processed '()) + (unprocessed line)) (cond ((null? unprocessed) ;; format #t "inline-colons processed line: ~A\n" processed @@ -417,9 +422,8 @@ =20 (define (wisp-propagate-source-properties code) "Propagate the source properties from the sourrounding list into every p= art of the code." =2D (let loop =2D ((processed '()) =2D (unprocessed code)) + (let loop ((processed '()) + (unprocessed code)) (cond ((and (null? processed) (not (pair? unprocessed)) (not (list? unproce= ssed))) unprocessed) @@ -460,22 +464,20 @@ (list (format #f "The first symbol in a chunk must start at zero inde= ntation. Indentation and line: ~A" (car lines))))))) =2D (let loop =2D ((processed '()) =2D (unprocessed lines) =2D (indentation-levels '(0))) =2D (let* =2D ((current-line =2D (if (<=3D 1 (length unprocessed)) =2D (car unprocessed) =2D (make-line 0))); empty code =2D (next-line =2D (if (<=3D 2 (length unprocessed)) =2D (car (cdr unprocessed)) =2D (make-line 0))); empty code =2D (current-indentation =2D (car indentation-levels)) =2D (current-line-indentation (line-real-indent current-line))) + (let loop ((processed '()) + (unprocessed lines) + (indentation-levels '(0))) + (let* ((current-line + (if (<=3D 1 (length unprocessed)) + (car unprocessed) + (make-line 0))); empty code + (next-line + (if (<=3D 2 (length unprocessed)) + (car (cdr unprocessed)) + (make-line 0))); empty code + (current-indentation + (car indentation-levels)) + (current-line-indentation (line-real-indent current-line))) ;; format #t "processed: ~A\ncurrent-line: ~A\nnext-line: ~A\nunproc= essed: ~A\nindentation-levels: ~A\ncurrent-indentation: ~A\n\n" ;; . processed current-line next-line unprocessed indentation-le= vels current-indentation (cond @@ -528,9 +530,8 @@ current-line-indentation (cdr indentation-levels))))))) ((=3D current-indentation current-line-indentation) =2D (let =2D ((line (line-finalize current-line)) =2D (next-line-indentation (line-real-indent next-line))) + (let ((line (line-finalize current-line)) + (next-line-indentation (line-real-indent next-line))) (cond ((>=3D current-line-indentation next-line-indentation) ;; simple recursiive step to the next line @@ -571,9 +572,8 @@ =20 (define (wisp-scheme-replace-inline-colons lines) "Replace inline colons by opening parens which close at the end of the l= ine" =2D (let loop =2D ((processed '()) =2D (unprocessed lines)) + (let loop ((processed '()) + (unprocessed lines)) (if (null? unprocessed) processed (loop @@ -583,9 +583,8 @@ =20 (define (wisp-scheme-strip-indentation-markers lines) "Strip the indentation markers from the beginning of the lines" =2D (let loop =2D ((processed '()) =2D (unprocessed lines)) + (let loop ((processed '()) + (unprocessed lines)) (if (null? unprocessed) processed (loop @@ -684,21 +683,20 @@ Match is awesome!" (wisp-add-source-properties-from/when-required code form)) (wisp-add-source-properties-from/when-required code =2D (let =2D ((improper =2D (match code =2D ((a ... b 'REPR-DOT-e749c73d-c826-47e2-a798-c16c13cb89dd c) =2D (set! is-proper? #f) =2D (wisp-add-source-properties-from/when-required =2D code =2D (append (map wisp-make-improper (map add-prop/req a)) =2D (cons (wisp-make-improper (add-prop/req b)) =2D (wisp-make-improper (add-prop/req c)))))) =2D ((a ...) =2D (add-prop/req =2D (map wisp-make-improper (map add-prop/req a)))) =2D (a =2D a)))) + (let ((improper + (match code + ((a ... b 'REPR-DOT-e749c73d-c826-47e2-a798-c16c13cb89dd c) + (set! is-proper? #f) + (wisp-add-source-properties-from/when-required + code + (append (map wisp-make-improper (map add-prop/req a)) + (cons (wisp-make-improper (add-prop/req b)) + (wisp-make-improper (add-prop/req c)))))) + ((a ...) + (add-prop/req + (map wisp-make-improper (map add-prop/req a)))) + (a + a)))) (define (syntax-error li msg) (raise-exception (make-exception-from-throw @@ -706,8 +704,7 @@ Match is awesome!" (list (format #f "incorrect dot-syntax #{.}# in code: ~A: ~A" msg= li))))) (if is-proper? improper =2D (let check =2D ((tocheck improper)) + (let check ((tocheck improper)) (match tocheck ;; lists with only one member (('REPR-DOT-e749c73d-c826-47e2-a798-c16c13cb89dd) @@ -725,9 +722,8 @@ Match is awesome!" (syntax-error tocheck "dot as last element in already improp= er pair")) ;; more complex pairs ((? pair? a) =2D (let =2D ((head (drop-right a 1)) =2D (tail (last-pair a))) + (let ((head (drop-right a 1)) + (tail (last-pair a))) (cond ((equal? repr-dot (car tail)) (syntax-error tocheck "equal? repr-dot : car tail")) @@ -754,8 +750,7 @@ Match is awesome!" =20 (define (wisp-scheme-read-all port) "Read all chunks from the given port" =2D (let loop =2D ((tokens '())) + (let loop ((tokens '())) (cond ((eof-object? (peek-char port)) tokens) =2D-=20 2.41.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0018-SRFI-119-Wisp-Fix-comment-syntax-and-trailing-whites.patch Content-Transfer-Encoding: quoted-printable From=200ca2a934c96d657c996d8b2f0241cc7e38ae2a0e Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Fri, 18 Aug 2023 19:15:20 +0200 Subject: [PATCH 18/21] SRFI-119 (Wisp): Fix comment syntax and trailing whitespace * module/language/wisp/spec.scm (define-language): comment with ;;, strip trailing lines =2D-- module/language/wisp/spec.scm | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/module/language/wisp/spec.scm b/module/language/wisp/spec.scm index 5f8feca9a..f7fd794e0 100644 =2D-- a/module/language/wisp/spec.scm +++ b/module/language/wisp/spec.scm @@ -52,7 +52,7 @@ =20 (define-language wisp #:title "Wisp Scheme Syntax. See SRFI-119 for details" =2D ; . #:reader read-one-wisp-sexp + ;; . #:reader read-one-wisp-sexp #:reader read-one-wisp-sexp ; : lambda (port env) : let ((x (read-one-wi= sp-sexp port env))) (display x)(newline) x ; #:compilers `((tree-il . ,compile-tree-il)) #:decompilers `((tree-il . ,decompile-tree-il)) @@ -68,6 +68,3 @@ ;; limited to the current compilation unit. (module-define! m 'current-reader (make-fluid)) m))) =2D =2D =2D =2D-=20 2.41.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0019-SRFI-119-Wisp-reindent-test.patch Content-Transfer-Encoding: quoted-printable From=207de03c8ce421e809afb95823037d655aa9a47fd2 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Fri, 18 Aug 2023 19:17:25 +0200 Subject: [PATCH 19/21] SRFI-119 (Wisp): reindent test * test-suite/tests/srfi-119.test (with-read-options, wisp->list): M-x inden= t-region =2D-- test-suite/tests/srfi-119.test | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test-suite/tests/srfi-119.test b/test-suite/tests/srfi-119.test index f4a19a0a7..6fe87f2b2 100644 =2D-- a/test-suite/tests/srfi-119.test +++ b/test-suite/tests/srfi-119.test @@ -27,14 +27,14 @@ (define (with-read-options opts thunk) (let ((saved-options (read-options))) (dynamic-wind =2D (lambda () =2D (read-options opts)) =2D thunk =2D (lambda () =2D (read-options saved-options))))) + (lambda () + (read-options opts)) + thunk + (lambda () + (read-options saved-options))))) =20 (define (wisp->list str) =2D (wisp-scheme-read-string str)) + (wisp-scheme-read-string str)) =20 (with-test-prefix "wisp-read-simple" (pass-if (equal? (wisp->list "<=3D n 5") '((<=3D n 5)))) =2D-=20 2.41.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0020-SRFI-119-Wisp-use-pass-if-equal-instead-of-pass-if-e.patch Content-Transfer-Encoding: quoted-printable From=208cd856e060840277b1a8b30892d6ef4f55fe5c7a Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Fri, 18 Aug 2023 19:19:40 +0200 Subject: [PATCH 20/21] SRFI-119 (Wisp): use pass-if-equal instead of pass-if (equal? ...) * test-suite/tests/srfi-119.test (wisp-read-simple, wisp-read-complex): use pass-if-equal and invert conditions to improve error messages =2D-- test-suite/tests/srfi-119.test | 54 ++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/test-suite/tests/srfi-119.test b/test-suite/tests/srfi-119.test index 6fe87f2b2..64ccc2ff6 100644 =2D-- a/test-suite/tests/srfi-119.test +++ b/test-suite/tests/srfi-119.test @@ -37,11 +37,21 @@ (wisp-scheme-read-string str)) =20 (with-test-prefix "wisp-read-simple" =2D (pass-if (equal? (wisp->list "<=3D n 5") '((<=3D n 5)))) =2D (pass-if (equal? (wisp->list ". 5") '(5))) =2D (pass-if (equal? (wisp->list "+ 1 : * 2 3") '((+ 1 (* 2 3)))))) + (pass-if-equal '((<=3D n 5)) + (wisp->list "<=3D n 5")) + (pass-if-equal '(5) + (wisp->list ". 5")) + (pass-if-equal '((+ 1 (* 2 3))) + (wisp->list "+ 1 : * 2 3"))) (with-test-prefix "wisp-read-complex" =2D (pass-if (equal? (wisp->list " + (pass-if-equal '( + (a b c d e + f g h + i j k) + + (concat "I want " + (getwish from me) + " - " username)) (wisp->list " a b c d e . f g h . i j k @@ -49,16 +59,20 @@ a b c d e concat \"I want \" getwish from me . \" - \" username =2D") '( =2D(a b c d e =2D f g h =2D i j k) +")) + + (pass-if-equal + '( + (define (a b c) + (d e + (f) + (g h) + i)) =20 =2D(concat "I want " =2D (getwish from me) =2D " - " username)))) + (define (_) + (display "hello\n")) =20 =2D (pass-if (equal? (wisp->list " + (_)) (wisp->list " define : a b c _ d e ___ f @@ -68,21 +82,11 @@ __ . i define : _ _ display \"hello\n\" =20 =2D\\_") '( =2D(define (a b c) =2D (d e =2D (f) =2D (g h) =2D i)) =2D =2D(define (_) =2D (display "hello\n")) =2D =2D(_)))) +\\_")) =20 ;; nesting with pairs =2D (pass-if (equal? (wisp->list "1 . 2\n3 4\n 5 . 6") =2D '((1 . 2)(3 4 (5 . 6)))))) + (pass-if-equal '((1 . 2)(3 4 (5 . 6))) + (wisp->list "1 . 2\n3 4\n 5 . 6"))) =20 (with-test-prefix "wisp-source-properties" (pass-if (not (find null? (map source-properties (wisp->list "1 . 2\n3 4= \n 5 . 6"))))) =2D-=20 2.41.0 --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0021-SRFI-119-Wisp-add-tests-for-equality-of-source-prope.patch Content-Transfer-Encoding: quoted-printable From=20e120fc39aca45d55ede90b4200b7b9e39bc83e1e Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Fri, 18 Aug 2023 19:25:59 +0200 Subject: [PATCH 21/21] SRFI-119 (Wisp): add tests for equality of source-properties and fix them * test-suite/tests/srfi-119.test (scheme->list): new procedure * test-suite/tests/srfi-119.test (wisp-source-properties): use pass-if (every pair? ...) for the existance test. Use scheme->list to compare source-properties from regular Scheme read and wisp read. * module/language/wisp.scm (line-code): replace custom logic with wisp-add-source-properties-from/when-required * module/language/wisp.scm (wisp-scheme-read-chunk-lines): set the line-number from the start of the chunk as source-property instead of the line number from the end of the chunk. =2D-- module/language/wisp.scm | 57 ++++++++++++++++++---------------- test-suite/tests/srfi-119.test | 19 ++++++++++-- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/module/language/wisp.scm b/module/language/wisp.scm index 3b14eba54..dae9642ae 100644 =2D-- a/module/language/wisp.scm +++ b/module/language/wisp.scm @@ -45,6 +45,24 @@ (read-enable 'curly-infix)) =20 =20 +;; Helpers to preserver source properties + +(define (wisp-add-source-properties-from source target) + "Copy the source properties from source into the target and return the t= arget." + (catch #t + (lambda () + (set-source-properties! target (source-properties source))) + (lambda (key . arguments) + #f)) + target) + +(define (wisp-add-source-properties-from/when-required source target) + "Copy the source properties if target has none." + (if (null? (source-properties target)) + (wisp-add-source-properties-from source target) + target)) + + ;; Helper functions for the indent-and-symbols data structure: '((indent t= oken token ...) ...) (define make-line list) =20 @@ -63,7 +81,7 @@ (let ((code (cdr line))) ;; propagate source properties (when (not (null? code)) =2D (set-source-properties! code (source-properties line))) + (wisp-add-source-properties-from/when-required line code)) code)) =20 ;; literal values I need @@ -204,14 +222,16 @@ =20 =20 (define (wisp-scheme-read-chunk-lines port) =2D (let loop =2D ((indent-and-symbols (list)); '((5 "(foobar)" "\"yobble\"")(3 "#t"= )) =2D (in-indent? #t) =2D (in-underscoreindent? (equal? #\_ (peek-char port))) =2D (in-comment? #f) =2D (currentindent 0) =2D (currentsymbols '()) =2D (emptylines 0)) + ;; the line number for this chunk is the line number when starting to re= ad it + ;; a top-level form stops processing, so we only need to retrieve this h= ere. + (define line-number (port-line port)) + (let loop ((indent-and-symbols (list)); '((5 "(foobar)" "\"yobble\"")(3 = "#t")) + (in-indent? #t) + (in-underscoreindent? (equal? #\_ (peek-char port))) + (in-comment? #f) + (currentindent 0) + (currentsymbols '()) + (emptylines 0)) (cond ((>=3D emptylines 2) ;; the chunk end has to be checked @@ -226,7 +246,7 @@ ((eof-object? next-char) (let ((line (apply make-line currentindent currentsymbols))) (set-source-property! line 'filename (port-filename port)) =2D (set-source-property! line 'line (port-line port)) + (set-source-property! line 'line line-number) (append indent-and-symbols (list line)))) ((and in-indent? (zero? currentindent) @@ -296,7 +316,7 @@ (when (not (=3D 0 (length (line-code parsedline)))) ;; set the source properties to parsedline so we can try to = add them later. (set-source-property! parsedline 'filename (port-filename po= rt)) =2D (set-source-property! parsedline 'line (port-line port))) + (set-source-property! parsedline 'line line-number)) ;; TODO: If the line is empty. Either do it here and do not ad= d it, just ;; increment the empty line counter, or strip it later. Replac= e indent ;; -1 by indent 0 afterwards. @@ -405,21 +425,6 @@ #f))) l)) =20 =2D(define (wisp-add-source-properties-from source target) =2D "Copy the source properties from source into the target and return the= target." =2D (catch #t =2D (lambda () =2D (set-source-properties! target (source-properties source))) =2D (lambda (key . arguments) =2D #f)) =2D target) =2D =2D(define (wisp-add-source-properties-from/when-required source target) =2D "Copy the source properties if target has none." =2D (if (null? (source-properties target)) =2D (wisp-add-source-properties-from source target) =2D target)) =2D (define (wisp-propagate-source-properties code) "Propagate the source properties from the sourrounding list into every p= art of the code." (let loop ((processed '()) diff --git a/test-suite/tests/srfi-119.test b/test-suite/tests/srfi-119.test index 64ccc2ff6..60e1e0377 100644 =2D-- a/test-suite/tests/srfi-119.test +++ b/test-suite/tests/srfi-119.test @@ -19,6 +19,7 @@ (define-module (test-srfi-119) #:use-module (test-suite lib) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) ;; cut #:use-module (language wisp)) =20 (define (read-string s) @@ -36,6 +37,14 @@ (define (wisp->list str) (wisp-scheme-read-string str)) =20 +(define (scheme->list str) + (with-input-from-string str + (=CE=BB () + (let loop ((result '())) + (if (eof-object? (peek-char)) + (reverse! result) + (loop (cons (read) result))))))) + (with-test-prefix "wisp-read-simple" (pass-if-equal '((<=3D n 5)) (wisp->list "<=3D n 5")) @@ -89,5 +98,11 @@ _ display \"hello\n\" (wisp->list "1 . 2\n3 4\n 5 . 6"))) =20 (with-test-prefix "wisp-source-properties" =2D (pass-if (not (find null? (map source-properties (wisp->list "1 . 2\n3= 4\n 5 . 6"))))) =2D (pass-if (not (find null? (map source-properties (wisp->list "1 2\n3 4= \n 5 6")))))) + ;; has properties + (pass-if (every pair? (map source-properties (wisp->list "1 . 2\n3 4\n = 5 . 6")))) + (pass-if (every pair? (map source-properties (wisp->list "1 2\n3 4\n 5= 6")))) + ;; has the same properties + (pass-if-equal + (map source-properties (scheme->list "(1 . 2)\n(3 4\n (5 . 6))\n(1= 4)\n\n(7 8)")) + (map (cut cons '(filename . #f) <>) + (map source-properties (wisp->list "1 . 2\n3 4\n 5 . 6\n1 4\n= \n7 8"))))) =2D-=20 2.41.0 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Best wishes, Arne =2D-=20 Unpolitisch sein hei=C3=9Ft politisch sein, ohne es zu merken. draketo.de --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJEBAEBCAAuFiEE801qEjXQSQPNItXAE++NRSQDw+sFAmTfr+gQHGFybmVfYmFi QHdlYi5kZQAKCRAT741FJAPD66LjD/wOvbTG6GPU/id3eOZSVNN0yOZY5FzVJKVI dFXN5Iq/LtKhY0DYpC05h7OJYJmqAIiHvyrjP76gQ2gUKnlZE9SuPNmPOiyTz+C4 bIywFHsgmGDPVK3dJO0EVRLa8q3ZJ66IwMcABMS00h/gCr27b5I/0Ku8dyrwXvLn 1kQuXsu9YJyO3x8olyrvPS6+bAybUDXV/J/NTTWGh7+l88dmP8oyXgfX0Cg0wcpU jplXdEIpyT9gfufTJqar+3nwIiRBMqK/2nMHp3oUVkD3jqcX7VD3/H1RFLwdk3l1 V/5rwcNwXqdl59NRX6T1501kG248JIYVsjyVhulUXYNKTBjUNffb05IHifZmBHeG Prd9c/dCc57FrR2u4z2PSwn3fEWGhmA/EiI44JMrPGLuUd89aeLgKONsYZ9dhkty gzJSbw+OW8UDNn1XyLMSj6BXWMM0siED//lpS9WLOhym3ozz5hgTDVzfQigVXgcI xcy6XHzctJtIC7E2icp2jkZu4P4vgWmGUvDuUdihJfyAja0D3E2gWxr2fj0RRJP2 I28L6jg4s+KfXdfHXZhbiinObvFNhs5Py4xND0FU2Bkfuwf75WAwVo3pGPRscH8B +JwjUktC1gR9Sb46rrdV6R7O4hn4DcIKEV64dH6d9J2gL//qLtJwidz7rA6cnKO/ V7l9vpbWOYjEBAEBCAAuFiEE3Si95tmHXKvOSosd3M8NswvBBUgFAmTfr+gQHGFy bmVfYmFiQHdlYi5kZQAKCRDczw2zC8EFSLMxA/49ProkGLjS4Zupm2g0zr9FO6Na 26AGNdKtEYomtGRqjfji3dXMOqsL/PKYpqp6cVTASBYFlIrss/6nZvoiEbSbvVXu 6JrArcHmupJx0qnxWuHA1Kn7jcG00i7FpmuaEFI8jmdM/t1Sr8WpRwMCKLB/04Ke MmrdJHXTfcAlDplP3w== =AWVR -----END PGP SIGNATURE----- --==-=-=--