Skip to content

Commit d1b02ac

Browse files
authored
Merge pull request #50 from yoheimuta/allow-comment-no-newline
feat: Allow a comment without newlines
2 parents 1c8bf3e + d553803 commit d1b02ac

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

internal/lexer/scanner/comment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ func (s *Scanner) scanComment() (string, error) {
88
switch ch {
99
case '/':
1010
for ch != '\n' {
11-
if s.isEOF() {
12-
return lit, s.unexpected(eof, "\n")
13-
}
1411
lit += string(ch)
1512

13+
if s.isEOF() {
14+
return lit, nil
15+
}
1616
ch = s.read()
1717
}
1818
case '*':

internal/lexer/scanner/scanner_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,26 @@ fugafuga
305305
},
306306
},
307307
},
308+
{
309+
name: "scan a comment without a newline",
310+
input: `
311+
// hogehoge`,
312+
mode: scanner.ScanComment,
313+
wants: []want{
314+
{
315+
token: scanner.TCOMMENT,
316+
text: "// hogehoge",
317+
pos: scanner.Position{
318+
Position: meta.Position{
319+
320+
Offset: 1,
321+
Line: 2,
322+
Column: 1,
323+
},
324+
},
325+
},
326+
},
327+
},
308328
{
309329
name: "scan strLits",
310330
input: `"" '' "abc" 'あいう' "\x1fzz" '\123\n\\'`,

0 commit comments

Comments
 (0)