nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: robertkrimen/otto
Pull request #495 (2023-05-19 00:06:20)

Add BadStatement case to walk.go to avoid panic
This PR is to address what I think might have been an oversight in the ast package walk.go file.

When the switch runs across a BadStatement node, this causes it to default (and panic).

I have added an empty case for this node type similar to BadExpression to get around this as well as a unit test.

stevenh: If you rebase to master, I fixed the lint issues @amaicode 
amaicode: > If you rebase to master, I fixed the lint issues @amaicode

Just rebased :)

Patch:
diff --git a/ast/walk.go b/ast/walk.go
index 521445b..4422930 100644
--- a/ast/walk.go
+++ b/ast/walk.go
@@ -38,6 +38,7 @@ func Walk(v Visitor, n Node) {
 			Walk(v, n.Right)
 		}
 	case *BadExpression:
+	case *BadStatement:
 	case *BinaryExpression:
 		if n != nil {
 			Walk(v, n.Left)


Test patch:
diff --git a/ast/walk_test.go b/ast/walk_test.go
index 1748c67..d4f23e9 100644
--- a/ast/walk_test.go
+++ b/ast/walk_test.go
@@ -136,3 +136,22 @@ func Test_issue261(t *testing.T) {
 		})
 	}
 }
+
+func TestBadStatement(t *testing.T) {
+	source := `
+	var abc;
+	break; do {
+	} while(true);
+`
+	program, err := parser.ParseFile(nil, "", source, 0)
+	require.ErrorContains(t, err, "Illegal break statement")
+
+	w := &walker{
+		source: source,
+		seen:   make(map[ast.Node]struct{}),
+	}
+
+	require.NotPanics(t, func() {
+		ast.Walk(w, program)
+	})
+}
Repository: robertkrimen/otto
Pull request #501 (2023-07-14 07:37:58)

Fix the starting position of if statement
Currently, IfStatement#Idx0 points to the right parenthesis after the test expression.

stevenh: Could you rebase to the latest master which fixes the linting issues flag @tyamagu2 
tyamagu2: @stevenh done

Patch:
diff --git a/parser/statement.go b/parser/statement.go
index c4a03b4..0f8262b 100644
--- a/parser/statement.go
+++ b/parser/statement.go
@@ -722,7 +722,7 @@ func (p *parser) parseIfStatement() ast.Statement {
 	if p.mode&StoreComments != 0 {
 		comments = p.comments.FetchAll()
 	}
-	p.expect(token.IF)
+	pos := p.expect(token.IF)
 	var ifComments []*ast.Comment
 	if p.mode&StoreComments != 0 {
 		ifComments = p.comments.FetchAll()
@@ -730,7 +730,7 @@ func (p *parser) parseIfStatement() ast.Statement {
 
 	p.expect(token.LEFT_PARENTHESIS)
 	node := &ast.IfStatement{
-		If:   p.idx,
+		If:   pos,
 		Test: p.parseExpression(),
 	}
 	p.expect(token.RIGHT_PARENTHESIS)


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 202d8da..9f6c178 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -1022,7 +1022,8 @@ func TestPosition(t *testing.T) {
 		is(err, nil)
 		block := program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.FunctionLiteral).Body.(*ast.BlockStatement)
 		node = block.List[0].(*ast.IfStatement)
-		is(node.Idx0(), 21)
+		is(node.Idx0(), 14)
+		is(parser.slice(node.Idx0(), node.Idx1()), "if (abc) { throw 'failed'; }")
 		node = node.(*ast.IfStatement).Consequent.(*ast.BlockStatement).List[0].(*ast.ThrowStatement)
 		is(node.Idx0(), 39)
 	})
Repository: robertkrimen/otto
Pull request #503 (2023-07-18 02:29:21)

fix: starting positions of for and for-in statements
Currently, the parser does not set their starting positions.


Patch:
diff --git a/parser/statement.go b/parser/statement.go
index 0f8262b..f853afc 100644
--- a/parser/statement.go
+++ b/parser/statement.go
@@ -603,6 +603,7 @@ func (p *parser) parseForOrForInStatement() ast.Statement {
 		}
 
 		forin := p.parseForIn(left[0])
+		forin.For = idx
 		if p.mode&StoreComments != 0 {
 			p.comments.CommentMap.AddComments(forin, comments, ast.LEADING)
 			p.comments.CommentMap.AddComments(forin, forComments, ast.FOR)
@@ -616,6 +617,7 @@ func (p *parser) parseForOrForInStatement() ast.Statement {
 	p.expect(token.SEMICOLON)
 	initializer := &ast.SequenceExpression{Sequence: left}
 	forstatement := p.parseFor(initializer)
+	forstatement.For = idx
 	if p.mode&StoreComments != 0 {
 		p.comments.CommentMap.AddComments(forstatement, comments, ast.LEADING)
 		p.comments.CommentMap.AddComments(forstatement, forComments, ast.FOR)


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 9f6c178..603c994 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -1026,6 +1026,22 @@ func TestPosition(t *testing.T) {
 		is(parser.slice(node.Idx0(), node.Idx1()), "if (abc) { throw 'failed'; }")
 		node = node.(*ast.IfStatement).Consequent.(*ast.BlockStatement).List[0].(*ast.ThrowStatement)
 		is(node.Idx0(), 39)
+
+		parser = newParser("", "(function(){ for (x=1; x<=4; x++) { console.log(x); } })", 1, nil)
+		program, err = parser.parse()
+		is(err, nil)
+		block = program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.FunctionLiteral).Body.(*ast.BlockStatement)
+		node = block.List[0].(*ast.ForStatement)
+		is(node.Idx0(), 14)
+		is(parser.slice(node.Idx0(), node.Idx1()), "for (x=1; x<=4; x++) { console.log(x); }")
+
+		parser = newParser("", "(function(){ for (p in o) { console.log(p); } })", 1, nil)
+		program, err = parser.parse()
+		is(err, nil)
+		block = program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.FunctionLiteral).Body.(*ast.BlockStatement)
+		node = block.List[0].(*ast.ForInStatement)
+		is(node.Idx0(), 14)
+		is(parser.slice(node.Idx0(), node.Idx1()), "for (p in o) { console.log(p); }")
 	})
 }
