From 6db264d96fef4829a7f925375f8bf5ab3cad69ca Mon Sep 17 00:00:00 2001 From: nasa9084 Date: Tue, 12 Nov 2019 19:50:58 +0900 Subject: [PATCH] Comments must be separated from other tokens by white space characters --- parser/parser_test.go | 8 ++++++++ scanner/scanner.go | 16 +++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/parser/parser_test.go b/parser/parser_test.go index 2abd84bc..c3cbc3b0 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -259,6 +259,14 @@ d: e # comment a: b: c d: e +`, + }, + { + ` +a: b#notcomment +`, + ` +a: b#notcomment `, }, { diff --git a/scanner/scanner.go b/scanner/scanner.go index 63a3d924..47e9c882 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -476,13 +476,15 @@ func (s *Scanner) scan(ctx *Context) (pos int) { return } case '#': - s.addBufferedTokenIfExists(ctx) - token, progress := s.scanComment(ctx) - ctx.addToken(token) - s.progressColumn(ctx, progress) - s.progressLine(ctx) - pos += progress - return + if ctx.bufferedSrc() == "" || ctx.previousChar() == ' ' { + s.addBufferedTokenIfExists(ctx) + token, progress := s.scanComment(ctx) + ctx.addToken(token) + s.progressColumn(ctx, progress) + s.progressLine(ctx) + pos += progress + return + } case '\'', '"': if ctx.bufferedSrc() == "" { token, progress := s.scanQuote(ctx, c)