From 0755a9bcb5f359c39cc5e91ff33e03e8b897b93d Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Tue, 14 Feb 2023 09:41:24 +0100 Subject: [PATCH 2/3] Stylistic changes to language/wisp * module/language/wisp.scm: fix whitespace and remove commented-out code * module/language/wisp/spec.scm: remove unused variable Acked-by: Arne Babenhauserheide --- module/language/wisp.scm | 101 ++++++++++++++-------------------- module/language/wisp/spec.scm | 2 - 2 files changed, 42 insertions(+), 61 deletions(-) diff --git a/module/language/wisp.scm b/module/language/wisp.scm index ba24f54c5..bec91e274 100644 --- a/module/language/wisp.scm +++ b/module/language/wisp.scm @@ -40,8 +40,8 @@ (use-modules (srfi srfi-1) - (srfi srfi-11 ); for let-values - (ice-9 rw ); for write-string/partial + (srfi srfi-11); for let-values + (ice-9 rw); for write-string/partial (ice-9 match)) @@ -106,15 +106,15 @@ repr-unquote) ((equal? chlist (list #\`)) repr-quasiquote) - ((equal? chlist (list #\, #\@ )) + ((equal? chlist (list #\, #\@)) repr-unquote-splicing) - ((equal? chlist (list #\# #\' )) + ((equal? chlist (list #\# #\')) repr-syntax) - ((equal? chlist (list #\# #\, )) + ((equal? chlist (list #\# #\,)) repr-unsyntax) - ((equal? chlist (list #\# #\` )) + ((equal? chlist (list #\# #\`)) repr-quasisyntax) - ((equal? chlist (list #\# #\, #\@ )) + ((equal? chlist (list #\# #\, #\@)) repr-unsyntax-splicing) (else #f)))) @@ -124,33 +124,23 @@ (let ((prefix-maxlen 4)) (let longpeek ((peeked '()) - (repr-symbol #f)) + (repr-symbol #f)) (cond - ((or (< prefix-maxlen (length peeked)) (eof-object? (peek-char port)) (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. - ; TODO: Somehow store source-properties. The commented-out code below does not work. - ; catch #t - ; lambda () - ; write : source-properties symbol-or-symbols - ; set-source-property! symbol-or-symbols 'filename : port-filename port - ; set-source-property! symbol-or-symbols 'line : 1+ : port-line port - ; set-source-property! symbol-or-symbols 'column : port-column port - ; write : source-properties symbol-or-symbols - ; lambda : key . arguments - ; . #f repr-symbol (let unpeek ((remaining peeked)) (cond - ((equal? '() remaining ) - (read port )); let read to the work + ((equal? '() remaining) + (read port)); let read to the work (else (unread-char (car remaining) port) (unpeek (cdr remaining))))))) (else (let* ((next-char (read-char port)) - (peeked (cons next-char peeked))) + (peeked (cons next-char peeked))) (longpeek peeked (match-charlist-to-repr peeked)))))))) @@ -174,7 +164,7 @@ (= 0 (line-indent line)) (line-empty-code? line))) -(define (line-strip-continuation line ) +(define (line-strip-continuation line) (if (line-continues? line) (append (list @@ -204,13 +194,13 @@ (define (indent-level-difference indentation-levels level) "Find how many indentation levels need to be popped off to find the given level." (indent-level-reduction indentation-levels level - (lambda (x ); get the count + (lambda (x); get the count (car x)))) (define (indent-reduce-to-level indentation-levels level) "Find how many indentation levels need to be popped off to find the given level." (indent-level-reduction indentation-levels level - (lambda (x ); get the levels + (lambda (x); get the levels (car (cdr x))))) (define (chunk-ends-with-period currentsymbols next-char) @@ -222,7 +212,7 @@ (define (wisp-scheme-read-chunk-lines port) (let loop - ((indent-and-symbols (list )); '((5 "(foobar)" "\"yobble\"")(3 "#t")) + ((indent-and-symbols (list)); '((5 "(foobar)" "\"yobble\"")(3 "#t")) (inindent #t) (inunderscoreindent (equal? #\_ (peek-char port))) (incomment #f) @@ -230,7 +220,7 @@ (currentsymbols '()) (emptylines 0)) (cond - ((>= emptylines 2 ); the chunk end has to be checked + ((>= emptylines 2); the chunk end has to be checked ; before we look for new chars in the ; port to make execution in the REPL ; after two empty lines work @@ -242,14 +232,14 @@ ((eof-object? next-char) (append indent-and-symbols (list (append (list currentindent) currentsymbols)))) ((and inindent (zero? currentindent) (not incomment) (not (null? indent-and-symbols)) (not inunderscoreindent) (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 + (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 ; SRFI-119. Use it to end the line in the REPL without ; showing continuation dots (...). (append indent-and-symbols (list (append (list currentindent) (drop-right currentsymbols 1))))) ((and inindent (equal? #\space next-char)) - (read-char port ); remove char + (read-char port); remove char (loop indent-and-symbols #t ; inindent @@ -259,7 +249,7 @@ currentsymbols emptylines)) ((and inunderscoreindent (equal? #\_ next-char)) - (read-char port ); remove char + (read-char port); remove char (loop indent-and-symbols #t ; inindent @@ -276,7 +266,7 @@ ((and inunderscoreindent (and (not (equal? #\space next-char)) (not (equal? #\newline next-char)))) (throw 'wisp-syntax-error "initial underscores without following whitespace at beginning of the line after" (last indent-and-symbols))) ((equal? #\newline next-char) - (read-char port ); remove the newline + (read-char port); remove the newline ; The following two lines would break the REPL by requiring one char too many. ; if : and (equal? #\newline next-char) : equal? #\return : peek-char port ; read-char port ; remove a full \n\r. Damn special cases... @@ -285,14 +275,13 @@ ; indent. Lines with a comment at zero indent ; get indent -1 for the same reason - meaning ; not actually empty. - ( - (indent + ((indent (cond (incomment - (if (= 0 currentindent ); specialcase + (if (= 0 currentindent); specialcase -1 - currentindent )) - ((not (null? currentsymbols )); pure whitespace + currentindent)) + ((not (null? currentsymbols)); pure whitespace currentindent) (else 0))) @@ -313,13 +302,13 @@ #t ; inindent (if (<= 2 emptylines) #f ; chunk ends here - (equal? #\_ (peek-char port ))); are we in underscore indent? + (equal? #\_ (peek-char port))); are we in underscore indent? #f ; incomment 0 '() emptylines))) ((equal? #t incomment) - (read-char port ); remove one comment character + (read-char port); remove one comment character (loop indent-and-symbols #f ; inindent @@ -328,8 +317,8 @@ currentindent currentsymbols emptylines)) - ((or (equal? #\space next-char) (equal? #\tab next-char) (equal? #\return next-char) ); remove whitespace when not in indent - (read-char port ); remove char + ((or (equal? #\space next-char) (equal? #\tab next-char) (equal? #\return next-char)); remove whitespace when not in indent + (read-char port); remove char (loop indent-and-symbols #f ; inindent @@ -406,10 +395,7 @@ (define (line-finalize line) "Process all wisp-specific information in a line and strip it" - (let - ( - (l - (line-code-replace-inline-colons + (let ((l (line-code-replace-inline-colons (line-strip-indentation-marker (line-strip-lone-colon (line-strip-continuation line)))))) @@ -459,7 +445,7 @@ (and (not (null? lines)) (not (line-empty-code? (car lines))) - (not (= 0 (line-real-indent (car lines ))))); -1 is a line with a comment + (not (= 0 (line-real-indent (car lines))))); -1 is a line with a comment (if (= 1 (line-real-indent (car lines))) ;; accept a single space as indentation of the first line (and ignore the indentation) to support meta commands (set! lines @@ -474,15 +460,14 @@ (unprocessed lines) (indentation-levels '(0))) (let* - ( - (current-line + ((current-line (if (<= 1 (length unprocessed)) (car unprocessed) - (list 0 ))); empty code + (list 0))); empty code (next-line (if (<= 2 (length unprocessed)) (car (cdr unprocessed)) - (list 0 ))); empty code + (list 0))); empty code (current-indentation (car indentation-levels)) (current-line-indentation (line-real-indent current-line))) @@ -517,7 +502,7 @@ processed (cdr unprocessed) indentation-levels)) - ((and (line-empty-code? next-line) (<= 2 (length unprocessed ))) + ((and (line-empty-code? next-line) (<= 2 (length unprocessed))) ; display "next-line empty\n" ; TODO: Somehow preserve the line-numbers. ; take out the next-line from unprocessed. @@ -555,18 +540,17 @@ (if (line-continues? current-line) line (wisp-add-source-properties-from line (list line)))) - (cdr unprocessed ); recursion here + (cdr unprocessed); recursion here indentation-levels)) ((< current-line-indentation next-line-indentation) ; display "current-line-indent < next-line-indent\n" ; format #t "line: ~A\n" line ; side-recursion via a sublist (let-values - ( - ((sub-processed sub-unprocessed) + (((sub-processed sub-unprocessed) (loop line - (cdr unprocessed ); recursion here + (cdr unprocessed); recursion here indentation-levels))) ; format #t "side-recursion:\n sub-processed: ~A\n processed: ~A\n\n" sub-processed processed (loop @@ -660,7 +644,7 @@ (match code (('REPR-QUOTE-e749c73d-c826-47e2-a798-c16c13cb89dd a ...) (list 'quote (map wisp-replace-paren-quotation-repr a))) - ((a ... 'REPR-QUOTE-e749c73d-c826-47e2-a798-c16c13cb89dd b ); this is the quoted empty list + ((a ... 'REPR-QUOTE-e749c73d-c826-47e2-a798-c16c13cb89dd b); this is the quoted empty list (append (map wisp-replace-paren-quotation-repr a) (list (list 'quote (map wisp-replace-paren-quotation-repr b))))) @@ -668,13 +652,13 @@ (list 'quasiquote (list 'unquote (map wisp-replace-paren-quotation-repr a)))) (('REPR-UNQUOTE-e749c73d-c826-47e2-a798-c16c13cb89dd a ...) (list 'unquote (map wisp-replace-paren-quotation-repr a))) - ((a ... 'REPR-UNQUOTE-e749c73d-c826-47e2-a798-c16c13cb89dd b ) + ((a ... 'REPR-UNQUOTE-e749c73d-c826-47e2-a798-c16c13cb89dd b) (append (map wisp-replace-paren-quotation-repr a) (list (list 'unquote (map wisp-replace-paren-quotation-repr b))))) (('REPR-QUASIQUOTE-e749c73d-c826-47e2-a798-c16c13cb89dd a ...) (list 'quasiquote (map wisp-replace-paren-quotation-repr a))) - ((a ... 'REPR-QUASIQUOTE-e749c73d-c826-47e2-a798-c16c13cb89dd b ); this is the quoted empty list + ((a ... 'REPR-QUASIQUOTE-e749c73d-c826-47e2-a798-c16c13cb89dd b); this is the quoted empty list (append (map wisp-replace-paren-quotation-repr a) (list (list 'quasiquote (map wisp-replace-paren-quotation-repr b))))) @@ -713,8 +697,7 @@ code to recreate the improper lists. Match is awesome!" (let - ( - (improper + ((improper (match code ((a ... b 'REPR-DOT-e749c73d-c826-47e2-a798-c16c13cb89dd c) (append (map wisp-make-improper a) diff --git a/module/language/wisp/spec.scm b/module/language/wisp/spec.scm index d5ea7abce..155292d9a 100644 --- a/module/language/wisp/spec.scm +++ b/module/language/wisp/spec.scm @@ -63,8 +63,6 @@ ;;; Language definition ;;; -(define wisp-pending-sexps (list)) - (define (read-one-wisp-sexp port env) ;; allow using "# foo" as #(foo). (read-hash-extend #\# (λ (chr port) #\#)) -- 2.39.1