mirror of
https://github.com/kanaka/mal.git
synced 2024-11-10 12:47:45 +03:00
Correctly report unterminated strings
This commit is contained in:
parent
8db930794d
commit
9b09c8a689
@ -6,24 +6,13 @@
|
|||||||
|
|
||||||
(in-package :reader)
|
(in-package :reader)
|
||||||
|
|
||||||
(defvar *two-char-token* "~@"
|
(defvar *string-re* "^\"\\(\\\\\\(.\\|
|
||||||
"RE two char")
|
\\)\\|[^\"\\]\\)*\"$"
|
||||||
|
|
||||||
(defvar *single-char-token* "[][{}()`'^@]"
|
|
||||||
"RE single char")
|
|
||||||
|
|
||||||
(defvar *string-re* "\"\\(?:\\\\\\(?:.\\|\n\\)\\|[^\"\\]\\)*\""
|
|
||||||
"RE string")
|
"RE string")
|
||||||
|
|
||||||
(defvar *comment-re* ";[^
|
(defvar *tokenizer-re* "[[:space:],]*\\(~@\\|[][{}()`'^@]\\|\"\\(\\\\\\(.\\|
|
||||||
]*"
|
\\)\\|[^\"\\]\\)*\"\\?\\|;[^
|
||||||
"RE comment")
|
]*\\|[^][[:space:]{}()`'\";]*\\)"
|
||||||
|
|
||||||
(defvar *identifier-re* "[^][[:space:]{}()`'\";]\\+"
|
|
||||||
"RE identifier")
|
|
||||||
|
|
||||||
(defvar *tokenizer-re* "[[:space:],]*\\(~@\\|[][{}()`'^@]\\|\"\\(\\\\\\(.\\|\n\\)\\|[^\"\\]\\)*\"\\|;[^
|
|
||||||
]*\\|[^][[:space:]{}()`'\";]\\+\\)"
|
|
||||||
"RE")
|
"RE")
|
||||||
|
|
||||||
(define-condition eof (error)
|
(define-condition eof (error)
|
||||||
@ -33,6 +22,15 @@
|
|||||||
"EOF encountered while reading ~a"
|
"EOF encountered while reading ~a"
|
||||||
(context condition)))))
|
(context condition)))))
|
||||||
|
|
||||||
|
(defun parse-string (token)
|
||||||
|
(if (and (> (length token) 1)
|
||||||
|
(regexp:match *string-re* token))
|
||||||
|
(read-from-string token)
|
||||||
|
;; A bit inaccurate
|
||||||
|
(error 'eof
|
||||||
|
:context "string")))
|
||||||
|
|
||||||
|
;; Useful to debug regexps
|
||||||
(defun test-re (re string)
|
(defun test-re (re string)
|
||||||
(let ((match (regexp:match re string)))
|
(let ((match (regexp:match re string)))
|
||||||
(when match
|
(when match
|
||||||
@ -105,6 +103,7 @@
|
|||||||
(consume reader)
|
(consume reader)
|
||||||
(nreverse forms)))
|
(nreverse forms)))
|
||||||
|
|
||||||
|
|
||||||
(defun read-atom (reader)
|
(defun read-atom (reader)
|
||||||
(let ((token (next reader)))
|
(let ((token (next reader)))
|
||||||
(cond
|
(cond
|
||||||
@ -117,5 +116,5 @@
|
|||||||
((string= token "nil")
|
((string= token "nil")
|
||||||
(make-mal-nil nil))
|
(make-mal-nil nil))
|
||||||
((char= (char token 0) #\")
|
((char= (char token 0) #\")
|
||||||
(make-mal-string (read-from-string token)))
|
(make-mal-string (parse-string token)))
|
||||||
(t (make-mal-symbol (read-from-string-preserving-case token))))))
|
(t (make-mal-symbol (read-from-string-preserving-case token))))))
|
||||||
|
Loading…
Reference in New Issue
Block a user