Skip to content

Commit 66eb75e

Browse files
committed
Fix empty triple quote parse error
1 parent bce7f80 commit 66eb75e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Diff for: parser/lexer.lisp

+3-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,9 @@ Used by compiler to generate 'forbidden' identfiers.")
585585
(not prev-bs))
586586
until (and (char= z x y ch1) (not prev-bs))
587587
finally (return (- %lex-last-read-char-ix% 3)))))
588-
(lex-substring start end)))
588+
(if (> start end)
589+
(return-from read-kind "")
590+
(lex-substring start end))))
589591

590592
((char= ch1 ch2) ;; "" or '' but not """ or '''
591593
(when ch3 (lex-unread-char ch3))

Diff for: test/parser-test.lisp

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@
5757
(test-equal '([module-stmt] ([suite-stmt] (([literal-expr] :number 42)))) (ps "42"))
5858
(test-equal '([module-stmt] ([suite-stmt] (([literal-expr] :string "x")))) (ps "'x'"))
5959
(test-equal '([module-stmt] ([suite-stmt] (([literal-expr] :bytes "x")))) (ps "b'x'"))
60-
60+
(test-equal '([module-stmt] ([suite-stmt] (([literal-expr] :string "")))) (ps "\"\"\"\"\"\""))
61+
(test-equal '([module-stmt] ([suite-stmt] (([literal-expr] :string "")))) (ps "''''''"))
62+
(test-equal '([module-stmt] ([suite-stmt] (([literal-expr] :string "x")))) (ps "'''x'''"))
63+
(test-equal '([module-stmt] ([suite-stmt] (([literal-expr] :string " ")))) (ps "''' '''"))
64+
(test-equal '([module-stmt] ([suite-stmt] (([literal-expr] :string "'")))) (ps "'''\\''''"))
65+
6166
;; variables
6267
(test-equal '([assign-stmt] ([literal-expr] :number 3) (([identifier-expr] {y} ))) (ps "y = 3" t))
6368
(test-equal '([assign-stmt] ([literal-expr] :number 3) (([identifier-expr] {len}))) (ps "len = 3" t))

0 commit comments

Comments
 (0)