Repository: robertkrimen/otto
Pull request #504 (2023-07-18 10:19:05)

Fix Idx1 of ObjectLiteral and ArrayLiteral
Idx1 should point to the first character immediately after the node, rather than the last character of the node.


Patch:
diff --git a/ast/node.go b/ast/node.go
index 7cc2344..db37770 100644
--- a/ast/node.go
+++ b/ast/node.go
@@ -36,7 +36,7 @@ func (al *ArrayLiteral) Idx0() file.Idx {
 
 // Idx1 implements Node.
 func (al *ArrayLiteral) Idx1() file.Idx {
-	return al.RightBracket
+	return al.RightBracket + 1
 }
 
 // expression implements Expression.
@@ -343,7 +343,7 @@ func (ol *ObjectLiteral) Idx0() file.Idx {
 
 // Idx1 implements Node.
 func (ol *ObjectLiteral) Idx1() file.Idx {
-	return ol.RightBrace
+	return ol.RightBrace + 1
 }
 
 // expression implements Expression.


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 603c994..13f7328 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -1042,6 +1042,20 @@ func TestPosition(t *testing.T) {
 		node = block.List[0].(*ast.ForInStatement)
 		is(node.Idx0(), 14)
 		is(parser.slice(node.Idx0(), node.Idx1()), "for (p in o) { console.log(p); }")
+
+		parser = newParser("", "x = {x: 1}", 1, nil)
+		program, err = parser.parse()
+		is(err, nil)
+		node = program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.AssignExpression).Right.(*ast.ObjectLiteral)
+		is(node.Idx0(), 5)
+		is(parser.slice(node.Idx0(), node.Idx1()), "{x: 1}")
+
+		parser = newParser("", "x = [1, 2]", 1, nil)
+		program, err = parser.parse()
+		is(err, nil)
+		node = program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.AssignExpression).Right.(*ast.ArrayLiteral)
+		is(node.Idx0(), 5)
+		is(parser.slice(node.Idx0(), node.Idx1()), "[1, 2]")
 	})
 }
Repository: robertkrimen/otto
Pull request #520 (2024-04-24 17:39:49)

Support trailing comma after the last argument.
Example:

```js
function mergeObjects(x, y) { /* dummy body */}

mergeObjects(
    { "duck": "quack" },
    { "dog": "bark" }, // Allow trailing comma after the last argument.
);
```


Patch:
diff --git a/parser/expression.go b/parser/expression.go
index 3c9410e..fe73fa2 100644
--- a/parser/expression.go
+++ b/parser/expression.go
@@ -384,21 +384,19 @@ func (p *parser) parseArgumentList() (argumentList []ast.Expression, idx0, idx1
 		p.comments.Unset()
 	}
 	idx0 = p.expect(token.LEFT_PARENTHESIS)
-	if p.token != token.RIGHT_PARENTHESIS {
-		for {
-			exp := p.parseAssignmentExpression()
-			if p.mode&StoreComments != 0 {
-				p.comments.SetExpression(exp)
-			}
-			argumentList = append(argumentList, exp)
-			if p.token != token.COMMA {
-				break
-			}
-			if p.mode&StoreComments != 0 {
-				p.comments.Unset()
-			}
-			p.next()
+	for p.token != token.RIGHT_PARENTHESIS {
+		exp := p.parseAssignmentExpression()
+		if p.mode&StoreComments != 0 {
+			p.comments.SetExpression(exp)
+		}
+		argumentList = append(argumentList, exp)
+		if p.token != token.COMMA {
+			break
 		}
+		if p.mode&StoreComments != 0 {
+			p.comments.Unset()
+		}
+		p.next()
 	}
 	if p.mode&StoreComments != 0 {
 		p.comments.Unset()


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 9c547fd..165a688 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -879,6 +879,15 @@ func TestParser(t *testing.T) {
                 2
             debugger
         `, nil)
+
+		test(`
+            function mergeObjects(x, y) { /* dummy body */}
+
+            mergeObjects(
+                { "duck": "quack" },
+                { "dog": "bark" }, // Allow trailing comma after the last argument.
+            );
+        `, nil)
 	})
 }
Repository: robertkrimen/otto
Pull request #529 (2024-07-05 11:00:57)

fix: missing flag from regex literal in corner case
In the specific corner case where a regex contains a flag but is not followed by any symbols, the `ast.RegExpLiteral.Literal` value would drop (part of) that flag.

This happens because the `p.next()` call during the parsing of the flag wouldn't actually advance the `p.chrOffset`, and thus `endOffset` would be erroneously adjusted.

The fix is just to use the current `p.chrOffset` and then call `p.next()` afterwards.

psve: @stevenh , I removed the erroneous import, the linter checks should pass now. 

Patch:
diff --git a/parser/expression.go b/parser/expression.go
index fe73fa2..2c8e299 100644
--- a/parser/expression.go
+++ b/parser/expression.go
@@ -136,8 +136,8 @@ func (p *parser) parseRegExpLiteral() *ast.RegExpLiteral {
 	flags := ""
 	if p.token == token.IDENTIFIER { // gim
 		flags = p.literal
+		endOffset = p.chrOffset
 		p.next()
-		endOffset = p.chrOffset - 1
 	}
 
 	var value string


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 165a688..303e01d 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -975,6 +975,32 @@ func Test_parseNumberLiteral(t *testing.T) {
 	})
 }
 
+func Test_praseRegExpLiteral(t *testing.T) {
+	tt(t, func() {
+		test := func(input, literal, pattern, flags string) {
+			parser := newParser("", input, 1, nil)
+			program, err := parser.parse()
+			is(err, nil)
+
+			regex := program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.RegExpLiteral)
+			is(regex.Literal, literal)
+			is(regex.Pattern, pattern)
+			is(regex.Flags, flags)
+		}
+
+		test("/abc/", "/abc/", "abc", "")
+		test("/abc/gim", "/abc/gim", "abc", "gim")
+		test("/abc/ ", "/abc/", "abc", "")
+		test("/abc/gim ", "/abc/gim", "abc", "gim")
+		test("/abc/;", "/abc/", "abc", "")
+		test("/abc/gim;", "/abc/gim", "abc", "gim")
+		test("/abc/\n", "/abc/", "abc", "")
+		test("/abc/gim\n", "/abc/gim", "abc", "gim")
+		test("/abc/;\n", "/abc/", "abc", "")
+		test("/abc/gim;\n", "/abc/gim", "abc", "gim")
+	})
+}
+
 func TestPosition(t *testing.T) {
 	tt(t, func() {
 		parser := newParser("", "// Lorem ipsum", 1, nil)
Repository: rollbar/rollbar-go
Pull request #60 (2019-06-11 16:49:17)

Use actual error class name  for default error type
Grouping in the dashboard gets scrambled when sending hash strings as the error class. The current grouping logic is smart enough to use back trace and other signals to bucket these.


Patch:
diff --git a/transforms.go b/transforms.go
index e15bdb6..a10a21a 100644
--- a/transforms.go
+++ b/transforms.go
@@ -2,8 +2,6 @@ package rollbar
 
 import (
 	"context"
-	"fmt"
-	"hash/adler32"
 	"net/http"
 	"net/url"
 	"reflect"
@@ -294,9 +292,6 @@ func errorClass(err error) string {
 	class := reflect.TypeOf(err).String()
 	if class == "" {
 		return "panic"
-	} else if class == "*errors.errorString" {
-		checksum := adler32.Checksum([]byte(err.Error()))
-		return fmt.Sprintf("{%x}", checksum)
 	} else {
 		return strings.TrimPrefix(class, "*")
 	}


Test patch:
diff --git a/rollbar_test.go b/rollbar_test.go
index 6ddcfdd..361ec9e 100644
--- a/rollbar_test.go
+++ b/rollbar_test.go
@@ -44,7 +44,9 @@ func testErrorStackWithSkipGeneric2(s string) {
 
 func TestErrorClass(t *testing.T) {
 	errors := map[string]error{
-		"{4b81076c}":          fmt.Errorf("something is broken"),
+		// generic error
+		"errors.errorString":          fmt.Errorf("something is broken"),
+		// custom error
 		"rollbar.CustomError": &CustomError{"terrible mistakes were made"},
 	}
Repository: rollbar/rollbar-go
Pull request #94 (2022-06-13 18:29:39)

fixed default IP Address, removed the port
## Description of the change

fixed default IP Address in the request, removed the port

## Type of change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Maintenance
- [ ] New release

## Checklists

### Development

- [x] Lint rules pass locally
- [x] The code changed/added as part of this pull request has been covered with tests
- [x] All tests related to the changed code pass in development

### Code review

- [x] This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
- [x] "Ready for review" label attached to the PR and reviewers assigned
- [x] Issue from task tracker has a link to this pull request
- [x] Changes have been reviewed by at least one other engineer



Patch:
diff --git a/transforms.go b/transforms.go
index d2a1e39..336168a 100644
--- a/transforms.go
+++ b/transforms.go
@@ -146,7 +146,9 @@ func remoteIP(req *http.Request) string {
 		ips := strings.Split(forwardedIPs, ", ")
 		return ips[0]
 	}
-	return req.RemoteAddr
+	remoteAddr := req.RemoteAddr
+	spltRemoteAddr := strings.Split(remoteAddr, ":")
+	return spltRemoteAddr[0]
 }
 
 // filterFlatten filters sensitive information like passwords from being sent to Rollbar, and


Test patch:
diff --git a/rollbar_test.go b/rollbar_test.go
index df58dc1..babe5a9 100644
--- a/rollbar_test.go
+++ b/rollbar_test.go
@@ -209,7 +209,7 @@ func TestBuildBodyNoBaseCustom(t *testing.T) {
 func TestErrorRequest(t *testing.T) {
 	r, _ := http.NewRequest("GET", "http://foo.com/somethere?param1=true", nil)
 	r.RemoteAddr = "1.1.1.1:123"
-
+	SetCaptureIp(CaptureIpFull)
 	object := std.requestDetails(r)
 
 	if object["url"] != "http://foo.com/somethere?param1=true" {
@@ -223,6 +223,9 @@ func TestErrorRequest(t *testing.T) {
 	if object["query_string"] != "param1=true" {
 		t.Errorf("wrong id, got %v", object["query_string"])
 	}
+	if object["user_ip"] != "1.1.1.1" {
+		t.Errorf("wrong user_ip, got %v", object["user_ip"])
+	}
 }
 
 func TestRequestForwardedIP(t *testing.T) {
Repository: andig/evcc
Pull request #432 (2020-11-13 14:40:43)

Let vehicle control deactivation at target soc 100%
Fix https://github.com/andig/evcc/issues/431


Patch:
diff --git a/core/loadpoint.go b/core/loadpoint.go
index fec0e29f..a903b817 100644
--- a/core/loadpoint.go
+++ b/core/loadpoint.go
@@ -370,6 +370,7 @@ func (lp *LoadPoint) connected() bool {
 func (lp *LoadPoint) targetSocReached() bool {
 	return lp.vehicle != nil &&
 		lp.SoC.Target > 0 &&
+		lp.SoC.Target < 100 &&
 		lp.socCharge >= float64(lp.SoC.Target)
 }
 


Test patch:
diff --git a/core/loadpoint_test.go b/core/loadpoint_test.go
index ec0dc1a3..600f4eb7 100644
--- a/core/loadpoint_test.go
+++ b/core/loadpoint_test.go
@@ -623,16 +623,17 @@ func TestTargetSoC(t *testing.T) {
 		soc     float64
 		res     bool
 	}{
-		{nil, 0, 0, false},    // never reached without vehicle
-		{nil, 0, 10, false},   // never reached without vehicle
-		{nil, 80, 0, false},   // never reached without vehicle
-		{nil, 80, 80, false},  // never reached without vehicle
-		{nil, 80, 100, false}, // never reached without vehicle
-		{vhc, 0, 0, false},    // target disabled
-		{vhc, 0, 10, false},   // target disabled
-		{vhc, 80, 0, false},   // target not reached
-		{vhc, 80, 80, true},   // target reached
-		{vhc, 80, 100, true},  // target reached
+		{nil, 0, 0, false},     // never reached without vehicle
+		{nil, 0, 10, false},    // never reached without vehicle
+		{nil, 80, 0, false},    // never reached without vehicle
+		{nil, 80, 80, false},   // never reached without vehicle
+		{nil, 80, 100, false},  // never reached without vehicle
+		{vhc, 0, 0, false},     // target disabled
+		{vhc, 0, 10, false},    // target disabled
+		{vhc, 80, 0, false},    // target not reached
+		{vhc, 80, 80, true},    // target reached
+		{vhc, 80, 100, true},   // target reached
+		{vhc, 100, 100, false}, // target reached, let ev control deactivation
 	}
 
 	for _, tc := range tc {
Repository: alecthomas/chroma
Pull request #515 (2021-05-23 21:15:12)

Add tabindex="0" to default <pre> wrapper
Closes https://github.com/alecthomas/chroma/issues/514


Patch:
diff --git a/formatters/html/html.go b/formatters/html/html.go
index a0854af..5121529 100644
--- a/formatters/html/html.go
+++ b/formatters/html/html.go
@@ -131,7 +131,7 @@ var (
 	}
 	defaultPreWrapper = preWrapper{
 		start: func(code bool, styleAttr string) string {
-			return fmt.Sprintf("<pre%s>", styleAttr)
+			return fmt.Sprintf(`<pre tabindex="0"%s>`, styleAttr)
 		},
 		end: func(code bool) string {
 			return "</pre>"


Test patch:
diff --git a/formatters/html/html_test.go b/formatters/html/html_test.go
index 408d0df..b261ade 100644
--- a/formatters/html/html_test.go
+++ b/formatters/html/html_test.go
@@ -202,7 +202,7 @@ func TestWithPreWrapper(t *testing.T) {
 
 	t.Run("Regular", func(t *testing.T) {
 		s := format(New(WithClasses(true)))
-		assert.Equal(t, s, `<pre class="chroma"><span class="nb">echo</span> FOO</pre>`)
+		assert.Equal(t, s, `<pre tabindex="0" class="chroma"><span class="nb">echo</span> FOO</pre>`)
 	})
 
 	t.Run("PreventSurroundingPre", func(t *testing.T) {
@@ -246,7 +246,7 @@ func TestReconfigureOptions(t *testing.T) {
 	err = f.Format(&buf, styles.Fallback, it)
 
 	assert.NoError(t, err)
-	assert.Equal(t, `<pre class="chroma"><span class="nb">echo</span> FOO</pre>`, buf.String())
+	assert.Equal(t, `<pre tabindex="0" class="chroma"><span class="nb">echo</span> FOO</pre>`, buf.String())
 }
 
 func TestWriteCssWithAllClasses(t *testing.T) {
Repository: alecthomas/chroma
Pull request #525 (2021-06-17 07:56:05)

fish: Fix incorrect tokenisation of command arguments containing dash
Command line arguments containing dash/hyphen were incorrectly tokenised as command line options.


Patch:
diff --git a/lexers/f/fish.go b/lexers/f/fish.go
index c350900..29d5028 100644
--- a/lexers/f/fish.go
+++ b/lexers/f/fish.go
@@ -74,7 +74,7 @@ func fishRules() Rules {
 			{`&&|\|\||&|\||\^|<|>`, Operator, nil},
 			{`\s+`, Text, nil},
 			{`\b\d+\b`, LiteralNumber, nil},
-			{`--?[^\d][\w-]*`, NameAttribute, nil},
+			{`(?<=\s+)--?[^\d][\w-]*`, NameAttribute, nil},
 			{".+?", Text, nil},
 		},
 		"string": {


Test patch:
diff --git a/lexers/testdata/fish.actual b/lexers/testdata/fish.actual
index 7da42b4..1e9bc1c 100644
--- a/lexers/testdata/fish.actual
+++ b/lexers/testdata/fish.actual
@@ -24,6 +24,8 @@ set data (cat data | string split0)
 
 grep fish myanimallist1 | wc -l
 
+command some-arg-with-dash
+
 echo input.{c,h,txt}
 
 echo {$dogs}dog
@@ -241,4 +243,4 @@ function fish_config --description "Launch fish's web based configuration"
         end
 
         return 0
-    end
\ No newline at end of file
+    end
diff --git a/lexers/testdata/fish.expected b/lexers/testdata/fish.expected
index 1583669..ee7a7c1 100644
--- a/lexers/testdata/fish.expected
+++ b/lexers/testdata/fish.expected
@@ -94,6 +94,8 @@
   {"type":"Text","value":" "},
   {"type":"NameAttribute","value":"-l"},
   {"type":"Text","value":"\n\n"},
+  {"type":"NameBuiltin","value":"command "},
+  {"type":"Text","value":"some-arg-with-dash\n\n"},
   {"type":"Keyword","value":"echo"},
   {"type":"Text","value":" input."},
   {"type":"Operator","value":"{"},
@@ -865,7 +867,7 @@
   {"type":"Text","value":" "},
   {"type":"Operator","value":"("},
   {"type":"NameBuiltin","value":"status fish"},
-  {"type":"NameAttribute","value":"-path"},
+  {"type":"Text","value":"-path"},
   {"type":"Operator","value":")"},
   {"type":"Text","value":"\n                "},
   {"type":"Keyword","value":"set"},
@@ -1261,5 +1263,6 @@
   {"type":"Text","value":" "},
   {"type":"LiteralNumber","value":"0"},
   {"type":"Text","value":"\n    "},
-  {"type":"Keyword","value":"end"}
+  {"type":"Keyword","value":"end"},
+  {"type":"Text","value":"\n"}
 ]
Repository: alecthomas/chroma
Pull request #539 (2021-08-15 11:31:47)

Raku: Fix incorrectly matching closing brackets as opening


Patch:
diff --git a/lexers/r/raku.go b/lexers/r/raku.go
index 5b5c8a7..88d1f23 100644
--- a/lexers/r/raku.go
+++ b/lexers/r/raku.go
@@ -1156,12 +1156,11 @@ func rakuRules() Rules {
 	}
 }
 
-// Joins keys and values of rune map
+// Joins keys of rune map
 func joinRuneMap(m map[rune]rune) string {
-	runes := make([]rune, 0, len(m)*2)
-	for k, v := range m {
+	runes := make([]rune, 0, len(m))
+	for k := range m {
 		runes = append(runes, k)
-		runes = append(runes, v)
 	}
 
 	return string(runes)


Test patch:
diff --git a/lexers/testdata/raku.actual b/lexers/testdata/raku.actual
index f95e434..26b18e4 100644
--- a/lexers/testdata/raku.actual
+++ b/lexers/testdata/raku.actual
@@ -21,7 +21,7 @@ fmt.Println("Hello from Go")
 say $=pod[0].config<numbered>;
 
 sub f1($a) {
-    $a+1;
+    $a+1; #=> Comment looking like a pod declaration, but with a closing bracket!
 }
 
 2.&f1;
diff --git a/lexers/testdata/raku.expected b/lexers/testdata/raku.expected
index fcc9407..4ae4b69 100644
--- a/lexers/testdata/raku.expected
+++ b/lexers/testdata/raku.expected
@@ -67,6 +67,8 @@
   {"type":"Operator","value":"+"},
   {"type":"LiteralNumberInteger","value":"1"},
   {"type":"Punctuation","value":";"},
+  {"type":"Text","value":" "},
+  {"type":"CommentSingle","value":"#=\u003e Comment looking like a pod declaration, but with a closing bracket!"},
   {"type":"Text","value":"\n"},
   {"type":"Punctuation","value":"}"},
   {"type":"Text","value":"\n\n"},