birth: Include pos and window in lexing error

Analog to prelude.js's `Parser#_error'.

* build-aux/bootstrap/birth.scm (parse-error): Add procedure.
  (lex): Use it for string error.
master
Mike Gerwitz 2017-08-31 12:44:41 -04:00
parent b58bbe3949
commit 5fca236834
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
1 changed files with 13 additions and 1 deletions

View File

@ -85,7 +85,8 @@
;; quotes, which can be escaped with a backslash
(("\"") (let ((str (js:match-regexp "^\"(|.*?[^\\\\])\""
trim)))
(or str (error "missing closing string delimiter" str))
(or str (parse-error
src pos "missing closing string delimiter"))
;; a string token consists of the entire string
;; including quotes as its lexeme, but its value will
;; be the value of the string without quotes due to
@ -100,6 +101,17 @@
(token "symbol" symbol trim newpos))))))))
;; Throw an error with a window of surrounding source code.
;;
;; The "window" is simply ten characters to the left and right of the
;; first character of the source input SRC that resulted in the error.
;; It's a little more than useless.
(define (parse-error src pos msg)
(let ((window (substring src (- pos 10) (+ pos 10))))
(error (string-append msg " (pos " pos "): " window)
src)))
;; Produce a token and recurse.
;;
;; The token will be concatenated with the result of the mutually