1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 13:00:26 +02:00

handle EOF correctly in parser and lexer

* module/language/elisp/lexer.scm (lex, get-lexer/1): Return a valid
  token at EOF.
* module/language/elisp/parser.scm (get-expression): Raise an error if
  EOF is reached.
  (read-elisp): If at EOF, return the EOF object instead of attempting
  to read an expression.
This commit is contained in:
Brian Templeton 2010-06-24 23:03:08 -04:00
parent 258914f320
commit c8ed3e7cef
2 changed files with 10 additions and 5 deletions

View file

@ -270,7 +270,7 @@
(c (read-char port)))
(cond
;; End of input must be specially marked to the parser.
((eof-object? c) '*eoi*)
((eof-object? c) (return 'eof c))
;; Whitespace, just skip it.
((char-whitespace? c) (lex port))
;; The dot is only the one for dotted lists if followed by
@ -390,7 +390,7 @@
(paren-level 0))
(lambda ()
(if finished
'*eoi*
(cons 'eof ((@ (rnrs io ports) eof-object)))
(let ((next (lex))
(quotation #f))
(case (car next)

View file

@ -178,6 +178,8 @@
(source-properties token)))
result)))
(case type
((eof)
(parse-error token "end of file during parsing"))
((integer float symbol character string)
(return (cdr token)))
((quote backquote unquote unquote-splicing)
@ -207,6 +209,9 @@
(with-fluids ((circular-definitions (make-circular-definitions)))
(let* ((lexer (get-lexer port))
(lexbuf (make-lexer-buffer lexer))
(result (get-expression lexbuf)))
(next (lexbuf 'peek)))
(if (eq? (car next) 'eof)
(cdr next)
(let ((result (get-expression lexbuf)))
(lexbuf 'finish)
result)))
result)))))