From 27d17255dbe5c620dba1a427c2fd5e2d46cb03f7 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 30 Jul 2013 10:27:08 -0400 Subject: [PATCH] cmd/gc: insert \n at end of every input file Not just the first one. Fixes #5433. Fixes #5913. R=ken2 CC=golang-dev https://golang.org/cl/12028049 --- src/cmd/gc/go.h | 1 + src/cmd/gc/lex.c | 5 ++++- test/fixedbugs/bug435.go | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cmd/gc/go.h b/src/cmd/gc/go.h index db25013cca1..e530e79dd0c 100644 --- a/src/cmd/gc/go.h +++ b/src/cmd/gc/go.h @@ -751,6 +751,7 @@ struct Io int32 ilineno; int nlsemi; int eofnl; + int last; int peekc; int peekc1; // second peekc for ... char* cp; // used for content when bin==nil diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c index b7f71d553ea..750b6aad6a9 100644 --- a/src/cmd/gc/lex.c +++ b/src/cmd/gc/lex.c @@ -329,6 +329,8 @@ main(int argc, char *argv[]) curio.peekc = 0; curio.peekc1 = 0; curio.nlsemi = 0; + curio.eofnl = 0; + curio.last = 0; // Skip initial BOM if present. if(Bgetrune(curio.bin) != BOM) @@ -1602,7 +1604,7 @@ check: } case EOF: // insert \n at EOF - if(curio.eofnl) + if(curio.eofnl || curio.last == '\n') return EOF; curio.eofnl = 1; c = '\n'; @@ -1611,6 +1613,7 @@ check: lexlineno++; break; } + curio.last = c; return c; } diff --git a/test/fixedbugs/bug435.go b/test/fixedbugs/bug435.go index 9c30b143bcf..45323d8eed6 100644 --- a/test/fixedbugs/bug435.go +++ b/test/fixedbugs/bug435.go @@ -12,4 +12,4 @@ package main func foo() { - bar(1, // ERROR "unexpected|missing|undefined" + bar(1, // ERROR "unexpected|missing|undefined" \ No newline at end of file