nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: cloudspannerecosystem/memefish
Pull request #187 (2024-10-30 11:17:11)

Fix error positions on tokenizing a literal terminated with a newline
Before:

```console
go run ./tools/parse/main.go $'"foo\n'
syntax error: :1:1: unclosed string literal: newline appears in non triple-quoted

  1:  "foo
  2:
exit status 1
```

After:

```console
$ go run ./tools/parse/main.go $'"foo\n'
syntax error: :1:1: unclosed string literal: newline appears in non triple-quoted

  1:  "foo
      ^~~~
exit status 1
```


Patch:
diff --git a/lexer.go b/lexer.go
index 4b96e4b..216aafb 100644
--- a/lexer.go
+++ b/lexer.go
@@ -512,7 +512,7 @@ func (l *Lexer) consumeQuotedContent(q string, raw, unicode bool, name string) s
 		}
 
 		if c == '\n' && len(q) != 3 {
-			l.panicfAtPosition(token.Pos(l.pos), token.Pos(l.pos+i+1), "unclosed %s: newline appears in non triple-quoted", name)
+			l.panicfAtPosition(token.Pos(l.pos), token.Pos(l.pos+i), "unclosed %s: newline appears in non triple-quoted", name)
 		}
 
 		content = append(content, c)
diff --git a/tools/gen-ast-pos/main.go b/tools/gen-ast-pos/main.go
index 1041e3c..2bcee65 100644
--- a/tools/gen-ast-pos/main.go
+++ b/tools/gen-ast-pos/main.go
@@ -80,6 +80,7 @@ func main() {
 			e := m[1]
 			expr, err := poslang.Parse(e)
 			if err != nil {
+				log.Printf("Error at node %s, pos = %s", nodes[len(nodes)-1].name, e)
 				log.Fatal(err)
 			}
 			nodes[len(nodes)-1].posExpr = expr
@@ -90,6 +91,7 @@ func main() {
 			e := m[1]
 			expr, err := poslang.Parse(e)
 			if err != nil {
+				log.Printf("Error at node %s, end = %s", nodes[len(nodes)-1].name, e)
 				log.Fatal(err)
 			}
 			nodes[len(nodes)-1].endExpr = expr


Test patch:
diff --git a/lexer_test.go b/lexer_test.go
index 7f9fc38..e69aef1 100644
--- a/lexer_test.go
+++ b/lexer_test.go
@@ -149,8 +149,8 @@ var lexerWrongTestCase = []struct {
 	{"\b", 0, 0, "illegal input character: '\\b'"},
 	{`"foo`, 0, 4, "unclosed string literal"},
 	{`R"foo`, 1, 5, "unclosed raw string literal"},
-	{"'foo\n", 0, 5, "unclosed string literal: newline appears in non triple-quoted"},
-	{"R'foo\n", 1, 6, "unclosed raw string literal: newline appears in non triple-quoted"},
+	{"'foo\n", 0, 4, "unclosed string literal: newline appears in non triple-quoted"},
+	{"R'foo\n", 1, 5, "unclosed raw string literal: newline appears in non triple-quoted"},
 	{"R'foo\\", 5, 6, "invalid escape sequence: \\<eof>"},
 	{`"\400"`, 1, 3, "invalid escape sequence: \\4"},
 	{`"\3xx"`, 1, 4, "invalid escape sequence: octal escape sequence must be follwed by 3 octal digits"},