Fix lexing of empty double quotes

* geesh/lexer.scm (get-double-quotation): Handle empty quotation.
* tests/lexer.scm: Add a test for this and for empty single
quotes (which already worked correctly).
This commit is contained in:
Timothy Sample 2018-11-09 16:22:11 -05:00
parent ff14ea0097
commit 73414716bb
2 changed files with 9 additions and 0 deletions

View File

@ -385,6 +385,7 @@ next character statisfies @var{pred} (or is a newline)."
(#\" (begin
(get-char port)
`(<sh-quote> ,(match (join-contiguous-strings (reverse! acc))
(() "")
((word) word)
(words words)))))
((or #\$ #\`)

View File

@ -225,6 +225,10 @@
'((WORD (0 . 12) (<sh-quote> "foo\n#\\`$<\"")))
(tokenize "'foo\n#\\`$<\"'"))
(test-equal "Lexes an empty single quotation"
'((WORD (0 . 2) (<sh-quote> "")))
(tokenize "''"))
;;;
;;; Double quotations.
;;;
@ -241,6 +245,10 @@
'((WORD (0 . 9) (<sh-quote> "foo\n#<'")))
(tokenize "\"foo\n#<'\""))
(test-equal "Recognizes an empty double quotation"
'((WORD (0 . 2) (<sh-quote> "")))
(tokenize "\"\""))
(test-equal "Respects escapes for special characters in double quotations"
'((WORD (0 . 10) (<sh-quote> ("foo" (<sh-quote> "\"") "bar"))))
(tokenize "\"foo\\\"bar\""))