fix REPL treating a regex literal as an unbalanced form
repl-form-complete? entered the :regex state on '#' but only consumed the '#', so the opening '"' was then read by the :regex handler as the CLOSING quote. The regex body got scanned in :code state, and any delimiter or quote inside it (a group like #"(a)", a char class #"[0-9]+") threw off the paren/string count — so a one-line regex form was judged incomplete and the REPL hung waiting for continuation lines. Consume the '#"' together. Adds a self-checking predicate test (test/chez/repl-reader-test.clj, run via joltc so jolt.main resolves) and an end-to-end regex REPL case in smoke.sh.
This commit is contained in:
parent
4889505204
commit
e4cbbb8912
3 changed files with 53 additions and 2 deletions
27
test/chez/repl-reader-test.clj
Normal file
27
test/chez/repl-reader-test.clj
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
;; Self-checking regression for the REPL's read-until-complete predicate
|
||||
;; (jolt.main/repl-form-complete?), which decides whether a line buffer is a whole
|
||||
;; form or the REPL should keep reading continuation lines. Runs via `bin/joltc run`
|
||||
;; (jolt.main is loaded, so the private var resolves); prints a sentinel the smoke
|
||||
;; gate greps. The regex cases are the ones that regressed: a #"..." literal opens a
|
||||
;; regex whose body — parens, quotes and all — must not be miscounted as delimiters.
|
||||
(require 'jolt.main)
|
||||
|
||||
(def complete? jolt.main/repl-form-complete?)
|
||||
|
||||
;; [input expected-complete?]
|
||||
(def cases
|
||||
[["(+ 1 2)" true] ; balanced
|
||||
["(+ 1" false] ; open paren -> keep reading
|
||||
["(defn g [] (foo (bar" false] ; deeply unbalanced
|
||||
["[1 2 {:a 3}]" true] ; mixed bracket types balance
|
||||
["(str \")\")" true] ; a close-paren inside a string doesn't count
|
||||
["\\(" true] ; a paren char literal doesn't count
|
||||
["(+ 1 2) ; ) ) trailing" true] ; parens in a line comment don't count
|
||||
["(re-find #\"(a)(b)\" \"ab\")" true] ; groups inside a regex must not count as depth
|
||||
["#\"[0-9]+\"" true] ; a bare regex literal is a complete form
|
||||
["#\"a(b" false]]) ; an unterminated regex is incomplete
|
||||
|
||||
(let [bad (remove (fn [[in exp]] (= exp (boolean (complete? in)))) cases)]
|
||||
(println (if (empty? bad)
|
||||
"REPL-READER OK"
|
||||
(str "REPL-READER FAIL " (pr-str (map first bad))))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue