diff options
author | Brian Templeton <bpt@hcoop.net> | 2010-06-24 23:03:08 -0400 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2010-12-07 13:21:02 +0100 |
commit | 1dfe593954b094bfd25738f1553baa3a557476a9 (patch) | |
tree | b01a4dd0f960f4d3ce41103a0c9c4a9240878ee7 | |
parent | 8295b7c4e5637d363649101fa5080f9d31b80c14 (diff) | |
download | guile-1dfe593954b094bfd25738f1553baa3a557476a9.tar.gz |
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.
Signed-off-by: Andy Wingo <wingo@pobox.com>
-rw-r--r-- | module/language/elisp/lexer.scm | 4 | ||||
-rw-r--r-- | module/language/elisp/parser.scm | 11 |
2 files changed, 10 insertions, 5 deletions
diff --git a/module/language/elisp/lexer.scm b/module/language/elisp/lexer.scm index 9c4bf5893..b201e18ce 100644 --- a/module/language/elisp/lexer.scm +++ b/module/language/elisp/lexer.scm @@ -269,7 +269,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 @@ -389,7 +389,7 @@ (paren-level 0)) (lambda () (if finished - '*eoi* + (cons 'eof ((@ (rnrs io ports) eof-object))) (let ((next (lex)) (quotation #f)) (case (car next) diff --git a/module/language/elisp/parser.scm b/module/language/elisp/parser.scm index 3436abf22..188b2961c 100644 --- a/module/language/elisp/parser.scm +++ b/module/language/elisp/parser.scm @@ -179,6 +179,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) @@ -208,6 +210,9 @@ (with-fluids ((circular-definitions (make-circular-definitions))) (let* ((lexer (get-lexer port)) (lexbuf (make-lexer-buffer lexer)) - (result (get-expression lexbuf))) - (lexbuf 'finish) - result))) + (next (lexbuf 'peek))) + (if (eq? (car next) 'eof) + (cdr next) + (let ((result (get-expression lexbuf))) + (lexbuf 'finish) + result))))) |