Skip to content

Commit 970586f

Browse files
authored
Fix error positions on tokenizing a literal terminated with a newline (#187)
1 parent e9aa0d4 commit 970586f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lexer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func (l *Lexer) consumeQuotedContent(q string, raw, unicode bool, name string) s
512512
}
513513

514514
if c == '\n' && len(q) != 3 {
515-
l.panicfAtPosition(token.Pos(l.pos), token.Pos(l.pos+i+1), "unclosed %s: newline appears in non triple-quoted", name)
515+
l.panicfAtPosition(token.Pos(l.pos), token.Pos(l.pos+i), "unclosed %s: newline appears in non triple-quoted", name)
516516
}
517517

518518
content = append(content, c)

lexer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ var lexerWrongTestCase = []struct {
149149
{"\b", 0, 0, "illegal input character: '\\b'"},
150150
{`"foo`, 0, 4, "unclosed string literal"},
151151
{`R"foo`, 1, 5, "unclosed raw string literal"},
152-
{"'foo\n", 0, 5, "unclosed string literal: newline appears in non triple-quoted"},
153-
{"R'foo\n", 1, 6, "unclosed raw string literal: newline appears in non triple-quoted"},
152+
{"'foo\n", 0, 4, "unclosed string literal: newline appears in non triple-quoted"},
153+
{"R'foo\n", 1, 5, "unclosed raw string literal: newline appears in non triple-quoted"},
154154
{"R'foo\\", 5, 6, "invalid escape sequence: \\<eof>"},
155155
{`"\400"`, 1, 3, "invalid escape sequence: \\4"},
156156
{`"\3xx"`, 1, 4, "invalid escape sequence: octal escape sequence must be follwed by 3 octal digits"},

0 commit comments

Comments
 (0)