Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions TeXmacs/plugins/gnuplot/goldfish/tm-gnuplot.scm
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@
) ;let
) ;define

(define (gnuplot-read-code)
(define (read-code code)
(let ((line (read-line)))
(if (string=? line "<EOF>\n") code (read-code (string-append code line)))
) ;let
) ;define
;; 协议读取统一由 (texmacs protocol) 承担:兼容 R7RS read-line(不保留行尾
;; 换行),实现见 read-paragraph-by-visible-eof

(read-code "")
(define (gnuplot-read-code)
(read-paragraph-by-visible-eof)
) ;define

(define (gen-temp-path)
Expand Down
28 changes: 27 additions & 1 deletion TeXmacs/plugins/goldfish/goldfish/texmacs/protocol.scm
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,36 @@
(flush-any (string-append "latex:" msg))
) ;define

;; 行尾归一:R7RS 的 read-line 不保留行尾换行(goldfish >= 18.11.40 的
;; stdin 实现);18.11.39 及更早的 stdin 实现用 fgets,保留换行。插件
;; 协议以逐行拼接还原段落,故新语义下须补回换行。
(define (read-paragraph-line-with-eol line)
(let ((n (string-length line)))
(if
(and (> n 0) (char=? (string-ref line (- n 1)) #\newline))
line
(string-append line "\n")
) ;if
) ;let
) ;define

;; 段末标记:同时接受带/不带行尾换行(含 CRLF)的 "<EOF>"。旧 goldfish
;; 送来的行自带 "\n",新 goldfish 不带;两种都认,升级前后行为一致。
(define (read-paragraph-eof-marker? line)
(or (string=? line "<EOF>")
(string=? line "<EOF>\n")
(string=? line "<EOF>\r")
(string=? line "<EOF>\r\n")
) ;or
) ;define

(define (read-paragraph-by-visible-eof)
(define (read-code code)
(let ((line (read-line)))
(if (string=? line "<EOF>\n") code (read-code (string-append code line)))
(if (read-paragraph-eof-marker? line)
code
(read-code (string-append code (read-paragraph-line-with-eol line)))
) ;if
) ;let
) ;define

Expand Down
20 changes: 20 additions & 0 deletions TeXmacs/plugins/llm/progs/llm/tests/chat-protocol-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
(import (liii json))
(import (liii os))
(import (liii path))
(import (texmacs protocol))

(check-set-mode! 'report-failed)

Expand Down Expand Up @@ -467,6 +468,24 @@
) ;let*
) ;define

;;; ---------- read-paragraph-by-visible-eof:R7RS read-line 兼容 ----------

(define (test-read-paragraph-eof-marker)
;; 18.11.40:read-line 不带行尾换行,helper 需自行补回;
;; 18.11.39:行内已带换行,helper 原样拼接。两种语义期望结果相同。
(with-input-from-string "line1\nline2\n<EOF>\n"
(lambda () (check (read-paragraph-by-visible-eof) => "line1\nline2\n"))
) ;with-input-from-string
;; 空段落
(with-input-from-string "<EOF>\n"
(lambda () (check (read-paragraph-by-visible-eof) => ""))
) ;with-input-from-string
;; 空行也保留
(with-input-from-string "a\n\nb\n<EOF>\n"
(lambda () (check (read-paragraph-by-visible-eof) => "a\n\nb\n"))
) ;with-input-from-string
) ;define

;;; ---------- 测试套件入口 ----------

(tm-define (regtest-chat-protocol)
Expand All @@ -484,5 +503,6 @@
(test-fake-llm-attachment-injection)
(test-fake-llm-no-attachments)
(test-chat-wire-encoding)
(test-read-paragraph-eof-marker)
(check-report)
) ;tm-define
13 changes: 4 additions & 9 deletions TeXmacs/plugins/quiver/goldfish/tm-quiver.scm
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,11 @@
(flush-verbatim "Liii STEM interface to Quiver")
) ;define

;; 协议读取统一由 (texmacs protocol) 承担:兼容 R7RS read-line(不保留行尾
;; 换行),实现见 read-paragraph-by-visible-eof

(define (quiver-read-code)
(define (read-code code)
(let ((line (read-line)))
(if (or (eof-object? line) (string=? line "<EOF>\n"))
code
(read-code (string-append code line))
) ;if
) ;let
) ;define
(read-code "")
(read-paragraph-by-visible-eof)
) ;define

(define (gen-temp-path)
Expand Down
13 changes: 4 additions & 9 deletions TeXmacs/plugins/tikz/goldfish/tm-tikz.scm
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,11 @@
(flush-verbatim "Liii STEM interface to TikZ")
) ;define

;; 协议读取统一由 (texmacs protocol) 承担:兼容 R7RS read-line(不保留行尾
;; 换行),实现见 read-paragraph-by-visible-eof

(define (tikz-read-code)
(define (read-code code)
(let ((line (read-line)))
(if (or (eof-object? line) (string=? line "<EOF>\n"))
code
(read-code (string-append code line))
) ;if
) ;let
) ;define
(read-code "")
(read-paragraph-by-visible-eof)
) ;define

(define (decode-texmacs-markup code)
Expand Down
Loading