gc: insert semicolon at EOF if needed

R=ken2, gri
CC=golang-dev
https://golang.org/cl/2208053
This commit is contained in:
Russ Cox 2010-09-28 10:35:02 -04:00
parent b233ac8f18
commit ec13ed1fce
2 changed files with 11 additions and 7 deletions

View file

@ -1247,13 +1247,8 @@ yylex(void)
lx = _yylex();
if(curio.nlsemi && lx == EOF) {
// if the nlsemi bit is set, we'd be willing to
// insert a ; if we saw a \n, but we didn't.
// that means the final \n is missing.
// complain here, because we can give a
// good message. the syntax error we'd get
// otherwise is inscrutable.
yyerror("missing newline at end of file");
// Treat EOF as "end of line" for the purposes
// of inserting a semicolon.
lx = ';';
}

9
test/eof.go Normal file
View file

@ -0,0 +1,9 @@
// $G $D/$F.go
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// No newline at the end of this file.
package main