Broken code

This commit is contained in:
Vivianne 2024-03-04 12:05:46 -05:00
parent e3c9ed9d8f
commit 4ac39aebd1

View file

@ -122,28 +122,33 @@
(else (values 'any #t))))
(define glyphs-reverse '())
(define grapheme-width 0)
(define %glyphs-reverse '())
(define %grapheme-width 0)
(define hit-eof #f)
(define (iterate-through-grapheme state)
(define glyph (get-char port))
(if
(eof-object? glyph)
(define glyph (peek-char port))
(if (eof-object? glyph)
(begin
(set! hit-eof #t)
state)
(begin
(set! glyphs-reverse (cons glyph glyphs-reverse))
(let* ((width property (char-width glyph))
(next-state boundary? (state-machine state property)))
(set! grapheme-width (+ grapheme-width width))
(pk width next-state)
(if boundary?
state
(iterate-through-grapheme state))))))
(let ((new-width (+ %grapheme-width width))
(new-glyphs-reverse (cons glyph %glyphs-reverse)))
;; Officially induct this char into the cluster
(get-char port)
(set! %grapheme-width new-width)
(set! %glyphs-reverse new-glyphs-reverse)
(iterate-through-grapheme state)))))))
(define final-state (iterate-through-grapheme 'any))
@ -152,8 +157,8 @@
stream-null
(stream-cons
(make-grapheme
grapheme-width
%grapheme-width
;; Delay to avoid construction of unnecessary lists and strings!
(delay (reverse-list->string glyphs-reverse))
(delay (reverse glyphs-reverse)))
(delay (reverse-list->string %glyphs-reverse))
(delay (reverse %glyphs-reverse)))
(input->grapheme-stream port))))