From c9dd35bf4888a03e6bc170611c9b521080d00912 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Wed, 22 Mar 2017 08:35:34 -0400 Subject: [PATCH] Handle eof in comments and do not prematurely close file handler --- parser.go | 1 - scanner.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/parser.go b/parser.go index 08609e7..a289eaf 100644 --- a/parser.go +++ b/parser.go @@ -40,7 +40,6 @@ func NewParser(reader io.Reader) *Parser { // NewFileParser will create and initialize a new Parser from a provided from a filename string func NewFileParser(filename string) (*Parser, error) { reader, err := os.Open(filename) - defer reader.Close() if err != nil { return nil, err } diff --git a/scanner.go b/scanner.go index 670b431..dae8857 100644 --- a/scanner.go +++ b/scanner.go @@ -167,7 +167,7 @@ func (scanner *Scanner) parseComment() { scanner.curTok.Literal = "" for { scanner.readRune() - if scanner.curCh == '\n' { + if scanner.curCh == '\n' || scanner.curCh == eof { break } scanner.curTok.Literal += string(scanner.curCh)