(Arne Babenhauserheide)
2015-09-12: end chunks on trailing period. end chunks on trailing period.
diff --git a/wisp-scheme.w b/wisp-scheme.w --- a/wisp-scheme.w +++ b/wisp-scheme.w @@ -222,16 +222,34 @@ define : indent-reduce-to-level indentat lambda : x ; get the levels car : cdr x +define : chunk-ends-with-period currentsymbols port + . "Check whether indent-and-symbols ends with a period, indicating the end of a chunk." + define : ref-last li + list-ref li : - (length li) 1 + define : drop-last li + drop-right li 1 + and : not : null? currentsymbols + equal? #\newline : peek-char port + equal? repr-dot + ref-last currentsymbols + +define : indent-and-lines-drop-last-symbol indent-and-symbols + . "Check whether indent-and-symbols ends with a period, indicating the end of a chunk." + define : drop-last li + drop-right li 1 + define : ref-last li + list-ref li : - (length li) 1 + define : set-last! li val + list-set! li : - (length li) 1 + . val + when : not : null? indent-and-symbols + set-last! indent-and-symbols + drop-last : ref-last indent-and-symbols + . indent-and-symbols define : wisp-scheme-read-chunk-lines port - define : ends-with-period indent-and-symbols - . "Check whether indent-and-symbols ends with a period, indicating the end of a chunk." - equal? repr-dot - take-right - take-right - take-right indent-and-symbols 1 - . 1 - . 1 + define : finalize indent-and-symbols currentindent currentsymbols + append indent-and-symbols : list : append (list currentindent) currentsymbols let loop : indent-and-symbols : list ; '((5 "(foobar)" "\"yobble\"")(3 "#t")) inindent #t @@ -247,15 +265,16 @@ define : wisp-scheme-read-chunk-lines po ; after two empty lines work ; (otherwise it shows one more line). . indent-and-symbols - : and (equal? '() currentsymbols) : ends-with-period indent-and-symbols + : chunk-ends-with-period currentsymbols port ; the line ends with a period. This is forbidden in SRFI-119. ; use it to end the line in the REPL without hitting return thrice. - . indent-and-symbols + indent-and-lines-drop-last-symbol + finalize indent-and-symbols currentindent currentsymbols else let : : next-char : peek-char port cond : eof-object? next-char - append indent-and-symbols : list : append (list currentindent) currentsymbols + finalize indent-and-symbols 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 : and inindent : equal? #\space next-char